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.
This commit is contained in:
@@ -361,12 +361,15 @@ function Client:create_room(alias, public, invite)
|
|||||||
return self:_make_room(response.room_id)
|
return self:_make_room(response.room_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Client:join_room(room_id_or_alias)
|
function Client:join_room(room)
|
||||||
local response = self._api:join_room(room_id_or_alias)
|
if type(room) == "string" then
|
||||||
local room = self:_make_room(response.room_id or room_id_or_alias)
|
local response = self._api:join_room(room)
|
||||||
-- XXX: At this point we might have joined the room, but its state has not
|
elseif type(room) == "table" and getmetatable(room) == Room then
|
||||||
-- been synced. Maybe firing the "joined" event should be delayed
|
local response = self._api:join_room(room.room_id)
|
||||||
-- until the next sync (or when the corresponding events come in).
|
else
|
||||||
|
error("argument #1 must be a string or a room object")
|
||||||
|
end
|
||||||
|
room = self:_make_room(response.room_id)
|
||||||
self:fire("joined", room)
|
self:fire("joined", room)
|
||||||
return room
|
return room
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user