Include room members' presence in room initialSync

This commit is contained in:
Paul "LeoNerd" Evans 2014-11-18 15:28:58 +00:00
parent 759db7d7d5
commit 33d328d967
2 changed files with 36 additions and 1 deletions

View File

@ -299,6 +299,10 @@ class MessageHandler(BaseHandler):
feedback=False): feedback=False):
yield self.auth.check_joined_room(room_id, user_id) yield self.auth.check_joined_room(room_id, user_id)
# TODO(paul): I wish I was called with user objects not user_id
# strings...
auth_user = self.hs.parse_userid(user_id)
# TODO: These concurrently # TODO: These concurrently
state_tuples = yield self.store.get_current_state(room_id) state_tuples = yield self.store.get_current_state(room_id)
state = [self.hs.serialize_event(x) for x in state_tuples] state = [self.hs.serialize_event(x) for x in state_tuples]
@ -323,6 +327,23 @@ class MessageHandler(BaseHandler):
start_token = now_token.copy_and_replace("room_key", token[0]) start_token = now_token.copy_and_replace("room_key", token[0])
end_token = now_token.copy_and_replace("room_key", token[1]) end_token = now_token.copy_and_replace("room_key", token[1])
room_members = yield self.store.get_room_members(room_id)
presence_handler = self.hs.get_handlers().presence_handler
presence = []
for m in room_members:
try:
member_presence = yield presence_handler.get_state(
target_user=self.hs.parse_userid(m.user_id),
auth_user=auth_user,
as_event=True,
)
presence.append(member_presence)
except Exception as e:
logger.exception("Failed to get member presence of %r",
m.user_id
)
defer.returnValue({ defer.returnValue({
"membership": member_event.membership, "membership": member_event.membership,
"room_id": room_id, "room_id": room_id,
@ -332,5 +353,5 @@ class MessageHandler(BaseHandler):
"end": end_token.to_string(), "end": end_token.to_string(),
}, },
"state": state, "state": state,
#"presence": presence "presence": presence
}) })

View File

@ -1026,6 +1026,12 @@ class RoomInitialSyncTestCase(RestTestCase):
synapse.rest.room.register_servlets(hs, self.mock_resource) synapse.rest.room.register_servlets(hs, self.mock_resource)
# Since I'm getting my own presence I need to exist as far as presence
# is concerned.
hs.get_handlers().presence_handler.registered_user(
hs.parse_userid(self.user_id)
)
# create the room # create the room
self.room_id = yield self.create_room_as(self.user_id) self.room_id = yield self.create_room_as(self.user_id)
@ -1054,6 +1060,14 @@ class RoomInitialSyncTestCase(RestTestCase):
self.assertTrue("chunk" in response["messages"]) self.assertTrue("chunk" in response["messages"])
self.assertTrue("end" in response["messages"]) self.assertTrue("end" in response["messages"])
self.assertTrue("presence" in response)
presence_by_user = {e["content"]["user_id"]: e
for e in response["presence"]
}
self.assertTrue(self.user_id in presence_by_user)
self.assertEquals("m.presence", presence_by_user[self.user_id]["type"])
# (code, response) = yield self.mock_resource.trigger("GET", path, None) # (code, response) = yield self.mock_resource.trigger("GET", path, None)
# self.assertEquals(200, code, msg=str(response)) # self.assertEquals(200, code, msg=str(response))
# self.assert_dict(json.loads(content), response) # self.assert_dict(json.loads(content), response)