Add Client.get_room_by_alias

This commit is contained in:
Gergely Polonkai 2016-03-18 11:17:04 +01:00 committed by Gergely Polonkai
parent 0e4a572058
commit 3ddac22f78
2 changed files with 32 additions and 0 deletions

View File

@ -205,4 +205,16 @@ public interface Matrix.Client : GLib.Object {
public abstract Room
get_room_by_id(string room_id)
throws Matrix.Error;
/**
* Get a room object by the room alias specified
* in @param room_alias. If room data is not cached yet,
* {@link Matrix.Error.UNAVAILABLE} is thrown.
*
* @param room_alias a room alias
* @return a Matrix.Room object
*/
public abstract Room
get_room_by_alias(string room_alias)
throws Matrix.Error;
}

View File

@ -453,4 +453,24 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
return room;
}
public Room
get_room_by_alias(string room_alias)
throws Matrix.Error
{
foreach (var entry in _rooms.entries) {
var room = entry.value;
if (room.canonical_alias == room_alias) {
return room;
}
if (room_alias in room.aliases) {
return room;
}
}
throw new Matrix.Error.UNAVAILABLE(
"Noo room data found for alias %s", room_alias);
}
}