mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Implement MSC3026: busy presence state
This commit is contained in:
parent
7b06f85c0e
commit
405aeb0b2c
6 changed files with 27 additions and 1 deletions
1
changelog.d/9644.feature
Normal file
1
changelog.d/9644.feature
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Implement the busy presence state as described in [MSC3026](https://github.com/matrix-org/matrix-doc/pull/3026).
|
|
@ -51,6 +51,7 @@ class PresenceState:
|
||||||
OFFLINE = "offline"
|
OFFLINE = "offline"
|
||||||
UNAVAILABLE = "unavailable"
|
UNAVAILABLE = "unavailable"
|
||||||
ONLINE = "online"
|
ONLINE = "online"
|
||||||
|
BUSY = "org.matrix.msc3026.busy"
|
||||||
|
|
||||||
|
|
||||||
class JoinRules:
|
class JoinRules:
|
||||||
|
|
|
@ -439,6 +439,7 @@ class GenericWorkerPresence(BasePresenceHandler):
|
||||||
PresenceState.ONLINE,
|
PresenceState.ONLINE,
|
||||||
PresenceState.UNAVAILABLE,
|
PresenceState.UNAVAILABLE,
|
||||||
PresenceState.OFFLINE,
|
PresenceState.OFFLINE,
|
||||||
|
PresenceState.BUSY,
|
||||||
)
|
)
|
||||||
if presence not in valid_presence:
|
if presence not in valid_presence:
|
||||||
raise SynapseError(400, "Invalid presence state")
|
raise SynapseError(400, "Invalid presence state")
|
||||||
|
|
|
@ -730,6 +730,7 @@ class PresenceHandler(BasePresenceHandler):
|
||||||
PresenceState.ONLINE,
|
PresenceState.ONLINE,
|
||||||
PresenceState.UNAVAILABLE,
|
PresenceState.UNAVAILABLE,
|
||||||
PresenceState.OFFLINE,
|
PresenceState.OFFLINE,
|
||||||
|
PresenceState.BUSY,
|
||||||
)
|
)
|
||||||
if presence not in valid_presence:
|
if presence not in valid_presence:
|
||||||
raise SynapseError(400, "Invalid presence state")
|
raise SynapseError(400, "Invalid presence state")
|
||||||
|
@ -744,7 +745,7 @@ class PresenceHandler(BasePresenceHandler):
|
||||||
msg = status_msg if presence != PresenceState.OFFLINE else None
|
msg = status_msg if presence != PresenceState.OFFLINE else None
|
||||||
new_fields["status_msg"] = msg
|
new_fields["status_msg"] = msg
|
||||||
|
|
||||||
if presence == PresenceState.ONLINE:
|
if presence == PresenceState.ONLINE or presence == PresenceState.BUSY:
|
||||||
new_fields["last_active_ts"] = self.clock.time_msec()
|
new_fields["last_active_ts"] = self.clock.time_msec()
|
||||||
|
|
||||||
await self._update_states([prev_state.copy_and_replace(**new_fields)])
|
await self._update_states([prev_state.copy_and_replace(**new_fields)])
|
||||||
|
|
|
@ -81,6 +81,8 @@ class VersionsRestServlet(RestServlet):
|
||||||
"io.element.e2ee_forced.public": self.e2ee_forced_public,
|
"io.element.e2ee_forced.public": self.e2ee_forced_public,
|
||||||
"io.element.e2ee_forced.private": self.e2ee_forced_private,
|
"io.element.e2ee_forced.private": self.e2ee_forced_private,
|
||||||
"io.element.e2ee_forced.trusted_private": self.e2ee_forced_trusted_private,
|
"io.element.e2ee_forced.trusted_private": self.e2ee_forced_trusted_private,
|
||||||
|
# Supports the busy presence state described in MSC3026.
|
||||||
|
"org.matrix.msc3026.busy_presence": True,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -310,6 +310,26 @@ class PresenceTimeoutTestCase(unittest.TestCase):
|
||||||
self.assertIsNotNone(new_state)
|
self.assertIsNotNone(new_state)
|
||||||
self.assertEquals(new_state.state, PresenceState.UNAVAILABLE)
|
self.assertEquals(new_state.state, PresenceState.UNAVAILABLE)
|
||||||
|
|
||||||
|
def test_busy_no_idle(self):
|
||||||
|
"""
|
||||||
|
Tests that a user setting their presence to busy but idling doesn't turn their
|
||||||
|
presence state into unavailable.
|
||||||
|
"""
|
||||||
|
user_id = "@foo:bar"
|
||||||
|
now = 5000000
|
||||||
|
|
||||||
|
state = UserPresenceState.default(user_id)
|
||||||
|
state = state.copy_and_replace(
|
||||||
|
state=PresenceState.BUSY,
|
||||||
|
last_active_ts=now - IDLE_TIMER - 1,
|
||||||
|
last_user_sync_ts=now,
|
||||||
|
)
|
||||||
|
|
||||||
|
new_state = handle_timeout(state, is_mine=True, syncing_user_ids=set(), now=now)
|
||||||
|
|
||||||
|
self.assertIsNotNone(new_state)
|
||||||
|
self.assertEquals(new_state.state, PresenceState.BUSY)
|
||||||
|
|
||||||
def test_sync_timeout(self):
|
def test_sync_timeout(self):
|
||||||
user_id = "@foo:bar"
|
user_id = "@foo:bar"
|
||||||
now = 5000000
|
now = 5000000
|
||||||
|
|
Loading…
Reference in a new issue