From bad6e6ee1637db2d238c7166ada1cd977633d33a Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Tue, 5 Jul 2016 01:01:34 +0300 Subject: [PATCH] Allow passing a room object to client:join_room() This neatly allows to pass the room object passed to the "invited" event directly to :join_room(). This way the user does not need to know that rooms have a "room_id" attribute. --- matrix/client.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/matrix/client.lua b/matrix/client.lua index 615688c..320859a 100644 --- a/matrix/client.lua +++ b/matrix/client.lua @@ -361,12 +361,15 @@ function Client:create_room(alias, public, invite) return self:_make_room(response.room_id) end -function Client:join_room(room_id_or_alias) - local response = self._api:join_room(room_id_or_alias) - local room = self:_make_room(response.room_id or room_id_or_alias) - -- XXX: At this point we might have joined the room, but its state has not - -- been synced. Maybe firing the "joined" event should be delayed - -- until the next sync (or when the corresponding events come in). +function Client:join_room(room) + if type(room) == "string" then + local response = self._api:join_room(room) + elseif type(room) == "table" and getmetatable(room) == Room then + local response = self._api:join_room(room.room_id) + else + error("argument #1 must be a string or a room object") + end + room = self:_make_room(response.room_id) self:fire("joined", room) return room end