diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2021-10-20 17:47:04 +0100 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2021-10-20 17:58:53 +0100 |
commit | e423a94b28263a3971147c210729769734fe66c5 (patch) | |
tree | 8ac9c1c24cb2622e7545fb02f5be2f24db5194d9 | |
parent | Add comments to _handle* methods and those methods they call (diff) | |
download | synapse-e423a94b28263a3971147c210729769734fe66c5.tar.xz |
Improve docstring for format_user_presence_state
-rw-r--r-- | synapse/handlers/presence.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index b5968e047b..06c30472cf 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -1483,11 +1483,38 @@ 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". Set to + the value of `state.currently_active`. + + Example: + + { + "presence": "online", + "user_id": "@alice:example.com", + "last_active_ago": 16783813918, + "status_msg": "Hello world!", + "currently_active": True + } """ content: JsonDict = {"presence": state.state} if include_user_id: |