Fix state and room events

* State event descended from Event, but it is actually based on Room
* Room events may have a missing room_id property due to HS
* optimization
This commit is contained in:
Gergely Polonkai 2016-03-16 17:13:05 +01:00 committed by Gergely Polonkai
parent 62eb4e7e21
commit fcc592b072
3 changed files with 15 additions and 2 deletions

View File

@ -26,7 +26,9 @@ public abstract class Matrix.Event.Room : Matrix.Event.Base {
public string? event_id { get; set; default = null; } public string? event_id { get; set; default = null; }
/** /**
* The ID of the room associated with this event. Required. * The ID of the room associated with this event. Required, but it
* may be stripped by HS implementations from some APIs if they
* reside under a key marked with the room ID.
*/ */
public string? room_id { get; set; default = null; } public string? room_id { get; set; default = null; }

View File

@ -16,7 +16,7 @@
* <http://www.gnu.org/licenses/>. * <http://www.gnu.org/licenses/>.
*/ */
public abstract class Matrix.Event.State : Matrix.Event.Base { public abstract class Matrix.Event.State : Matrix.Event.Room {
protected string? _state_key; protected string? _state_key;
public string? state_key { public string? state_key {

View File

@ -115,6 +115,17 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
if (evt != null) { if (evt != null) {
string? user_id = null; string? user_id = null;
GLib.Type evt_type = evt.get_type();
// Make sure Room events have room_id set, even if it was
// stripped by the HS
if (evt_type.is_a(typeof(Matrix.Event.Room))) {
Matrix.Event.Room revt = (Matrix.Event.Room)evt;
if (revt.room_id == null) {
revt.room_id = room_id;
}
}
if (evt.get_type().is_a(typeof(Matrix.Event.Presence))) { if (evt.get_type().is_a(typeof(Matrix.Event.Presence))) {
var pevt = (Matrix.Event.Presence)evt; var pevt = (Matrix.Event.Presence)evt;