From fcc592b072bf41ffd64d779d70fb3e3af7f96668 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 16 Mar 2016 17:13:05 +0100 Subject: [PATCH] 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 --- src/matrix-event-room-base.vala | 4 +++- src/matrix-event-state-base.vala | 2 +- src/matrix-http-client.vala | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/matrix-event-room-base.vala b/src/matrix-event-room-base.vala index 029fd81..a485bd9 100644 --- a/src/matrix-event-room-base.vala +++ b/src/matrix-event-room-base.vala @@ -26,7 +26,9 @@ public abstract class Matrix.Event.Room : Matrix.Event.Base { 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; } diff --git a/src/matrix-event-state-base.vala b/src/matrix-event-state-base.vala index 5a454a6..587a66a 100644 --- a/src/matrix-event-state-base.vala +++ b/src/matrix-event-state-base.vala @@ -16,7 +16,7 @@ * . */ -public abstract class Matrix.Event.State : Matrix.Event.Base { +public abstract class Matrix.Event.State : Matrix.Event.Room { protected string? _state_key; public string? state_key { diff --git a/src/matrix-http-client.vala b/src/matrix-http-client.vala index 7041246..459ca9c 100644 --- a/src/matrix-http-client.vala +++ b/src/matrix-http-client.vala @@ -115,6 +115,17 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { if (evt != 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))) { var pevt = (Matrix.Event.Presence)evt;