mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 22:03:49 +01:00
Added ability to .get_state() from the PresenceHandler by returning a complete m.presence event
This commit is contained in:
parent
4c18e08036
commit
759db7d7d5
1 changed files with 15 additions and 2 deletions
|
@ -165,7 +165,7 @@ class PresenceHandler(BaseHandler):
|
||||||
defer.returnValue(False)
|
defer.returnValue(False)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_state(self, target_user, auth_user):
|
def get_state(self, target_user, auth_user, as_event=False):
|
||||||
if target_user.is_mine:
|
if target_user.is_mine:
|
||||||
visible = yield self.is_presence_visible(
|
visible = yield self.is_presence_visible(
|
||||||
observer_user=auth_user,
|
observer_user=auth_user,
|
||||||
|
@ -191,6 +191,19 @@ class PresenceHandler(BaseHandler):
|
||||||
state["last_active_ago"] = int(
|
state["last_active_ago"] = int(
|
||||||
self.clock.time_msec() - state.pop("last_active")
|
self.clock.time_msec() - state.pop("last_active")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if as_event:
|
||||||
|
content = state
|
||||||
|
|
||||||
|
content["user_id"] = target_user.to_string()
|
||||||
|
|
||||||
|
if "last_active" in content:
|
||||||
|
content["last_active_ago"] = int(
|
||||||
|
self._clock.time_msec() - content.pop("last_active")
|
||||||
|
)
|
||||||
|
|
||||||
|
defer.returnValue({"type": "m.presence", "content": content})
|
||||||
|
else:
|
||||||
defer.returnValue(state)
|
defer.returnValue(state)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in a new issue