From f8cc8a66b406d6c36d8a06b722738ea19b3e967e Mon Sep 17 00:00:00 2001 From: Kegsay Date: Thu, 18 Dec 2014 14:16:31 +0000 Subject: [PATCH 01/11] Update README.rst Add windows (cygwin) install instructions. --- README.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.rst b/README.rst index 8459bcac2..7497f1584 100644 --- a/README.rst +++ b/README.rst @@ -133,6 +133,28 @@ failing, e.g.:: On OSX, if you encounter clang: error: unknown argument: '-mno-fused-madd' you will need to export CFLAGS=-Qunused-arguments. +Windows Install +--------------- +Synapse can be installed on Cygwin. It requires the following Cygwin packages: + + - gcc + - git + - libffi-devel + - openssl (and openssl-devel, python-openssl) + - python + - python-setuptools + +Troubleshooting: + +- You may need to upgrade ``setuptools`` to get this to work correctly: + ``pip install setuptools --upgrade``. +- You may encounter errors indicating that ``ffi.h`` is missing, even with + ``libffi-devel`` installed. If you do, copy the ``.h`` files: + ``cp /usr/lib/libffi-3.0.13/include/*.h /usr/include`` +- You may need to install libsodium from source in order to install PyNacl. If + you do, you may need to create a symlink to ``libsodium.a`` so ``ld`` can find + it: ``ln -s /usr/local/lib/libsodium.a /usr/lib/libsodium.a`` + Running Your Homeserver ======================= From 20923ffd43cc49b3f532012d9465c07a707534e3 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Thu, 18 Dec 2014 14:44:48 +0000 Subject: [PATCH 02/11] Update README.rst Add gotcha: The content repository requires additional cygwin packages. --- README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.rst b/README.rst index 7497f1584..f5d2b0af3 100644 --- a/README.rst +++ b/README.rst @@ -143,6 +143,15 @@ Synapse can be installed on Cygwin. It requires the following Cygwin packages: - openssl (and openssl-devel, python-openssl) - python - python-setuptools + +The content repository requires additional packages and will be unable to process +uploads without them: + - libjpeg8 + - libjpeg8-devel + - zlib +If you choose to install Synapse without these packages, you will need to reinstall +``pillow`` for changes to be applied, e.g. ``pip uninstall pillow`` ``pip install +pillow --user`` Troubleshooting: From 5739e6c60684556cbdf1a792514a74de36b480b7 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 11:43:46 +0000 Subject: [PATCH 03/11] s/user_id/sender/ --- synapse/handlers/room.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 8567d7409..4b8385c95 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -147,7 +147,7 @@ class RoomCreationHandler(BaseHandler): "type": EventTypes.Member, "state_key": invitee, "room_id": room_id, - "user_id": user_id, + "sender": user_id, "content": {"membership": Membership.INVITE}, }) From 390e48a8b03784d7cdb49d792c7798b194471ed0 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 12:05:26 +0000 Subject: [PATCH 04/11] SYN-203: Handle requests for thunbnails for images that are small --- synapse/media/v1/thumbnail_resource.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/synapse/media/v1/thumbnail_resource.py b/synapse/media/v1/thumbnail_resource.py index e19620d45..5ddcf54b9 100644 --- a/synapse/media/v1/thumbnail_resource.py +++ b/synapse/media/v1/thumbnail_resource.py @@ -165,18 +165,27 @@ class ThumbnailResource(BaseMediaResource): aspect_quality, size_quality, type_quality, length_quality, info )) - return min(info_list)[-1] + if info_list: + return min(info_list)[-1] else: info_list = [] + info_list2 = [] for info in thumbnail_infos: t_w = info["thumbnail_width"] t_h = info["thumbnail_height"] t_method = info["thumbnail_method"] + size_quality = abs((d_w - t_w) * (d_h - t_h)) + type_quality = desired_type != info["thumbnail_type"] + length_quality = info["thumbnail_length"] if t_method == "scale" and (t_w >= d_w or t_h >= d_h): - size_quality = abs((d_w - t_w) * (d_h - t_h)) - type_quality = desired_type != info["thumbnail_type"] - length_quality = info["thumbnail_length"] info_list.append(( size_quality, type_quality, length_quality, info )) - return min(info_list)[-1] + elif t_method == "scale": + info_list2.append(( + size_quality, type_quality, length_quality, info + )) + if info_list: + return min(info_list)[-1] + else: + return min(info_list2)[-1] From 5dbe820e9ac94247148eb57ce1c78f6a0c516004 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 12:16:26 +0000 Subject: [PATCH 05/11] Remove unneeded federation keys from events --- synapse/events/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/synapse/events/utils.py b/synapse/events/utils.py index 94f3f15f5..4849d3ce4 100644 --- a/synapse/events/utils.py +++ b/synapse/events/utils.py @@ -126,5 +126,8 @@ def serialize_event(hs, e): del d["prev_events"] del d["hashes"] del d["signatures"] + d.pop("depth", None) + d.pop("unsigned", None) + d.pop("origin", None) return d From 1e7f83b91dfdc68a9233dca5870d2511ec891bf0 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 12:31:46 +0000 Subject: [PATCH 06/11] Set display name when joining via alias --- synapse/handlers/room.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 4b8385c95..9644cd3d3 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -390,6 +390,11 @@ class RoomMemberHandler(BaseHandler): host = hosts[0] + # If event doesn't include a display name, add one. + yield self.distributor.fire( + "collect_presencelike_data", joinee, content + ) + content.update({"membership": Membership.JOIN}) builder = self.event_builder_factory.new({ "type": EventTypes.Member, From 1e4a56c3a9589bb3d88e5ee07eb4dd1aafde3893 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 13:39:24 +0000 Subject: [PATCH 07/11] Bump web sdk version to 0.6.0 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index eb410aa6d..043cd044a 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup( description="Reference Synapse Home Server", install_requires=[ "syutil==0.0.2", - "matrix_angular_sdk==0.5.3b", + "matrix_angular_sdk==0.6.0", "Twisted>=14.0.0", "service_identity>=1.0.0", "pyopenssl>=0.14", @@ -47,7 +47,7 @@ setup( dependency_links=[ "https://github.com/matrix-org/syutil/tarball/v0.0.2#egg=syutil-0.0.2", "https://github.com/pyca/pynacl/tarball/d4d3175589b892f6ea7c22f466e0e223853516fa#egg=pynacl-0.3.0", - "https://github.com/matrix-org/matrix-angular-sdk/tarball/v0.5.3b/#egg=matrix_angular_sdk-0.5.3b", + "https://github.com/matrix-org/matrix-angular-sdk/tarball/v0.6.0/#egg=matrix_angular_sdk-0.6.0", ], setup_requires=[ "setuptools_trial", From a999f0dec3b9ec12f8fe605c6d08d226c4d87ae8 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 14:18:27 +0000 Subject: [PATCH 08/11] Don't ratelimit room create events --- synapse/handlers/directory.py | 2 +- synapse/handlers/message.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py index 66d3b533d..a907a66e1 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 49c0e9811..01a718354 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -106,7 +106,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 +123,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,) From f70e622d59e7b97c539ee03ffc02315b4d626b00 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 14:30:57 +0000 Subject: [PATCH 09/11] bump_presence_active_time when sending a message event --- synapse/handlers/message.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 01a718354..854b2c73c 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 @@ -153,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 From 9c71d945d6072323df6d1e183efc4b6f7ad35237 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 15:16:48 +0000 Subject: [PATCH 10/11] Look for name, topic in the event content rather than the event itself when persisting room name and topic events --- synapse/storage/room.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/synapse/storage/room.py b/synapse/storage/room.py index 2378d6594..c20abbfe4 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"], } ) From efd27ff01b201c2e9f52cc90daccbda72709482e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 19 Dec 2014 15:31:27 +0000 Subject: [PATCH 11/11] Set a state_key for the topic and room name, otherwise they won't be treated as room state --- synapse/handlers/room.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 9644cd3d3..deefc3c11 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}, })