Skip to content

Commit

Permalink
Initialise UserPresenceCache instances to always contain a 'presence'…
Browse files Browse the repository at this point in the history
… key
  • Loading branch information
Paul "LeoNerd" Evans committed Nov 19, 2014
1 parent 4eada9a commit 03dc63f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 2 additions & 4 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def _get_or_offline_usercache(self, user):
if user in self._user_cachemap:
return self._user_cachemap[user]
else:
statuscache = UserPresenceCache()
statuscache.update({"presence": PresenceState.OFFLINE}, user)
return statuscache
return UserPresenceCache()

def registered_user(self, user):
self.store.create_presence(user.localpart)
Expand Down Expand Up @@ -873,7 +871,7 @@ class UserPresenceCache(object):
Includes the update timestamp.
"""
def __init__(self):
self.state = {}
self.state = {"presence": PresenceState.OFFLINE}
self.serial = None

def update(self, state, serial):
Expand Down
10 changes: 8 additions & 2 deletions tests/handlers/test_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,10 @@ def test_remote_poll_send(self):
path=ANY,
data=_expect_edu("remote", "m.presence",
content={
"push": [ {"user_id": "@clementine:test" }],
"push": [ {
"user_id": "@clementine:test",
"presence": OFFLINE,
}],
},
),
json_data_callback=ANY,
Expand Down Expand Up @@ -1229,7 +1232,10 @@ def test_remote_poll_send(self):
path=ANY,
data=_expect_edu("remote", "m.presence",
content={
"push": [ {"user_id": "@fig:test" }],
"push": [ {
"user_id": "@fig:test",
"presence": OFFLINE,
}],
},
),
json_data_callback=ANY,
Expand Down

0 comments on commit 03dc63f

Please sign in to comment.