Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/source/matrix_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ matrix_client.crypto
:members:
:undoc-members:
:show-inheritance:

.. automodule:: matrix_client.crypto.device_list
:members:
:undoc-members:
:show-inheritance:

.. automodule:: matrix_client.crypto.megolm_outbound_session
:members:
:undoc-members:
:show-inheritance:
40 changes: 25 additions & 15 deletions matrix_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ def send_content(self, room_id, item_url, item_name, msg_type,
return self.send_message_event(room_id, "m.room.message", content_pack,
timestamp=timestamp)

def get_location_body(self, geo_uri, name, thumb_url=None, thumb_info=None):
content_pack = {
"geo_uri": geo_uri,
"msgtype": "m.location",
"body": name,
}
if thumb_url:
content_pack["thumbnail_url"] = thumb_url
if thumb_info:
content_pack["thumbnail_info"] = thumb_info
return content_pack

# http://matrix.org/docs/spec/client_server/r0.2.0.html#m-location
def send_location(self, room_id, geo_uri, name, thumb_url=None, thumb_info=None,
timestamp=None):
Expand All @@ -356,15 +368,8 @@ def send_location(self, room_id, geo_uri, name, thumb_url=None, thumb_info=None,
thumb_info (dict): Metadata about the thumbnail, type ImageInfo.
timestamp (int): Set origin_server_ts (For application services only)
"""
content_pack = {
"geo_uri": geo_uri,
"msgtype": "m.location",
"body": name,
}
if thumb_url:
content_pack["thumbnail_url"] = thumb_url
if thumb_info:
content_pack["thumbnail_info"] = thumb_info
content_pack = self.get_location_body(
geo_uri, name, thumb_url, thumb_info)

return self.send_message_event(room_id, "m.room.message", content_pack,
timestamp=timestamp)
Expand Down Expand Up @@ -405,12 +410,11 @@ def send_notice(self, room_id, text_content, timestamp=None):
text_content (str): The m.notice body to send.
timestamp (int): Set origin_server_ts (For application services only)
"""
body = {
"msgtype": "m.notice",
"body": text_content
}
return self.send_message_event(room_id, "m.room.message", body,
timestamp=timestamp)
return self.send_message_event(
room_id, "m.room.message",
self.get_notice_body(text_content),
timestamp=timestamp
)

def get_room_messages(self, room_id, token, direction, limit=10, to=None):
"""Perform GET /rooms/{roomId}/messages.
Expand Down Expand Up @@ -675,6 +679,12 @@ def get_emote_body(self, text):
"body": text
}

def get_notice_body(self, text):
return {
"msgtype": "m.notice",
"body": text
}

def get_filter(self, user_id, filter_id):
return self._send("GET", "/user/{userId}/filter/{filterId}"
.format(userId=user_id, filterId=filter_id))
Expand Down
13 changes: 13 additions & 0 deletions matrix_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,15 @@ def _mkroom(self, room_id):
# TODO better handling of the blocking I/O caused by update_one_time_key_counts
def _sync(self, timeout_ms=30000):
response = self.api.sync(self.sync_token, timeout_ms, filter=self.sync_filter)

if self._encryption and 'device_lists' in response:
if response['device_lists'].get('changed'):
self.olm_device.device_list.update_user_device_keys(
response['device_lists']['changed'], self.sync_token)
if response['device_lists'].get('left'):
self.olm_device.device_list.stop_tracking_users(
response['device_lists']['left'])

self.sync_token = response["next_batch"]

for presence_update in response['presence']['events']:
Expand Down Expand Up @@ -627,6 +636,10 @@ def _sync(self, timeout_ms=30000):
):
listener['callback'](event)

if self._encryption and room.encrypted:
# Track the new users in the room
self.olm_device.device_list.track_pending_users()

for event in sync_room['ephemeral']['events']:
event['room_id'] = room_id
room._put_ephemeral_event(event)
Expand Down
Loading