Skip to content

Commit

Permalink
Handler for "m.room.member" event
Browse files Browse the repository at this point in the history
  • Loading branch information
delijati committed Oct 10, 2017
1 parent 640ae9b commit 3446d68
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions matrix_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ def _process_state_event(self, state_event, current_room):
current_room.topic = state_event["content"].get("topic", None)
elif etype == "m.room.aliases":
current_room.aliases = state_event["content"].get("aliases", None)
elif etype == "m.room.member":
if state_event["content"]["membership"] == "join":
current_room._mkmembers(
User(self.api,
state_event["state_key"],
state_event["content"].get("displayname", None))
)

for listener in current_room.state_listeners:
if (
Expand Down
3 changes: 2 additions & 1 deletion matrix_client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ def get_joined_members(self):
return self._members

def _mkmembers(self, member):
self._members.append(member)
if member.user_id not in [x.user_id for x in self._members]:
self._members.append(member)

def backfill_previous_messages(self, reverse=False, limit=10):
"""Backfill handling of previous messages.
Expand Down
8 changes: 8 additions & 0 deletions test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def test_state_event():
client._process_state_event(ev, room)
assert room.aliases is aliases

# test member event
ev["type"] = "m.room.member"
ev["content"] = {'membership': 'join', 'displayname': 'stereo'}
ev["state_key"] = "@stereo:xxx.org"
client._process_state_event(ev, room)
assert len(room._members) == 1
assert room._members[0].user_id == "@stereo:xxx.org"


def test_get_user():
client = MatrixClient("http://example.com")
Expand Down

0 comments on commit 3446d68

Please sign in to comment.