mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 12:54:57 -04:00
Implement MSC3852: Expose last_seen_user_agent
to users for their own devices; also expose to Admin API (#13549)
This commit is contained in:
parent
40e3e68cd7
commit
f9f03426de
8 changed files with 153 additions and 2 deletions
|
@ -42,12 +42,26 @@ class DevicesRestServlet(RestServlet):
|
|||
self.hs = hs
|
||||
self.auth = hs.get_auth()
|
||||
self.device_handler = hs.get_device_handler()
|
||||
self._msc3852_enabled = hs.config.experimental.msc3852_enabled
|
||||
|
||||
async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
|
||||
requester = await self.auth.get_user_by_req(request, allow_guest=True)
|
||||
devices = await self.device_handler.get_devices_by_user(
|
||||
requester.user.to_string()
|
||||
)
|
||||
|
||||
# If MSC3852 is disabled, then the "last_seen_user_agent" field will be
|
||||
# removed from each device. If it is enabled, then the field name will
|
||||
# be replaced by the unstable identifier.
|
||||
#
|
||||
# When MSC3852 is accepted, this block of code can just be removed to
|
||||
# expose "last_seen_user_agent" to clients.
|
||||
for device in devices:
|
||||
last_seen_user_agent = device["last_seen_user_agent"]
|
||||
del device["last_seen_user_agent"]
|
||||
if self._msc3852_enabled:
|
||||
device["org.matrix.msc3852.last_seen_user_agent"] = last_seen_user_agent
|
||||
|
||||
return 200, {"devices": devices}
|
||||
|
||||
|
||||
|
@ -108,6 +122,7 @@ class DeviceRestServlet(RestServlet):
|
|||
self.auth = hs.get_auth()
|
||||
self.device_handler = hs.get_device_handler()
|
||||
self.auth_handler = hs.get_auth_handler()
|
||||
self._msc3852_enabled = hs.config.experimental.msc3852_enabled
|
||||
|
||||
async def on_GET(
|
||||
self, request: SynapseRequest, device_id: str
|
||||
|
@ -118,6 +133,18 @@ class DeviceRestServlet(RestServlet):
|
|||
)
|
||||
if device is None:
|
||||
raise NotFoundError("No device found")
|
||||
|
||||
# If MSC3852 is disabled, then the "last_seen_user_agent" field will be
|
||||
# removed from each device. If it is enabled, then the field name will
|
||||
# be replaced by the unstable identifier.
|
||||
#
|
||||
# When MSC3852 is accepted, this block of code can just be removed to
|
||||
# expose "last_seen_user_agent" to clients.
|
||||
last_seen_user_agent = device["last_seen_user_agent"]
|
||||
del device["last_seen_user_agent"]
|
||||
if self._msc3852_enabled:
|
||||
device["org.matrix.msc3852.last_seen_user_agent"] = last_seen_user_agent
|
||||
|
||||
return 200, device
|
||||
|
||||
@interactive_auth_handler
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue