summaryrefslogtreecommitdiff
path: root/synapse/handlers/presence.py
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2021-11-08 14:53:03 +0100
committerAndrej Shadura <andrewsh@debian.org>2021-11-08 14:53:03 +0100
commit5a72e26a861b796b09c1b4b4b2bd5688a33d8df5 (patch)
tree6624948c82b5a926b56eb4f2365066a5f189d3be /synapse/handlers/presence.py
parent62c1a069b73e89b50d80fbbb4bc49f0c247afcdf (diff)
New upstream version 1.46.0
Diffstat (limited to 'synapse/handlers/presence.py')
-rw-r--r--synapse/handlers/presence.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 404afb94..fdab50da 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -52,7 +52,6 @@ import synapse.metrics
from synapse.api.constants import EventTypes, Membership, PresenceState
from synapse.api.errors import SynapseError
from synapse.api.presence import UserPresenceState
-from synapse.appservice import ApplicationService
from synapse.events.presence_router import PresenceRouter
from synapse.logging.context import run_in_background
from synapse.logging.utils import log_function
@@ -1483,13 +1482,39 @@ def should_notify(old_state: UserPresenceState, new_state: UserPresenceState) ->
def format_user_presence_state(
state: UserPresenceState, now: int, include_user_id: bool = True
) -> JsonDict:
- """Convert UserPresenceState to a format that can be sent down to clients
+ """Convert UserPresenceState to a JSON format that can be sent down to clients
and to other servers.
- The "user_id" is optional so that this function can be used to format presence
- updates for client /sync responses and for federation /send requests.
+ Args:
+ state: The user presence state to format.
+ now: The current timestamp since the epoch in ms.
+ include_user_id: Whether to include `user_id` in the returned dictionary.
+ As this function can be used both to format presence updates for client /sync
+ responses and for federation /send requests, only the latter needs the include
+ the `user_id` field.
+
+ Returns:
+ A JSON dictionary with the following keys:
+ * presence: The presence state as a str.
+ * user_id: Optional. Included if `include_user_id` is truthy. The canonical
+ Matrix ID of the user.
+ * last_active_ago: Optional. Included if `last_active_ts` is set on `state`.
+ The timestamp that the user was last active.
+ * status_msg: Optional. Included if `status_msg` is set on `state`. The user's
+ status.
+ * currently_active: Optional. Included only if `state.state` is "online".
+
+ Example:
+
+ {
+ "presence": "online",
+ "user_id": "@alice:example.com",
+ "last_active_ago": 16783813918,
+ "status_msg": "Hello world!",
+ "currently_active": True
+ }
"""
- content = {"presence": state.state}
+ content: JsonDict = {"presence": state.state}
if include_user_id:
content["user_id"] = state.user_id
if state.last_active_ts:
@@ -1526,7 +1551,6 @@ class PresenceEventSource(EventSource[int, UserPresenceState]):
is_guest: bool = False,
explicit_room_id: Optional[str] = None,
include_offline: bool = True,
- service: Optional[ApplicationService] = None,
) -> Tuple[List[UserPresenceState], int]:
# The process for getting presence events are:
# 1. Get the rooms the user is in.