Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Split presence out of master #9820

Merged
merged 9 commits into from
Apr 23, 2021
Merged
25 changes: 0 additions & 25 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,6 @@
logger = logging.getLogger("synapse.app.generic_worker")


class PresenceStatusStubServlet(RestServlet):
"""If presence is disabled this servlet can be used to stub out setting
presence status.
"""

PATTERNS = client_patterns("/presence/(?P<user_id>[^/]*)/status")

def __init__(self, hs):
super().__init__()
self.auth = hs.get_auth()

async def on_GET(self, request, user_id):
await self.auth.get_user_by_req(request)
return 200, {"presence": "offline"}

async def on_PUT(self, request, user_id):
await self.auth.get_user_by_req(request)
return 200, {}


class KeyUploadServlet(RestServlet):
"""An implementation of the `KeyUploadServlet` that responds to read only
requests, but otherwise proxies through to the master instance.
Expand Down Expand Up @@ -329,11 +309,6 @@ def _listen_http(self, listener_config: ListenerConfig):

presence.register_servlets(self, resource)

# If presence is disabled, use the stub servlet that does
# not allow sending presence
if not self.config.use_presence:
PresenceStatusStubServlet(self).register(resource)

groups.register_servlets(self, resource)

resources.update({CLIENT_API_PREFIX: resource})
Expand Down
7 changes: 6 additions & 1 deletion synapse/rest/client/v1/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ def __init__(self, hs):
self.clock = hs.get_clock()
self.auth = hs.get_auth()

self._use_presence = hs.config.server.use_presence

async def on_GET(self, request, user_id):
requester = await self.auth.get_user_by_req(request)
user = UserID.from_string(user_id)

if not self._use_presence:
return 200, {"presence": "offline"}

if requester.user != user:
allowed = await self.presence_handler.is_visible(
observed_user=user, observer_user=requester.user
Expand Down Expand Up @@ -80,7 +85,7 @@ async def on_PUT(self, request, user_id):
except Exception:
raise SynapseError(400, "Unable to parse state")

if self.hs.config.use_presence:
if self._use_presence:
await self.presence_handler.set_state(user, state)

return 200, {}
Expand Down
83 changes: 0 additions & 83 deletions tests/app/test_frontend_proxy.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/rest/client/v1/test_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def test_put_presence(self):
self.assertEqual(channel.code, 200)
self.assertEqual(self.hs.get_presence_handler().set_state.call_count, 1)

@unittest.override_config({"use_presence": False})
def test_put_presence_disabled(self):
"""
PUT to the status endpoint with use_presence disabled will NOT call
set_state on the presence handler.
"""
self.hs.config.use_presence = False

body = {"presence": "here", "status_msg": "beep boop"}
channel = self.make_request(
Expand Down