From c8f815c5427b78b69a13201d5cbc13f7953abe8d Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 16 Mar 2016 17:38:50 +0100 Subject: [PATCH] Add Client.get_room_by_id() --- src/matrix-client.vala | 12 ++++++++++++ src/matrix-http-client.vala | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/matrix-client.vala b/src/matrix-client.vala index 4a85d07..d1d4d75 100644 --- a/src/matrix-client.vala +++ b/src/matrix-client.vala @@ -193,4 +193,16 @@ public interface Matrix.Client : GLib.Object { public abstract Presence get_user_presence(string user_id, string? room_id = null) throws Matrix.Error; + + /** + * Get a room object by the room ID specified in @param room_id. + * If room data is not cached yet, Matrix.Error.UNAVAILABLE is + * thrown. + * + * @param room_id the ID of a room + * @return a Matrix.Room object + */ + public abstract Room + get_room_by_id(string room_id) + throws Matrix.Error; } diff --git a/src/matrix-http-client.vala b/src/matrix-http-client.vala index 973d893..242fa72 100644 --- a/src/matrix-http-client.vala +++ b/src/matrix-http-client.vala @@ -439,4 +439,18 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { throw new Matrix.Error.UNSUPPORTED( "Per-room presences are not supported yet."); } + + public Room + get_room_by_id(string room_id) + throws Matrix.Error + { + Room? room; + + if ((room = _rooms[room_id]) == null) { + throw new Matrix.Error.UNAVAILABLE( + "Room data for %s is not cached yet.", room_id); + } + + return room; + } }