diff --git a/MAP.rst b/MAP.rst new file mode 100644 index 000000000..0f8e9818a --- /dev/null +++ b/MAP.rst @@ -0,0 +1,35 @@ +Directory Structure +=================== + +Warning: this may be a bit stale... + +:: + + . + ├── cmdclient Basic CLI python Matrix client + ├── demo Scripts for running standalone Matrix demos + ├── docs All doc, including the draft Matrix API spec + │   ├── client-server The client-server Matrix API spec + │   ├── model Domain-specific elements of the Matrix API spec + │   ├── server-server The server-server model of the Matrix API spec + │   └── sphinx The internal API doc of the Synapse homeserver + ├── experiments Early experiments of using Synapse's internal APIs + ├── graph Visualisation of Matrix's distributed message store + ├── synapse The reference Matrix homeserver implementation + │   ├── api Common building blocks for the APIs + │   │   ├── events Definition of state representation Events + │   │   └── streams Definition of streamable Event objects + │   ├── app The __main__ entry point for the homeserver + │   ├── crypto The PKI client/server used for secure federation + │   │   └── resource PKI helper objects (e.g. keys) + │   ├── federation Server-server state replication logic + │   ├── handlers The main business logic of the homeserver + │   ├── http Wrappers around Twisted's HTTP server & client + │   ├── rest Servlet-style RESTful API + │   ├── storage Persistence subsystem (currently only sqlite3) + │   │   └── schema sqlite persistence schema + │   └── util Synapse-specific utilities + ├── tests Unit tests for the Synapse homeserver + └── webclient Basic AngularJS Matrix web client + + diff --git a/README.rst b/README.rst index c58ebf0db..319bbb6e4 100644 --- a/README.rst +++ b/README.rst @@ -1,16 +1,54 @@ -About -===== +Quick Start +=========== -Matrix is an ambitious new ecosystem for open federated Instant Messaging and VoIP[1]. +Matrix is an ambitious new ecosystem for open federated Instant Messaging and +VoIP[1]. The basics you need to know to get up and running are: -Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard, providing: + - Chatrooms are distributed and do not exist on any single server. Rooms + can be found using names like ``#matrix:matrix.org`` or + ``#test:localhost:8080`` or they can be ephemeral. + + - Matrix user IDs look like ``@matthew:matrix.org`` (although in the future + you will normally refer to yourself and others using a 3PID: email + address, phone number, etc rather than manipulating matrix user IDs) + +The overall architecture is:: + + client <----> homeserver <=================> homeserver <-----> client + e.g. matrix.org:8080 e.g. mydomain.net:8080 + +To get up and running: + + - To simply play with an **existing** homeserver you can + just go straight to http://matrix.org/alpha. + + - To run your own **private** homeserver on localhost:8080, install synapse + with ``python setup.py develop --user`` and then run one with + ``python synapse/app/homeserver.py`` + + - To run your own webclient: + ``cd webclient; python -m SimpleHTTPServer`` and hit http://localhost:8000 + in your web browser (a recent Chrome, Safari or Firefox for now, + please...) + + - To make the homeserver **public** and let it exchange messages with + other homeservers and participate in the overall Matrix federation, open + up port 8080 and run ``python synapse/app/homeserver.py --host + machine.my.domain.name``. Then come join ``#matrix:matrix.org`` and + say hi! :) + +About Matrix +============ + +Matrix specifies a set of pragmatic RESTful HTTP JSON APIs for VoIP and IM as an +open standard, providing: - Creating and managing fully distributed chat rooms with no single points of control or failure - - Eventually-consistent cryptographically secure synchronisation of room - state across a global open network of federated servers and services + - Eventually-consistent cryptographically secure[2] synchronisation of room + state across a global open network of federated servers and services - Sending and receiving extensible messages in a room with (optional) - end-to-end encryption[2] + end-to-end encryption[3] - Inviting, joining, leaving, kicking, banning room members - Managing user accounts (registration, login, logout) - Using 3rd Party IDs (3PIDs) such as email addresses, phone numbers, @@ -18,11 +56,11 @@ Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard, - Placing 1:1 VoIP and Video calls (in development) These APIs are intended to be implemented on a wide range of servers, services -and clients which then form the Matrix ecosystem, and allow developers to build -messaging and VoIP functionality on top of the open Matrix community rather than -using closed or proprietary solutions. The hope is for Matrix to act as the -building blocks for a new generation of fully open and interoperable messaging -and VoIP apps for the internet. +and clients, letting developers build messaging and VoIP functionality on top of +the entirely open Matrix ecosystem rather than using closed or proprietary +solutions. The hope is for Matrix to act as the building blocks for a new +generation of fully open and interoperable messaging and VoIP apps for the +internet. Synapse is a reference "homeserver" implementation of Matrix from the core development team at matrix.org, written in Python/Twisted for clarity and @@ -38,57 +76,30 @@ control and own your own communications and history or use one hosted by someone else (e.g. matrix.org) - there is no single point of control or mandatory service provider in Matrix, unlike WhatsApp, Facebook, Hangouts, etc. -Synapse ships with two basic demo Matrix clients: webclient (a basic group chat web client demo implemented in AngularJS) and cmdclient (a basic Python commandline utility which lets you easily see what the JSON APIs are up to). +Synapse ships with two basic demo Matrix clients: webclient (a basic group chat +web client demo implemented in AngularJS) and cmdclient (a basic Python +commandline utility which lets you easily see what the JSON APIs are up to). -We'd like to invite you to take a look at the Matrix spec, try to run a homeserver, and join the existing Matrix chatrooms already out there, experiment with the APIs and the demo clients, and let us know your thoughts at https://github.com/matrix-org/synapse/issues or at matrix@matrix.org. +We'd like to invite you to take a look at the Matrix spec, try to run a +homeserver, and join the existing Matrix chatrooms already out there, experiment +with the APIs and the demo clients, and let us know your thoughts at +https://github.com/matrix-org/synapse/issues or at matrix@matrix.org. Thanks for trying Matrix! [1] VoIP currently in development -[2] End-to-end encryption is currently in development +[2] Cryptographic signing of messages isn't turned on yet + +[3] End-to-end encryption is currently in development -Directory Structure -=================== - -:: - - . - ├── cmdclient Basic CLI python Matrix client - ├── demo Scripts for running standalone Matrix demos - ├── docs All doc, including the draft Matrix API spec - │   ├── client-server The client-server Matrix API spec - │   ├── model Domain-specific elements of the Matrix API spec - │   ├── server-server The server-server model of the Matrix API spec - │   └── sphinx The internal API doc of the Synapse homeserver - ├── experiments Early experiments of using Synapse's internal APIs - ├── graph Visualisation of Matrix's distributed message store - ├── synapse The reference Matrix homeserver implementation - │   ├── api Common building blocks for the APIs - │   │   ├── events Definition of state representation Events - │   │   └── streams Definition of streamable Event objects - │   ├── app The __main__ entry point for the homeserver - │   ├── crypto The PKI client/server used for secure federation - │   │   └── resource PKI helper objects (e.g. keys) - │   ├── federation Server-server state replication logic - │   ├── handlers The main business logic of the homeserver - │   ├── http Wrappers around Twisted's HTTP server & client - │   ├── rest Servlet-style RESTful API - │   ├── storage Persistence subsystem (currently only sqlite3) - │   │   └── schema sqlite persistence schema - │   └── util Synapse-specific utilities - ├── tests Unit tests for the Synapse homeserver - └── webclient Basic AngularJS Matrix web client - - -Installation -============ +Homeserver Installation +======================= First, the dependencies need to be installed. Start by installing 'python2.7-dev' and the various tools of the compiler toolchain. - -N.B. that python 2.x where x >= 7 is required. +N.B. synapse requires python 2.x where x >= 7 Installing prerequisites on ubuntu:: @@ -102,6 +113,18 @@ The homeserver has a number of external dependencies, that are easiest to install by making setup.py do so, in --user mode:: $ python setup.py develop --user + +You'll need a version of setuptools new enough to know about git, so you +may need to also run: + + $ sudo apt-get install python-pip + $ sudo pip install --upgrade setuptools + +If you get errors about ``sodium.h`` being missing, you may also need to +manually install a newer PyNaCl via pip as setuptools installs an old one. Or +you can check PyNaCl out of git directly (https://github.com/pyca/pynacl) and +installing it. Installing PyNaCl using pip may also work (remember to remove any +other versions installed by setuputils in, for example, ~/.local/lib). This will run a process of downloading and installing into your user's .local/lib directory all of the required dependencies that are @@ -119,8 +142,8 @@ This should end with a 'PASSED' result:: PASSED (successes=143) -Running The Synapse Homeserver -============================== +Setting up Federation +===================== In order for other homeservers to send messages to your server, it will need to be publicly visible on the internet, and they will need to know its host name. @@ -161,6 +184,14 @@ For the initial alpha release, the homeserver is not speaking TLS for either client-server or server-server traffic for ease of debugging. We have also not spent any time yet getting the homeserver to run behind loadbalancers. +Running a Demo Federation of Homeservers +---------------------------------------- + +If you want to get up and running quickly with a trio of homeservers in a +private federation (``localhost:8080``, ``localhost:8081`` and +``localhost:8082``) which you can then access through the webclient running at http://localhost:8080. Simply run:: + + $ demo/start.sh Running The Demo Web Client =========================== @@ -200,19 +231,44 @@ synapse sandbox running on localhost) Logging In To An Existing Account --------------------------------- -[[TODO(paul): It seems the current web client still requests an access_token - - I suspect this part will need updating before we can point people at how to - perform e.g. user+password or 3PID authenticated login]] +Just enter the ``@localpart:my.domain.here`` matrix user ID and password into the form and click the Login button. -Building Documentation -====================== +Identity Servers +================ -Before building documentation install spinx and sphinxcontrib-napoleon:: +The job of authenticating 3PIDs and tracking which 3PIDs are associated with a +given matrix user is very security-sensitive, as there is obvious risk of spam +if it is too easy to sign up for Matrix accounts or harvest 3PID data. Meanwhile +the job of publishing the end-to-end encryption public keys for Matrix users is +also very security-sensitive for similar reasons. + +Therefore the role of managing trusted identity in the Matrix ecosystem is +farmed out to a cluster of known trusted ecosystem partners, who run 'Matrix +Identity Servers' such as ``sydent``, whose role is purely to authenticate and +track 3PID logins and publish end-user public keys. + +It's currently early days for identity servers as Matrix is not yet using 3PIDs +as the primary means of identity and E2E encryption is not complete. As such, +we're not yet running an identity server in public. + + +Where's the spec?! +================== + +For now, please go spelunking in the ``docs/`` directory to find out. + + +Building Internal API Documentation +=================================== + +Before building internal API documentation install spinx and +sphinxcontrib-napoleon:: $ pip install sphinx $ pip install sphinxcontrib-napoleon -Building documentation:: +Building internal API documentation:: $ python setup.py build_sphinx + diff --git a/cmdclient/console.py b/cmdclient/console.py index 595ce429c..6c6e2085b 100755 --- a/cmdclient/console.py +++ b/cmdclient/console.py @@ -1,4 +1,19 @@ -#! /usr/bin/env python +#!/usr/bin/env python + +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ Starts a synapse client console. """ from twisted.internet import reactor, defer, threads diff --git a/cmdclient/http.py b/cmdclient/http.py index e71593837..9de6be9b7 100644 --- a/cmdclient/http.py +++ b/cmdclient/http.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.web.client import Agent, readBody from twisted.web.http_headers import Headers from twisted.internet import defer, reactor diff --git a/docs/server-server/specification.rst b/docs/server-server/specification.rst index e1e49cc06..a386bd3e7 100644 --- a/docs/server-server/specification.rst +++ b/docs/server-server/specification.rst @@ -116,9 +116,13 @@ federation.]] Protocol URLs ============= +All these URLs are namespaced within a prefix of + + /matrix/federation/v1/... + For active pushing of messages representing live activity "as it happens": - PUT /send/:transaction_id/ + PUT .../send/:transaction_id/ Body: JSON encoding of a single Transaction Response: [[TODO(paul): I don't actually understand what @@ -132,7 +136,7 @@ For active pushing of messages representing live activity "as it happens": To fetch a particular PDU: - GET /pdu/:origin/:pdu_id/ + GET .../pdu/:origin/:pdu_id/ Response: JSON encoding of a single Transaction containing one PDU @@ -142,7 +146,7 @@ To fetch a particular PDU: To fetch all the state of a given context: - GET /state/:context/ + GET .../state/:context/ Response: JSON encoding of a single Transaction containing multiple PDUs @@ -153,7 +157,7 @@ To fetch all the state of a given context: To paginate events on a given context: - GET /paginate/:context/ + GET .../paginate/:context/ Query args: v, limit Response: JSON encoding of a single Transaction containing multiple PDUs @@ -167,7 +171,7 @@ To paginate events on a given context: To stream events all the events: - GET /pull/ + GET .../pull/ Query args: origin, v Response: JSON encoding of a single Transaction consisting of multiple PDUs diff --git a/experiments/cursesio.py b/experiments/cursesio.py index 83b4a9f18..31fbda550 100644 --- a/experiments/cursesio.py +++ b/experiments/cursesio.py @@ -1,3 +1,17 @@ +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import curses import curses.wrapper from curses.ascii import isprint diff --git a/experiments/test_messaging.py b/experiments/test_messaging.py index 9a4542517..f4ae71bfc 100644 --- a/experiments/test_messaging.py +++ b/experiments/test_messaging.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ This is an example of using the server to server implementation to do a basic chat style thing. It accepts commands from stdin and outputs to stdout. diff --git a/graph/graph.py b/graph/graph.py index c60077341..03af12cbb 100644 --- a/graph/graph.py +++ b/graph/graph.py @@ -1,3 +1,17 @@ +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import sqlite3 import pydot diff --git a/scripts/copyrighter.pl b/scripts/copyrighter.pl new file mode 100755 index 000000000..e476c9cc8 --- /dev/null +++ b/scripts/copyrighter.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl -pi +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +$copyright = < """ from twisted.internet import defer diff --git a/synapse/rest/profile.py b/synapse/rest/profile.py index f384227c2..3d0427bf7 100644 --- a/synapse/rest/profile.py +++ b/synapse/rest/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with profile: /profile/ """ from twisted.internet import defer diff --git a/synapse/rest/public.py b/synapse/rest/public.py index 6fd1731a6..3430c8049 100644 --- a/synapse/rest/public.py +++ b/synapse/rest/public.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with public paths: /public""" from twisted.internet import defer diff --git a/synapse/rest/register.py b/synapse/rest/register.py index f1cbce5c6..eb457562b 100644 --- a/synapse/rest/register.py +++ b/synapse/rest/register.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with registration: /register""" from twisted.internet import defer diff --git a/synapse/rest/room.py b/synapse/rest/room.py index c96de5e65..228bc9623 100644 --- a/synapse/rest/room.py +++ b/synapse/rest/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with rooms: /rooms/ """ from twisted.internet import defer diff --git a/synapse/rest/webclient.py b/synapse/rest/webclient.py new file mode 100644 index 000000000..75a425c14 --- /dev/null +++ b/synapse/rest/webclient.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from synapse.rest.base import RestServlet + +import logging +import re + +logger = logging.getLogger(__name__) + + +class WebClientRestServlet(RestServlet): + # No PATTERN; we have custom dispatch rules here + + def register(self, http_server): + http_server.register_path("GET", + re.compile("^/$"), + self.on_GET_redirect) + http_server.register_path("GET", + re.compile("^/matrix/client$"), + self.on_GET) + + def on_GET(self, request): + return (200, "not implemented") + + def on_GET_redirect(self, request): + request.setHeader("Location", request.uri + "matrix/client") + return (302, None) + + +def register_servlets(hs, http_server): + logger.info("Registering web client.") + WebClientRestServlet(hs).register(http_server) \ No newline at end of file diff --git a/synapse/server.py b/synapse/server.py index 0aff75f39..0211972d0 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + # This file provides some classes for setting up (partially-populated) # homeservers; either as a full homeserver as a real application, or a small # partial one for unit test mocking. @@ -171,6 +172,10 @@ class HomeServer(BaseHomeServer): return Distributor() def register_servlets(self): - """Simply building the ServletFactory is sufficient to have it - register.""" - self.get_rest_servlet_factory() + """ Register all servlets associated with this HomeServer. + + Args: + host_web_client (bool): True to host the web client as well. + """ + # Simply building the ServletFactory is sufficient to have it register + factory = self.get_rest_servlet_factory() diff --git a/synapse/state.py b/synapse/state.py index 439c0b519..b081de8f4 100644 --- a/synapse/state.py +++ b/synapse/state.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.federation.pdu_codec import encode_event_id diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index ec93f9f8a..3c27428c0 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.events.room import ( RoomMemberEvent, MessageEvent, RoomTopicEvent, FeedbackEvent, RoomConfigEvent diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 4d98a6fd0..65f691ead 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import logging from twisted.internet import defer diff --git a/synapse/storage/directory.py b/synapse/storage/directory.py index 71fa9d9c9..b22ce02f3 100644 --- a/synapse/storage/directory.py +++ b/synapse/storage/directory.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore from twisted.internet import defer diff --git a/synapse/storage/feedback.py b/synapse/storage/feedback.py index 2b421e334..9bd562c76 100644 --- a/synapse/storage/feedback.py +++ b/synapse/storage/feedback.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from synapse.api.events.room import FeedbackEvent diff --git a/synapse/storage/message.py b/synapse/storage/message.py index 4822fa709..7bb69c138 100644 --- a/synapse/storage/message.py +++ b/synapse/storage/message.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from synapse.api.events.room import MessageEvent diff --git a/synapse/storage/pdu.py b/synapse/storage/pdu.py index a1cdde0a3..202d7f6cb 100644 --- a/synapse/storage/pdu.py +++ b/synapse/storage/pdu.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table, JoinHelper from synapse.util.logutils import log_function diff --git a/synapse/storage/presence.py b/synapse/storage/presence.py index e57ddaf14..6f5b042c2 100644 --- a/synapse/storage/presence.py +++ b/synapse/storage/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore diff --git a/synapse/storage/profile.py b/synapse/storage/profile.py index d2f24930c..91dd56503 100644 --- a/synapse/storage/profile.py +++ b/synapse/storage/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py index 4a970dd54..68cdfbb4c 100644 --- a/synapse/storage/registration.py +++ b/synapse/storage/registration.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from sqlite3 import IntegrityError diff --git a/synapse/storage/room.py b/synapse/storage/room.py index 174cbcf3d..a97162831 100644 --- a/synapse/storage/room.py +++ b/synapse/storage/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from sqlite3 import IntegrityError @@ -92,7 +93,10 @@ class RoomStore(SQLBaseStore): latest_topic = ("SELECT max(room_data.id) FROM room_data WHERE " + "room_data.type = ? GROUP BY room_id") - query = ("SELECT rooms.*, room_data.content FROM rooms LEFT JOIN " + query = ("SELECT rooms.*, room_data.content, room_alias FROM rooms " + + "LEFT JOIN " + + "room_aliases ON room_aliases.room_id = rooms.room_id " + + "LEFT JOIN " + "room_data ON rooms.room_id = room_data.room_id WHERE " + "(room_data.id IN (" + latest_topic + ") " + "OR room_data.id IS NULL) AND rooms.is_public = ?") @@ -102,7 +106,7 @@ class RoomStore(SQLBaseStore): ) # return only the keys the specification expects - ret_keys = ["room_id", "topic"] + ret_keys = ["room_id", "topic", "room_alias"] # extract topic from the json (icky) FIXME for i, room_row in enumerate(res): diff --git a/synapse/storage/roomdata.py b/synapse/storage/roomdata.py index 781d47793..cc04d1ba1 100644 --- a/synapse/storage/roomdata.py +++ b/synapse/storage/roomdata.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table import collections diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index e6e761779..ef73be4af 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.types import UserID diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index c3b1bfeb3..1dedffac4 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore from .message import MessagesTable from .feedback import FeedbackTable diff --git a/synapse/storage/transactions.py b/synapse/storage/transactions.py index aa41e2ad7..a277e4971 100644 --- a/synapse/storage/transactions.py +++ b/synapse/storage/transactions.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from .pdu import PdusTable diff --git a/synapse/types.py b/synapse/types.py index 1adc95bbb..054b1e713 100644 --- a/synapse/types.py +++ b/synapse/types.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError from collections import namedtuple diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py index 5361cb7ec..3ea431a7f 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import reactor import time diff --git a/synapse/util/async.py b/synapse/util/async.py index e04db8e28..ebbdc00ae 100644 --- a/synapse/util/async.py +++ b/synapse/util/async.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer, reactor diff --git a/synapse/util/distributor.py b/synapse/util/distributor.py index 32d19402b..9605d7d1b 100644 --- a/synapse/util/distributor.py +++ b/synapse/util/distributor.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer import logging diff --git a/synapse/util/jsonobject.py b/synapse/util/jsonobject.py index 190a80a32..e2840b59f 100644 --- a/synapse/util/jsonobject.py +++ b/synapse/util/jsonobject.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import copy class JsonEncodedObject(object): diff --git a/synapse/util/lockutils.py b/synapse/util/lockutils.py index e4d609d84..758be0b90 100644 --- a/synapse/util/lockutils.py +++ b/synapse/util/lockutils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer import logging diff --git a/synapse/util/logutils.py b/synapse/util/logutils.py index 08d5aafca..9270a1790 100644 --- a/synapse/util/logutils.py +++ b/synapse/util/logutils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from inspect import getcallargs import logging diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index 91550583a..e1b0796e5 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import random import string diff --git a/tests/__init__.py b/tests/__init__.py index 40a96afc6..2216c0f1c 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,15 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/tests/events/__init__.py b/tests/events/__init__.py index 40a96afc6..2216c0f1c 100644 --- a/tests/events/__init__.py +++ b/tests/events/__init__.py @@ -1 +1,15 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/tests/events/test_events.py b/tests/events/test_events.py index 11d3d09c9..35e9c68f5 100644 --- a/tests/events/test_events.py +++ b/tests/events/test_events.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from synapse.api.events import SynapseEvent import unittest diff --git a/tests/federation/test_federation.py b/tests/federation/test_federation.py index 1792f9de5..f493ee253 100644 --- a/tests/federation/test_federation.py +++ b/tests/federation/test_federation.py @@ -1,3 +1,17 @@ +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # trial imports from twisted.internet import defer from twisted.trial import unittest @@ -82,7 +96,7 @@ class FederationTestCase(unittest.TestCase): # Empty context initially (code, response) = yield self.mock_http_server.trigger("GET", - "/state/my-context/", None) + "/matrix/federation/v1/state/my-context/", None) self.assertEquals(200, code) self.assertFalse(response["pdus"]) @@ -107,7 +121,7 @@ class FederationTestCase(unittest.TestCase): ) (code, response) = yield self.mock_http_server.trigger("GET", - "/state/my-context/", None) + "/matrix/federation/v1/state/my-context/", None) self.assertEquals(200, code) self.assertEquals(1, len(response["pdus"])) @@ -118,7 +132,7 @@ class FederationTestCase(unittest.TestCase): ) (code, response) = yield self.mock_http_server.trigger("GET", - "/pdu/red/abc123def456/", None) + "/matrix/federation/v1/pdu/red/abc123def456/", None) self.assertEquals(404, code) # Now insert such a PDU @@ -137,7 +151,7 @@ class FederationTestCase(unittest.TestCase): ) (code, response) = yield self.mock_http_server.trigger("GET", - "/pdu/red/abc123def456/", None) + "/matrix/federation/v1/pdu/red/abc123def456/", None) self.assertEquals(200, code) self.assertEquals(1, len(response["pdus"])) self.assertEquals("m.text", response["pdus"][0]["pdu_type"]) @@ -163,7 +177,7 @@ class FederationTestCase(unittest.TestCase): self.mock_http_client.put_json.assert_called_with( "remote", - path="/send/1000000/", + path="/matrix/federation/v1/send/1000000/", data={ "ts": 1000000, "origin": "test", @@ -198,7 +212,7 @@ class FederationTestCase(unittest.TestCase): # MockClock ensures we can guess these timestamps self.mock_http_client.put_json.assert_called_with( "remote", - path="/send/1000000/", + path="/matrix/federation/v1/send/1000000/", data={ "origin": "test", "ts": 1000000, @@ -220,7 +234,8 @@ class FederationTestCase(unittest.TestCase): self.federation.register_edu_handler("m.test", recv_observer) - yield self.mock_http_server.trigger("PUT", "/send/1001000/", + yield self.mock_http_server.trigger("PUT", + "/matrix/federation/v1/send/1001000/", """{ "origin": "remote", "ts": 1001000, diff --git a/tests/federation/test_pdu_codec.py b/tests/federation/test_pdu_codec.py index 688182fa5..2c546040b 100644 --- a/tests/federation/test_pdu_codec.py +++ b/tests/federation/test_pdu_codec.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.trial import unittest from synapse.federation.pdu_codec import ( diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py index 880cfb47b..bdee7cfad 100644 --- a/tests/handlers/test_federation.py +++ b/tests/handlers/test_federation.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.internet import defer from twisted.trial import unittest diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index e81435752..2299a2a7b 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.trial import unittest from twisted.internet import defer @@ -13,7 +27,7 @@ from synapse.handlers.presence import PresenceHandler, UserPresenceCache OFFLINE = PresenceState.OFFLINE -BUSY = PresenceState.BUSY +UNAVAILABLE = PresenceState.UNAVAILABLE ONLINE = PresenceState.ONLINE @@ -135,12 +149,12 @@ class PresenceStateTestCase(unittest.TestCase): yield self.handler.set_state( target_user=self.u_apple, auth_user=self.u_apple, - state={"state": BUSY, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) mocked_set.assert_called_with("apple", - {"state": 1, "status_msg": "Away"}) + {"state": UNAVAILABLE, "status_msg": "Away"}) self.mock_start.assert_called_with(self.u_apple, - state={"state": 1, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) yield self.handler.set_state( target_user=self.u_apple, auth_user=self.u_apple, @@ -541,7 +555,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2}, + "state": "online"}, ], }), call( @@ -550,7 +564,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2}, + "state": "online"}, ], }) ], any_order=True) @@ -568,7 +582,7 @@ class PresencePushTestCase(unittest.TestCase): "remote", "m.presence", { "push": [ {"user_id": "@potato:remote", - "state": 2}, + "state": "online"}, ], } ) @@ -632,7 +646,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2}, + "state": "online"}, ], }), call( @@ -641,7 +655,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@banana:test", - "state": 0}, + "state": "offline"}, ], }), ], any_order=True) @@ -652,7 +666,7 @@ class PresencePushTestCase(unittest.TestCase): self.handler._user_cachemap[self.u_clementine] = UserPresenceCache() self.handler._user_cachemap[self.u_clementine].update( - {"state": PresenceState.ONLINE}, self.u_clementine) + {"state": ONLINE}, self.u_clementine) self.room_members.append(self.u_potato) yield self.distributor.fire("user_joined_room", self.u_clementine, @@ -666,7 +680,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@clementine:test", - "state": 2}, + "state": "online"}, ], }), ) @@ -868,7 +882,7 @@ class PresencePollingTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@banana:test", - "state": 0, + "state": "offline", "status_msg": None}, ], }, diff --git a/tests/handlers/test_presencelike.py b/tests/handlers/test_presencelike.py index c194e4dd7..224cf646f 100644 --- a/tests/handlers/test_presencelike.py +++ b/tests/handlers/test_presencelike.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """This file contains tests of the "presence-like" data that is shared between presence and profiles; namely, the displayname and avatar_url.""" @@ -15,7 +29,7 @@ from synapse.handlers.profile import ProfileHandler OFFLINE = PresenceState.OFFLINE -BUSY = PresenceState.BUSY +UNAVAILABLE = PresenceState.UNAVAILABLE ONLINE = PresenceState.ONLINE @@ -111,12 +125,12 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase): yield self.handlers.presence_handler.set_state( target_user=self.u_apple, auth_user=self.u_apple, - state={"state": BUSY, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) mocked_set.assert_called_with("apple", - {"state": 1, "status_msg": "Away"}) + {"state": UNAVAILABLE, "status_msg": "Away"}) self.mock_start.assert_called_with(self.u_apple, - state={"state": 1, "status_msg": "Away", + state={"state": UNAVAILABLE, "status_msg": "Away", "displayname": "Frank", "avatar_url": "http://foo"}) @@ -206,7 +220,7 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2, + "state": "online", "displayname": "Frank", "avatar_url": "http://foo"}, ], @@ -224,7 +238,7 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase): "remote", "m.presence", { "push": [ {"user_id": "@potato:remote", - "state": 2, + "state": "online", "displayname": "Frank", "avatar_url": "http://foo"}, ], diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py index a4408e9fd..34af7afd0 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.trial import unittest from twisted.internet import defer diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py index 26b233bcc..99067da6a 100644 --- a/tests/handlers/test_room.py +++ b/tests/handlers/test_room.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.internet import defer from twisted.trial import unittest diff --git a/tests/rest/__init__.py b/tests/rest/__init__.py index 40a96afc6..2216c0f1c 100644 --- a/tests/rest/__init__.py +++ b/tests/rest/__init__.py @@ -1 +1,15 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/tests/rest/test_events.py b/tests/rest/test_events.py index fa40e049e..e1b3cb4dd 100644 --- a/tests/rest/test_events.py +++ b/tests/rest/test_events.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ Tests REST events for /events paths.""" from twisted.trial import unittest diff --git a/tests/rest/test_presence.py b/tests/rest/test_presence.py index 3a2e86e5c..7c54e067c 100644 --- a/tests/rest/test_presence.py +++ b/tests/rest/test_presence.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """Tests REST events for /presence paths.""" from twisted.trial import unittest @@ -17,7 +31,7 @@ logging.getLogger().addHandler(logging.NullHandler()) OFFLINE = PresenceState.OFFLINE -BUSY = PresenceState.BUSY +UNAVAILABLE = PresenceState.UNAVAILABLE ONLINE = PresenceState.ONLINE @@ -55,7 +69,7 @@ class PresenceStateTestCase(unittest.TestCase): def test_get_my_status(self): mocked_get = self.mock_handler.get_state mocked_get.return_value = defer.succeed( - {"state": 2, "status_msg": "Available"}) + {"state": ONLINE, "status_msg": "Available"}) (code, response) = yield self.mock_server.trigger("GET", "/presence/%s/status" % (myid), None) @@ -73,12 +87,12 @@ class PresenceStateTestCase(unittest.TestCase): (code, response) = yield self.mock_server.trigger("PUT", "/presence/%s/status" % (myid), - '{"state": 1, "status_msg": "Away"}') + '{"state": "unavailable", "status_msg": "Away"}') self.assertEquals(200, code) mocked_set.assert_called_with(target_user=self.u_apple, auth_user=self.u_apple, - state={"state": 1, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) class PresenceListTestCase(unittest.TestCase): @@ -220,7 +234,7 @@ class PresenceEventStreamTestCase(unittest.TestCase): # I'll already get my own presence state change self.assertEquals({"start": "0", "end": "1", "chunk": [ {"type": "m.presence", - "content": {"user_id": "@apple:test", "state": 2}}, + "content": {"user_id": "@apple:test", "state": ONLINE}}, ]}, response) self.mock_datastore.set_presence_state.return_value = defer.succeed( @@ -237,5 +251,5 @@ class PresenceEventStreamTestCase(unittest.TestCase): self.assertEquals(200, code) self.assertEquals({"start": "1", "end": "2", "chunk": [ {"type": "m.presence", - "content": {"user_id": "@banana:test", "state": 2}}, + "content": {"user_id": "@banana:test", "state": ONLINE}}, ]}, response) diff --git a/tests/rest/test_profile.py b/tests/rest/test_profile.py index 13342b61e..46e613777 100644 --- a/tests/rest/test_profile.py +++ b/tests/rest/test_profile.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """Tests REST events for /profile paths.""" from twisted.trial import unittest diff --git a/tests/rest/test_rooms.py b/tests/rest/test_rooms.py index 29e82fc13..86025103d 100644 --- a/tests/rest/test_rooms.py +++ b/tests/rest/test_rooms.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """Tests REST events for /rooms paths.""" # twisted imports diff --git a/tests/rest/utils.py b/tests/rest/utils.py index 7e4e570ef..a543f049c 100644 --- a/tests/rest/utils.py +++ b/tests/rest/utils.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # twisted imports from twisted.internet import defer diff --git a/tests/storage/test_base.py b/tests/storage/test_base.py index 72869ef91..556748092 100644 --- a/tests/storage/test_base.py +++ b/tests/storage/test_base.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.trial import unittest from twisted.internet import defer diff --git a/tests/test_distributor.py b/tests/test_distributor.py index 36cbf6c52..21c91f335 100644 --- a/tests/test_distributor.py +++ b/tests/test_distributor.py @@ -1,3 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import unittest from twisted.internet import defer diff --git a/tests/test_state.py b/tests/test_state.py index 8d0251b1e..a2908a2ea 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.internet import defer from twisted.trial import unittest diff --git a/tests/test_types.py b/tests/test_types.py index 0f3c9492d..522d52363 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -1,3 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import unittest from synapse.server import BaseHomeServer diff --git a/tests/util/__init__.py b/tests/util/__init__.py index 40a96afc6..2216c0f1c 100644 --- a/tests/util/__init__.py +++ b/tests/util/__init__.py @@ -1 +1,15 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/tests/util/test_lock.py b/tests/util/test_lock.py index b7b8779fd..dd83d204d 100644 --- a/tests/util/test_lock.py +++ b/tests/util/test_lock.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.internet import defer from twisted.trial import unittest diff --git a/tests/utils.py b/tests/utils.py index 13f6b31c9..578866b4f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,3 +1,18 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from synapse.http.server import HttpServer from synapse.api.errors import cs_error, CodeMessageException, StoreError from synapse.api.constants import Membership diff --git a/webclient/app-controller.js b/webclient/app-controller.js index e7601cc21..41055bdcd 100644 --- a/webclient/app-controller.js +++ b/webclient/app-controller.js @@ -1,3 +1,19 @@ +/* +Copyright 2014 matrix.org + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* * Main controller */ diff --git a/webclient/app.css b/webclient/app.css index fd548c117..15b6c9130 100644 --- a/webclient/app.css +++ b/webclient/app.css @@ -43,7 +43,7 @@ h1 { } .inputBarTable tr td { - padding: 4px; + padding: 1px 4px; } .mainInput { @@ -106,7 +106,7 @@ h1 { background-color: #38AF00; } -.away { +.unavailable { background-color: #FFCC00; } @@ -118,7 +118,7 @@ h1 { overflow separetely. */ .room .page { - height: calc(100vh - 198px); + height: calc(100vh - 220px); } /*** Message table ***/ @@ -187,6 +187,14 @@ h1 { border: 0px ! important; } +.image { + display: block; + max-width:320px; + max-height:320px; + width: auto; + height: auto; +} + .bubble { padding: 6px; padding-left: 1em; diff --git a/webclient/app.js b/webclient/app.js index 2a75560ed..2133a98cb 100644 --- a/webclient/app.js +++ b/webclient/app.js @@ -1,3 +1,19 @@ +/* +Copyright 2014 matrix.org + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + var matrixWebClient = angular.module('matrixWebClient', [ 'ngRoute', 'MatrixWebClientController', diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index f98874dc7..f054bf301 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -1,3 +1,19 @@ +/* +Copyright 2014 matrix.org + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + 'use strict'; angular.module('matrixService', []) @@ -181,6 +197,17 @@ angular.module('matrixService', []) return this.sendMessage(room_id, msg_id, content); }, + // Send an image message + sendImageMessage: function(room_id, image_url, image_alt, msg_id) { + var content = { + msgtype: "m.image", + url: image_url, + body: image_alt + }; + + return this.sendMessage(room_id, msg_id, content); + }, + // Send an emote message sendEmoteMessage: function(room_id, body, msg_id) { var content = { diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index e54751ef6..5d1c65641 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -1,3 +1,19 @@ +/* +Copyright 2014 matrix.org + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + angular.module('RoomController', []) .controller('RoomController', ['$scope', '$http', '$timeout', '$routeParams', '$location', 'matrixService', function($scope, $http, $timeout, $routeParams, $location, matrixService) { @@ -11,7 +27,8 @@ angular.module('RoomController', []) $scope.messages = []; $scope.members = {}; $scope.stopPoll = false; - + + $scope.imageURLToSend = ""; $scope.userIDToInvite = ""; var shortPoll = function() { @@ -106,17 +123,14 @@ angular.module('RoomController', []) var member = $scope.members[chunk.content.user_id]; if ("state" in chunk.content) { - var ONLINE = 2; - var AWAY = 1; - var OFFLINE = 0; - if (chunk.content.state === ONLINE) { + if (chunk.content.state === "online") { member.presenceState = "online"; } - else if (chunk.content.state === OFFLINE) { + else if (chunk.content.state === "offline") { member.presenceState = "offline"; } - else if (chunk.content.state === AWAY) { - member.presenceState = "away"; + else if (chunk.content.state === "unavailable") { + member.presenceState = "unavailable"; } } @@ -208,6 +222,16 @@ angular.module('RoomController', []) }); }; + $scope.sendImage = function(url) { + matrixService.sendImageMessage($scope.room_id, url).then( + function() { + console.log("Image sent"); + }, + function(reason) { + $scope.feedback = "Failed to send image: " + reason; + }); + }; + $scope.$on('$destroy', function(e) { console.log("onDestroyed: Stopping poll."); $scope.stopPoll = true; diff --git a/webclient/room/room.html b/webclient/room/room.html index 5e947a03e..87d3458af 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -14,7 +14,7 @@
{{ info.displayname || name }}
- + @@ -32,7 +32,8 @@
{{ msg.content.msgtype === "m.emote" ? ("* " + (members[msg.user_id].displayname || msg.user_id) + " ") : "" }} - {{ msg.content.body }} + {{ msg.content.msgtype === "m.text" ? msg.content.body : "" }} + {{ msg.content.body }}
@@ -62,6 +63,18 @@ {{ feedback }} + + + + + + + + + + + + diff --git a/webclient/rooms/rooms-controller.js b/webclient/rooms/rooms-controller.js index 33912d63f..a4499761b 100644 --- a/webclient/rooms/rooms-controller.js +++ b/webclient/rooms/rooms-controller.js @@ -1,3 +1,19 @@ +/* +Copyright 2014 matrix.org + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + 'use strict'; angular.module('RoomsController', ['matrixService'])