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

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into shhs
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl committed May 20, 2019
2 parents d424ba9 + 24b93b9 commit d142e51
Show file tree
Hide file tree
Showing 46 changed files with 1,922 additions and 153 deletions.
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ virtualenv -p python3 ~/synapse/env
source ~/synapse/env/bin/activate
pip install --upgrade pip
pip install --upgrade setuptools
pip install matrix-synapse[all]
pip install matrix-synapse
```

This will download Synapse from [PyPI](https://pypi.org/project/matrix-synapse)
Expand All @@ -48,7 +48,7 @@ update flag:

```
source ~/synapse/env/bin/activate
pip install -U matrix-synapse[all]
pip install -U matrix-synapse
```

Before you can start Synapse, you will need to generate a configuration
Expand Down
1 change: 1 addition & 0 deletions changelog.d/3484.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make /sync attempt to return device updates for both joined and invited users. Note that this doesn't currently work correctly due to other bugs.
1 change: 1 addition & 0 deletions changelog.d/5039.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix image orientation when generating thumbnails (needs pillow>=4.3.0). Contributed by Pau Rodriguez-Estivill.
1 change: 1 addition & 0 deletions changelog.d/5174.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-order stages in registration flows such that msisdn and email verification are done last.
1 change: 1 addition & 0 deletions changelog.d/5177.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix 3pid guest invites.
1 change: 1 addition & 0 deletions changelog.d/5187.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where the register endpoint would fail with M_THREEPID_IN_USE instead of returning an account previously registered in the same session.
1 change: 1 addition & 0 deletions changelog.d/5191.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make generating SQL bounds for pagination generic.
1 change: 1 addition & 0 deletions changelog.d/5196.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add an option to disable per-room profiles.
1 change: 1 addition & 0 deletions changelog.d/5197.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop telling people to install the optional dependencies by default.
1 change: 1 addition & 0 deletions changelog.d/5198.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent registration for user ids that are to long to fit into a state key. Contributed by Reid Anderson.
1 change: 1 addition & 0 deletions changelog.d/5209.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for relations (aka reactions and edits).
1 change: 1 addition & 0 deletions changelog.d/5210.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a new room version which uses a new event ID format.
1 change: 1 addition & 0 deletions changelog.d/5211.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add experimental support for relations (aka reactions and edits).
2 changes: 2 additions & 0 deletions debian/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vagrant
*.log
23 changes: 23 additions & 0 deletions debian/test/provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
#
# provisioning script for vagrant boxes for testing the matrix-synapse debs.
#
# Will install the most recent matrix-synapse-py3 deb for this platform from
# the /debs directory.

set -e

apt-get update
apt-get install -y lsb-release

deb=`ls /debs/matrix-synapse-py3_*+$(lsb_release -cs)*.deb | sort | tail -n1`

debconf-set-selections <<EOF
matrix-synapse matrix-synapse/report-stats boolean false
matrix-synapse matrix-synapse/server-name string localhost:18448
EOF

dpkg -i "$deb"

sed -i -e '/port: 8...$/{s/8448/18448/; s/8008/18008/}' -e '$aregistration_shared_secret: secret' /etc/matrix-synapse/homeserver.yaml
systemctl restart matrix-synapse
13 changes: 13 additions & 0 deletions debian/test/stretch/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

ver = `cd ../../..; dpkg-parsechangelog -S Version`.strip()

Vagrant.configure("2") do |config|
config.vm.box = "debian/stretch64"

config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder "../../../../debs", "/debs", type: "nfs"

config.vm.provision "shell", path: "../provision.sh"
end
10 changes: 10 additions & 0 deletions debian/test/xenial/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"

config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder "../../../../debs", "/debs"
config.vm.provision "shell", path: "../provision.sh"
end
45 changes: 22 additions & 23 deletions docs/postgres.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ Using Postgres

Postgres version 9.4 or later is known to work.

Install postgres client libraries
=================================

Synapse will require the python postgres client library in order to connect to
a postgres database.

* If you are using the `matrix.org debian/ubuntu
packages <../INSTALL.md#matrixorg-packages>`_,
the necessary libraries will already be installed.

* For other pre-built packages, please consult the documentation from the
relevant package.

* If you installed synapse `in a virtualenv
<../INSTALL.md#installing-from-source>`_, you can install the library with::

~/synapse/env/bin/pip install matrix-synapse[postgres]

(substituting the path to your virtualenv for ``~/synapse/env``, if you used a
different path). You will require the postgres development files. These are in
the ``libpq-dev`` package on Debian-derived distributions.

Set up database
===============

Expand All @@ -26,29 +48,6 @@ encoding use, e.g.::
This would create an appropriate database named ``synapse`` owned by the
``synapse_user`` user (which must already exist).

Set up client in Debian/Ubuntu
===========================

Postgres support depends on the postgres python connector ``psycopg2``. In the
virtual env::

sudo apt-get install libpq-dev
pip install psycopg2

Set up client in RHEL/CentOs 7
==============================

Make sure you have the appropriate version of postgres-devel installed. For a
postgres 9.4, use the postgres 9.4 packages from
[here](https://wiki.postgresql.org/wiki/YUM_Installation).

As with Debian/Ubuntu, postgres support depends on the postgres python connector
``psycopg2``. In the virtual env::

sudo yum install postgresql-devel libpqxx-devel.x86_64
export PATH=/usr/pgsql-9.4/bin/:$PATH
pip install psycopg2

Tuning Postgres
===============

Expand Down
6 changes: 6 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ listeners:
#
#require_membership_for_aliases: false

# Whether to allow per-room membership profiles through the send of membership
# events with profile information that differ from the target's global profile.
# Defaults to 'true'.
#
#allow_per_room_profiles: false


## TLS ##

Expand Down
11 changes: 11 additions & 0 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
# the maximum length for a room alias is 255 characters
MAX_ALIAS_LENGTH = 255

# the maximum length for a user id is 255 characters
MAX_USERID_LENGTH = 255


class Membership(object):

Expand Down Expand Up @@ -116,3 +119,11 @@ class UserTypes(object):
"""
SUPPORT = "support"
ALL_USER_TYPES = (SUPPORT,)


class RelationTypes(object):
"""The types of relations known to this server.
"""
ANNOTATION = "m.annotation"
REPLACE = "m.replace"
REFERENCE = "m.reference"
13 changes: 11 additions & 2 deletions synapse/api/room_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ class EventFormatVersions(object):
"""This is an internal enum for tracking the version of the event format,
independently from the room version.
"""
V1 = 1 # $id:server format
V2 = 2 # MSC1659-style $hash format: introduced for room v3
V1 = 1 # $id:server event id format
V2 = 2 # MSC1659-style $hash event id format: introduced for room v3
V3 = 3 # MSC1884-style $hash format: introduced for room v4


KNOWN_EVENT_FORMAT_VERSIONS = {
EventFormatVersions.V1,
EventFormatVersions.V2,
EventFormatVersions.V3,
}


Expand Down Expand Up @@ -75,6 +77,12 @@ class RoomVersions(object):
EventFormatVersions.V2,
StateResolutionVersions.V2,
)
EVENTID_NOSLASH_TEST = RoomVersion(
"eventid-noslash-test",
RoomDisposition.UNSTABLE,
EventFormatVersions.V3,
StateResolutionVersions.V2,
)


# the version we will give rooms which are created on this server
Expand All @@ -87,5 +95,6 @@ class RoomVersions(object):
RoomVersions.V2,
RoomVersions.V3,
RoomVersions.STATE_V2_TEST,
RoomVersions.EVENTID_NOSLASH_TEST,
)
} # type: dict[str, RoomVersion]
16 changes: 16 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017-2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,6 +101,11 @@ def read_config(self, config):
"block_non_admin_invites", False,
)

# Whether to enable experimental MSC1849 (aka relations) support
self.experimental_msc1849_support_enabled = config.get(
"experimental_msc1849_support_enabled", False,
)

# Options to control access by tracking MAU
self.limit_usage_by_mau = config.get("limit_usage_by_mau", False)
self.max_mau_value = 0
Expand Down Expand Up @@ -173,6 +179,10 @@ def read_config(self, config):
"require_membership_for_aliases", True,
)

# Whether to allow per-room membership profiles through the send of membership
# events with profile information that differ from the target's global profile.
self.allow_per_room_profiles = config.get("allow_per_room_profiles", True)

self.listeners = []
for listener in config.get("listeners", []):
if not isinstance(listener.get("port", None), int):
Expand Down Expand Up @@ -566,6 +576,12 @@ def default_config(self, server_name, data_dir_path, **kwargs):
# Defaults to 'true'.
#
#require_membership_for_aliases: false
# Whether to allow per-room membership profiles through the send of membership
# events with profile information that differ from the target's global profile.
# Defaults to 'true'.
#
#allow_per_room_profiles: false
""" % locals()

def read_arguments(self, args):
Expand Down
23 changes: 22 additions & 1 deletion synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,32 @@ def __str__(self):
return self.__repr__()

def __repr__(self):
return "<FrozenEventV2 event_id='%s', type='%s', state_key='%s'>" % (
return "<%s event_id='%s', type='%s', state_key='%s'>" % (
self.__class__.__name__,
self.event_id,
self.get("type", None),
self.get("state_key", None),
)


class FrozenEventV3(FrozenEventV2):
"""FrozenEventV3, which differs from FrozenEventV2 only in the event_id format"""
format_version = EventFormatVersions.V3 # All events of this type are V3

@property
def event_id(self):
# We have to import this here as otherwise we get an import loop which
# is hard to break.
from synapse.crypto.event_signing import compute_event_reference_hash

if self._event_id:
return self._event_id
self._event_id = "$" + encode_base64(
compute_event_reference_hash(self)[1], urlsafe=True
)
return self._event_id


def room_version_to_event_format(room_version):
"""Converts a room version string to the event format
Expand Down Expand Up @@ -376,6 +395,8 @@ def event_type_from_format_version(format_version):
return FrozenEvent
elif format_version == EventFormatVersions.V2:
return FrozenEventV2
elif format_version == EventFormatVersions.V3:
return FrozenEventV3
else:
raise Exception(
"No event format %r" % (format_version,)
Expand Down
56 changes: 52 additions & 4 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from twisted.internet import defer

from synapse.api.constants import EventTypes
from synapse.api.constants import EventTypes, RelationTypes
from synapse.util.async_helpers import yieldable_gather_results

from . import EventBase
Expand Down Expand Up @@ -324,8 +324,12 @@ class EventClientSerializer(object):
"""

def __init__(self, hs):
pass
self.store = hs.get_datastore()
self.experimental_msc1849_support_enabled = (
hs.config.experimental_msc1849_support_enabled
)

@defer.inlineCallbacks
def serialize_event(self, event, time_now, **kwargs):
"""Serializes a single event.
Expand All @@ -337,8 +341,52 @@ def serialize_event(self, event, time_now, **kwargs):
Returns:
Deferred[dict]: The serialized event
"""
event = serialize_event(event, time_now, **kwargs)
return defer.succeed(event)
# To handle the case of presence events and the like
if not isinstance(event, EventBase):
defer.returnValue(event)

event_id = event.event_id
serialized_event = serialize_event(event, time_now, **kwargs)

# If MSC1849 is enabled then we need to look if thre are any relations
# we need to bundle in with the event
if self.experimental_msc1849_support_enabled:
annotations = yield self.store.get_aggregation_groups_for_event(
event_id,
)
references = yield self.store.get_relations_for_event(
event_id, RelationTypes.REFERENCE, direction="f",
)

if annotations.chunk:
r = serialized_event["unsigned"].setdefault("m.relations", {})
r[RelationTypes.ANNOTATION] = annotations.to_dict()

if references.chunk:
r = serialized_event["unsigned"].setdefault("m.relations", {})
r[RelationTypes.REFERENCE] = references.to_dict()

edit = None
if event.type == EventTypes.Message:
edit = yield self.store.get_applicable_edit(event_id)

if edit:
# If there is an edit replace the content, preserving existing
# relations.

relations = event.content.get("m.relates_to")
serialized_event["content"] = edit.content.get("m.new_content", {})
if relations:
serialized_event["content"]["m.relates_to"] = relations
else:
serialized_event["content"].pop("m.relates_to", None)

r = serialized_event["unsigned"].setdefault("m.relations", {})
r[RelationTypes.REPLACE] = {
"event_id": edit.event_id,
}

defer.returnValue(serialized_event)

def serialize_events(self, events, time_now, **kwargs):
"""Serializes multiple events.
Expand Down
Loading

0 comments on commit d142e51

Please sign in to comment.