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

Commit

Permalink
Random stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
hera committed Jul 7, 2017
1 parent 715bcf7 commit f2db3e4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
24 changes: 24 additions & 0 deletions synapse/app/frontend_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from synapse.http.servlet import (
RestServlet, parse_json_object_from_request,
)
from synapse.rest.client.v1.base import ClientV1RestServlet, client_path_patterns
from synapse.rest.client.v2_alpha._base import client_v2_patterns

from synapse import events
Expand All @@ -58,6 +59,28 @@
logger = logging.getLogger("synapse.app.frontend_proxy")


class PresenceStatusStubServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/presence/(?P<user_id>[^/]*)/status")

def __init__(self, hs):
super(PresenceStatusStubServlet, self).__init__(hs)
self.http_client = hs.get_simple_http_client()
self.auth = hs.get_auth()
self.main_uri = hs.config.worker_main_http_uri

@defer.inlineCallbacks
def on_GET(self, request, user_id):
result = yield self.http_client.get_json(
self.main_uri + request.uri,
)
defer.returnValue((200, result))

@defer.inlineCallbacks
def on_PUT(self, request, user_id):
yield self.auth.get_user_by_req(request)
defer.returnValue((200, {}))


class KeyUploadServlet(RestServlet):
PATTERNS = client_v2_patterns("/keys/upload(/(?P<device_id>[^/]+))?$",
releases=())
Expand Down Expand Up @@ -151,6 +174,7 @@ def _listen_http(self, listener_config):
elif name == "client":
resource = JsonResource(self, canonical_json=False)
KeyUploadServlet(self).register(resource)
PresenceStatusStubServlet(self).register(resource)
resources.update({
"/_matrix/client/r0": resource,
"/_matrix/client/unstable": resource,
Expand Down
2 changes: 2 additions & 0 deletions synapse/replication/slave/storage/client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def insert_client_ip(self, user_id, access_token, ip, user_agent, device_id):
if last_seen is not None and (now - last_seen) < LAST_SEEN_GRANULARITY:
return

self.client_ip_last_seen.prefill(key, now)

self.hs.get_tcp_replication().send_user_ip(
user_id, access_token, ip, user_agent, device_id, now
)
24 changes: 12 additions & 12 deletions synapse/rest/client/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ def on_POST(self, request, room_id):
)
new_room_id = info["room_id"]

msg_handler = self.handlers.message_handler
yield msg_handler.create_and_send_nonmember_event(
room_creator_requester,
{
"type": "m.room.message",
"content": {"body": message, "msgtype": "m.text"},
"room_id": new_room_id,
"sender": new_room_user_id,
},
ratelimit=False,
)

requester_user_id = requester.user.to_string()

logger.info("Shutting down room %r", room_id)
Expand Down Expand Up @@ -257,6 +245,18 @@ def on_POST(self, request, room_id):

kicked_users.append(user_id)

msg_handler = self.handlers.message_handler
yield msg_handler.create_and_send_nonmember_event(
room_creator_requester,
{
"type": "m.room.message",
"content": {"body": message, "msgtype": "m.text"},
"room_id": new_room_id,
"sender": new_room_user_id,
},
ratelimit=False,
)

aliases_for_room = yield self.store.get_aliases_for_room(room_id)

yield self.store.update_aliases_for_room(
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/client_ips.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Number of msec of granularity to store the user IP 'last seen' time. Smaller
# times give more inserts into the database even for readonly API hits
# 120 seconds == 2 minutes
LAST_SEEN_GRANULARITY = 120 * 1000
LAST_SEEN_GRANULARITY = 10 * 60 * 1000


class ClientIpStore(background_updates.BackgroundUpdateStore):
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def _get_media_ids_in_room(txn):
"""
UPDATE remote_media_cache
SET quarantined_by = ?
WHERE media_origin AND media_id = ?
WHERE media_origin = ? AND media_id = ?
""",
(
(quarantined_by, origin, media_id)
Expand Down

0 comments on commit f2db3e4

Please sign in to comment.