summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-12-19 17:52:58 +0000
committerMark Haines <mark.haines@matrix.org>2014-12-19 17:52:58 +0000
commit420ccfc925bbdc4344e3f870b61dba2dd5069f6b (patch)
treea705309ba66e2e60e3796c276bd2e2f3867e1956 /synapse
parentMerge branch 'release-v0.6.0' (diff)
parentMock ratelimiter to make tests pass. (diff)
downloadsynapse-420ccfc925bbdc4344e3f870b61dba2dd5069f6b.tar.xz
Merge branch 'hotfixes-v0.6.0' v0.6.0a
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/directory.py2
-rw-r--r--synapse/handlers/message.py11
-rw-r--r--synapse/handlers/profile.py6
-rw-r--r--synapse/handlers/room.py2
-rw-r--r--synapse/storage/room.py8
5 files changed, 20 insertions, 9 deletions
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 66d3b533d9..a907a66e12 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -155,4 +155,4 @@ class DirectoryHandler(BaseHandler):
             "room_id": room_id,
             "sender": user_id,
             "content": {"aliases": aliases},
-        })
+        }, ratelimit=False)
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 49c0e98113..854b2c73c6 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -19,6 +19,7 @@ from synapse.api.constants import EventTypes, Membership
 from synapse.api.errors import RoomError
 from synapse.streams.config import PaginationConfig
 from synapse.events.validator import EventValidator
+from synapse.util.logcontext import PreserveLoggingContext
 
 from ._base import BaseHandler
 
@@ -106,7 +107,7 @@ class MessageHandler(BaseHandler):
         defer.returnValue(chunk)
 
     @defer.inlineCallbacks
-    def create_and_send_event(self, event_dict):
+    def create_and_send_event(self, event_dict, ratelimit=True):
         """ Given a dict from a client, create and handle a new event.
 
         Creates an FrozenEvent object, filling out auth_events, prev_events,
@@ -123,7 +124,8 @@ class MessageHandler(BaseHandler):
 
         self.validator.validate_new(builder)
 
-        self.ratelimit(builder.user_id)
+        if ratelimit:
+            self.ratelimit(builder.user_id)
         # TODO(paul): Why does 'event' not have a 'user' object?
         user = self.hs.parse_userid(builder.user_id)
         assert self.hs.is_mine(user), "User must be our own: %s" % (user,)
@@ -152,6 +154,11 @@ class MessageHandler(BaseHandler):
                 context=context,
             )
 
+        if event.type == EventTypes.Message:
+            presence = self.hs.get_handlers().presence_handler
+            with PreserveLoggingContext():
+                presence.bump_presence_active_time(user)
+
         defer.returnValue(event)
 
     @defer.inlineCallbacks
diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py
index 33a2c167ec..3f11e2dcf4 100644
--- a/synapse/handlers/profile.py
+++ b/synapse/handlers/profile.py
@@ -194,6 +194,8 @@ class ProfileHandler(BaseHandler):
         if not self.hs.is_mine(user):
             return
 
+        self.ratelimit(user.to_string())
+
         joins = yield self.store.get_rooms_for_user_where_membership_is(
             user.to_string(),
             [Membership.JOIN],
@@ -214,5 +216,5 @@ class ProfileHandler(BaseHandler):
                 "room_id": j.room_id,
                 "state_key": j.state_key,
                 "content": content,
-                "sender": j.state_key,
-            })
+                "sender": j.state_key
+            }, ratelimit=False)
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index 9644cd3d34..deefc3c11e 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -130,6 +130,7 @@ class RoomCreationHandler(BaseHandler):
                 "type": EventTypes.Name,
                 "room_id": room_id,
                 "sender": user_id,
+                "state_key": "",
                 "content": {"name": name},
             })
 
@@ -139,6 +140,7 @@ class RoomCreationHandler(BaseHandler):
                 "type": EventTypes.Topic,
                 "room_id": room_id,
                 "sender": user_id,
+                "state_key": "",
                 "content": {"topic": topic},
             })
 
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index 2378d65943..c20abbfe4d 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -135,26 +135,26 @@ class RoomStore(SQLBaseStore):
         defer.returnValue(ret)
 
     def _store_room_topic_txn(self, txn, event):
-        if hasattr(event, "topic"):
+        if hasattr(event, "content") and "topic" in event.content:
             self._simple_insert_txn(
                 txn,
                 "topics",
                 {
                     "event_id": event.event_id,
                     "room_id": event.room_id,
-                    "topic": event.topic,
+                    "topic": event.content["topic"],
                 }
             )
 
     def _store_room_name_txn(self, txn, event):
-        if hasattr(event, "name"):
+        if hasattr(event, "content") and "name" in event.content:
             self._simple_insert_txn(
                 txn,
                 "room_names",
                 {
                     "event_id": event.event_id,
                     "room_id": event.room_id,
-                    "name": event.name,
+                    "name": event.content["name"],
                 }
             )