From 9b61076d42aa241c2f0766ab2b60c055c9e4abee Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 1 Sep 2014 17:43:14 +0200 Subject: [PATCH 01/10] BF: Check config exists (=defined in the localstorage) before using it --- webclient/app-controller.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webclient/app-controller.js b/webclient/app-controller.js index 172770f82f..97f799d623 100644 --- a/webclient/app-controller.js +++ b/webclient/app-controller.js @@ -36,8 +36,12 @@ angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'even eventStreamService.resume(); mPresence.start(); } - - $scope.user_id = matrixService.config().user_id; + + $scope.user_id; + var config = matrixService.config(); + if (config) { + $scope.user_id = matrixService.config().user_id; + } /** * Open a given page. From 5a11a8ef6934fa0a3f42e9503783e1837babc0d8 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 1 Sep 2014 16:52:26 +0100 Subject: [PATCH 02/10] Flesh out Room Events. --- docs/specification.rst | 116 +++++++++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 17 deletions(-) diff --git a/docs/specification.rst b/docs/specification.rst index 9a494a4c0f..51c34772ff 100644 --- a/docs/specification.rst +++ b/docs/specification.rst @@ -417,7 +417,7 @@ State events can be sent by ``PUT`` ing to ``/rooms//state/ These events will be overwritten if ````, ```` and ```` all match. If the state event has no ``state_key``, it can be omitted from the path. These requests **cannot use transaction IDs** like other ``PUT`` paths because they cannot be differentiated -from the ``state key``. Furthermore, ``POST`` is unsupported on state paths. Valid requests +from the ``state_key``. Furthermore, ``POST`` is unsupported on state paths. Valid requests look like:: PUT /rooms/!roomid:domain/state/m.example.event @@ -440,7 +440,7 @@ Care should be taken to avoid setting the wrong ``state key``:: { "key" : "with '11' as the state key, but was probably intended to be a txnId" } The ``state_key`` is often used to store state about individual users, by using the user ID as the -value. For example:: +``state_key`` value. For example:: PUT /rooms/!roomid:domain/state/m.favorite.animal.event/%40my_user%3Adomain.com { "animal" : "cat", "reason": "fluffy" } @@ -493,25 +493,107 @@ Room Events This specification outlines several standard event types, all of which are prefixed with ``m.`` -State messages --------------- -- m.room.name -- m.room.topic -- m.room.member -- m.room.config -- m.room.invite_join +``m.room.name`` + Summary: + Set the human-readable name for the room. + Type: + State event + JSON format: + ``{ "name" : "string" }`` + Example: + ``{ "name" : "My Room" }`` + Description: + A room has an opaque room ID which is not human-friendly to read. A room alias is + human-friendly, but not all rooms have room aliases. The room name is a human-friendly + string designed to be displayed to the end-user. The room name is not *unique*, as + multiple rooms can have the same room name set. The room name can also be set when + creating a room using ``/createRoom`` with the ``name`` key. -What are they, when are they used, what do they contain, how should they be used. -Link back to explanatory sections (e.g. invite/join/leave sections for m.room.member) +``m.room.topic`` + Summary: + Set a topic for the room. + Type: + State event + JSON format: + ``{ "topic" : "string" }`` + Example: + ``{ "topic" : "Welcome to the real world." }`` + Description: + A topic is a short message detailing what is currently being discussed in the room. + It can also be used as a way to display extra information about the room, which may + not be suitable for the room name. + +``m.room.member`` + Summary: + The current membership state of a user in the room. + Type: + State event + JSON format: + ``{ "membership" : "enum[ invite|join|leave|ban ]" }`` + Example: + ``{ "membership" : "join" }`` + Description: + The membership state of a user is automatically set when using the membership APIs: + ``/rooms//invite``, ``/rooms//join`` and ``/rooms//leave``. + See the "Rooms" section for how to use those APIs. + +``m.room.config`` + Summary: + The room config. + Type: + State event + JSON format: + TODO + Example: + TODO + Description: + TODO + +``m.room.invite_join`` + Summary: + TODO. + Type: + State event + JSON format: + TODO + Example: + TODO + Description: + TODO + +``m.room.message`` + Summary: + A message. + Type: + Non-state event + JSON format: + ``{ "msgtype": "string" }`` + Example: + ``{ "msgtype": "m.text", "body": "Testing" }`` + Description: + This event is used when sending messages in a room. Messages are not limited to be text. + The ``msgtype`` key outlines the type of message, e.g. text, audio, image, video, etc. + Whilst not required, the ``body`` key SHOULD be used with every kind of ``msgtype`` as + a fallback mechanism when a client cannot render the message. For more information on + the types of messages which can be sent, see "m.room.message msgtypes". + +``m.room.message.feedback`` + Summary: + A receipt for a message. + Type: + Non-state event + JSON format: + ``{ "type": "enum [ delivered|read ]", "target_event_id": "string" }`` + Example: + ``{ "type": "delivered", "target_event_id": "e3b2icys" }`` + Description: + Feedback events are events sent to acknowledge a message in some way. There are two + supported acknowledgements: ``delivered`` (sent when the event has been received) and + ``read`` (sent when the event has been observed by the end-user). The ``target_event_id`` + should reference the ``m.room.message`` event being acknowledged. -Non-state messages ------------------- -- m.room.message -- m.room.message.feedback (and compressed format) - voip? -What are they, when are they used, what do they contain, how should they be used - m.room.message msgtypes ----------------------- Each ``m.room.message`` MUST have a ``msgtype`` key which identifies the type of From 57f047a05a310883d534a6b01ac99916586fa584 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 1 Sep 2014 17:15:26 +0100 Subject: [PATCH 03/10] Fairly simple move of the call status widget to the header bar (and therefore into the index page rather than the rooms page). --- webclient/app-controller.js | 30 +++++++++++++++++++++++++----- webclient/app.css | 4 ++++ webclient/index.html | 13 +++++++++++++ webclient/room/room-controller.js | 28 +++------------------------- webclient/room/room.html | 11 ----------- 5 files changed, 45 insertions(+), 41 deletions(-) diff --git a/webclient/app-controller.js b/webclient/app-controller.js index 97f799d623..42c45f7c31 100644 --- a/webclient/app-controller.js +++ b/webclient/app-controller.js @@ -21,8 +21,8 @@ limitations under the License. 'use strict'; angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'eventStreamService']) -.controller('MatrixWebClientController', ['$scope', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventStreamService', - function($scope, $location, $rootScope, matrixService, mPresence, eventStreamService) { +.controller('MatrixWebClientController', ['$scope', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventStreamService', 'matrixPhoneService', + function($scope, $location, $rootScope, matrixService, mPresence, eventStreamService, matrixPhoneService) { // Check current URL to avoid to display the logout button on the login page $scope.location = $location.path(); @@ -88,7 +88,27 @@ angular.module('MatrixWebClientController', ['matrixService', 'mPresence', 'even $scope.updateHeader = function() { $scope.user_id = matrixService.config().user_id; }; - -}]); - + $rootScope.$on(matrixPhoneService.INCOMING_CALL_EVENT, function(ngEvent, call) { + console.trace("incoming call"); + call.onError = $scope.onCallError; + call.onHangup = $scope.onCallHangup; + $rootScope.currentCall = call; + }); + + $scope.answerCall = function() { + $scope.currentCall.answer(); + }; + + $scope.hangupCall = function() { + $scope.currentCall.hangup(); + $scope.currentCall = undefined; + }; + + $rootScope.onCallError = function(errStr) { + $scope.feedback = errStr; + } + + $rootScope.onCallHangup = function() { + } +}]); diff --git a/webclient/app.css b/webclient/app.css index cd1820e155..8685032d72 100755 --- a/webclient/app.css +++ b/webclient/app.css @@ -43,6 +43,10 @@ a:active { color: #000; } height: 32px; } +#callBar { + float: left; +} + #headerContent { color: #ccc; max-width: 1280px; diff --git a/webclient/index.html b/webclient/index.html index bf24e392ac..f016dbb877 100644 --- a/webclient/index.html +++ b/webclient/index.html @@ -44,6 +44,19 @@ {{ feedback }} From 99ce820cc83f23b0d1b67a0d43056ea23fb7b6f5 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 1 Sep 2014 17:51:24 +0100 Subject: [PATCH 06/10] Little bit more on syncing APIs, need to know more about responses before more work can be done on it. --- docs/specification.rst | 50 +++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/docs/specification.rst b/docs/specification.rst index 5351da9f24..f41308ce1d 100644 --- a/docs/specification.rst +++ b/docs/specification.rst @@ -471,7 +471,8 @@ Syncing rooms ------------- When a client logs in, they may have a list of rooms which they have already joined. These rooms may also have a list of events associated with them. The purpose of 'syncing' is to present the -current room and event information in a convenient, compact manner. There are two APIs provided: +current room and event information in a convenient, compact manner. The events returned are not +limited to room events; presence events will also be returned. There are two APIs provided: - ``/initialSync`` : A global sync which will present room and event information for all rooms the user has joined. @@ -482,10 +483,40 @@ current room and event information in a convenient, compact manner. There are tw - TODO: JSON response format for both types - TODO: when would you use global? when would you use scoped? -Getting grouped state events for a room ---------------------------------------- -- ``/members`` and ``/messages`` and the event types they return. Spec JSON response format. -- ``/state`` and it returns ALL THE THINGS. +Getting events for a room +------------------------- +There are several APIs provided to ``GET`` events for a room: + +``/rooms//state//`` + Description: + Get the state event identified. + Response format: + A JSON object representing the state event **content**. + Example: + ``/rooms/!room:domain.com/state/m.room.name`` returns ``{ "name": "Room name" }`` + +``/rooms//state`` + Description: + Get all state events for a room. + Response format: + ``[ { state event }, { state event }, ... ]`` + Example: + TODO + + +``/rooms//members`` + Description: + Get all ``m.room.member`` state events. + Response format: + ``{ "start": "token", "end": "token", "chunk": [ { m.room.member event }, ... ] }`` + Example: + TODO + + + + - ``/rooms//messages`` : Get all ``m.room.message`` events. + - ``/rooms//initialSync`` : Get all relevant events for a room. + Room Events =========== @@ -533,9 +564,12 @@ prefixed with ``m.`` Example: ``{ "membership" : "join" }`` Description: - The membership state of a user is automatically set when using the membership APIs: - ``/rooms//invite``, ``/rooms//join`` and ``/rooms//leave``. - See the "Rooms" section for how to use those APIs. + Adjusts the membership state for a user in a room. It is preferable to use the + membership APIs (``/rooms//invite`` etc) when performing membership actions + rather than adjusting the state directly as there are a restricted set of valid + transformations. For example, user A cannot force user B to join a room, and trying + to force this state change directly will fail. See the "Rooms" section for how to + use the membership APIs. ``m.room.config`` Summary: From 7d99cee3ef9e84ea24755ef9097342cf631cda59 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 1 Sep 2014 18:50:39 +0200 Subject: [PATCH 07/10] Added roomName, a directive to compute a room name based on its alias (not aliases for now) and its users displaynames or ids --- webclient/app-filter.js | 39 +++++++++++++++++++++++++ webclient/recents/recents-controller.js | 7 +++-- webclient/recents/recents.html | 2 +- webclient/room/room.html | 2 +- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/webclient/app-filter.js b/webclient/app-filter.js index b8f4ed25bc..124f4ebb48 100644 --- a/webclient/app-filter.js +++ b/webclient/app-filter.js @@ -79,4 +79,43 @@ angular.module('matrixWebClient') return function(text) { return $sce.trustAsHtml(text); }; +}]) + +// Compute the room name according to information we have +.filter('roomName', ['$rootScope', 'matrixService', function($rootScope, matrixService) { + return function(room_id) { + var roomName; + + // If there is an alias, use it + // TODO: only one alias is managed for now + var alias = matrixService.getRoomIdToAliasMapping(room_id); + if (alias) { + roomName = alias; + } + + if (undefined === roomName) { + // Else, build the name from its users + var room = $rootScope.events.rooms[room_id]; + if (room) { + if (room.members) { + // Limit the room renaming to 1:1 room + if (2 === Object.keys(room.members).length) { + for (var i in room.members) { + var member = room.members[i]; + if (member.user_id !== matrixService.config().user_id) { + roomName = member.content.displayname ? member.content.displayname : member.user_id; + } + } + } + } + } + } + + if (undefined === roomName) { + // By default, use the room ID + roomName = room_id; + } + + return roomName; + }; }]); diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js index c9fd022d7f..947bd29de3 100644 --- a/webclient/recents/recents-controller.js +++ b/webclient/recents/recents-controller.js @@ -33,8 +33,7 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService']) console.log("Invited to room " + event.room_id); // FIXME push membership to top level key to match /im/sync event.membership = event.content.membership; - // FIXME bodge a nicer name than the room ID for this invite. - event.room_display_name = event.user_id + "'s room"; + $scope.rooms[event.room_id] = event; } }); @@ -88,7 +87,9 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService']) }; $scope.onInit = function() { - refresh(); + eventHandlerService.waitForInitialSyncCompletion().then(function() { + refresh(); + }); }; }]); diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index 56fb38b02a..db3b0fb32f 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -6,7 +6,7 @@ ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}"> - {{ room.room_display_name }} + {{ room.room_id | roomName }} {{ (room.lastMsg.ts) | date:'MMM d HH:mm' }} diff --git a/webclient/room/room.html b/webclient/room/room.html index c4d6ccd6cc..f118461e6b 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -3,7 +3,7 @@
[matrix]
- {{ room_alias || room_id }} + {{ room_id | roomName }}
From 6d07a28a296e08467216280c24768e55756782c2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 1 Sep 2014 17:55:29 +0100 Subject: [PATCH 08/10] fix lying docs --- docs/client-server/specification.rst | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/docs/client-server/specification.rst b/docs/client-server/specification.rst index 4c9e313a6a..2f6645ceb9 100644 --- a/docs/client-server/specification.rst +++ b/docs/client-server/specification.rst @@ -1007,26 +1007,15 @@ for users from other servers entirely. Presence ======== -In the following messages, the presence state is an integer enumeration of the -following states: - 0 : OFFLINE - 1 : BUSY - 2 : ONLINE - 3 : FREE_TO_CHAT - -Aside from OFFLINE, the protocol doesn't assign any special meaning to these -states; they are provided as an approximate signal for users to give to other -users and for clients to present them in some way that may be useful. Clients -could have different behaviours for different states of the user's presence, for -example to decide how much prominence or sound to use for incoming event -notifications. +In the following messages, the presence state is a presence string as described in +the main specification document. Getting/Setting your own presence state --------------------------------------- REST Path: /presence/$user_id/status Valid methods: GET/PUT Required keys: - presence : [0|1|2|3] - The user's new presence state + presence : - The user's new presence state Optional keys: status_msg : text string provided by the user to explain their status From 74cffcf51abb2eaacc52882c4afdcdbf67b8af4d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 1 Sep 2014 17:57:37 +0100 Subject: [PATCH 09/10] Small formatting errors --- docs/specification.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/specification.rst b/docs/specification.rst index f41308ce1d..23c6b12091 100644 --- a/docs/specification.rst +++ b/docs/specification.rst @@ -514,8 +514,8 @@ There are several APIs provided to ``GET`` events for a room: - - ``/rooms//messages`` : Get all ``m.room.message`` events. - - ``/rooms//initialSync`` : Get all relevant events for a room. +- ``/rooms//messages`` : Get all ``m.room.message`` events. +- ``/rooms//initialSync`` : Get all relevant events for a room. Room Events From 0271e8e692ba2cedb2bea5a1deca81c1dc5f67eb Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 1 Sep 2014 19:09:17 +0200 Subject: [PATCH 10/10] Follow API renaming. state -> presence. mtime_ago -> last_active_ago --- webclient/app-filter.js | 2 +- webclient/room/room-controller.js | 25 ++++++++++++------------- webclient/room/room.html | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/webclient/app-filter.js b/webclient/app-filter.js index 124f4ebb48..b8d3d2a0d8 100644 --- a/webclient/app-filter.js +++ b/webclient/app-filter.js @@ -70,7 +70,7 @@ angular.module('matrixWebClient') }); filtered.sort(function (a, b) { - return ((a["mtime_age"] || 10e10) > (b["mtime_age"] || 10e10) ? 1 : -1); + return ((a["last_active_ago"] || 10e10) > (b["last_active_ago"] || 10e10) ? 1 : -1); }); return filtered; }; diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index b20a72f25b..9861b25617 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -165,11 +165,11 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) var isNewMember = !(target_user_id in $scope.members); if (isNewMember) { // FIXME: why are we copying these fields around inside chunk? - if ("state" in chunk.content) { - chunk.presenceState = chunk.content.state; // why is this renamed? + if ("presence" in chunk.content) { + chunk.presence = chunk.content.presence; } - if ("mtime_age" in chunk.content) { - chunk.mtime_age = chunk.content.mtime_age; + if ("last_active_ago" in chunk.content) { + chunk.last_active_ago = chunk.content.last_active_ago; } if ("displayname" in chunk.content) { chunk.displayname = chunk.content.displayname; @@ -188,11 +188,11 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) // selectively update membership and presence else it will nuke the picture and displayname too :/ var member = $scope.members[target_user_id]; member.membership = chunk.content.membership; - if ("state" in chunk.content) { - member.presenceState = chunk.content.state; + if ("presence" in chunk.content) { + member.presence = chunk.content.presence; } - if ("mtime_age" in chunk.content) { - member.mtime_age = chunk.content.mtime_age; + if ("last_active_ago" in chunk.content) { + member.last_active_ago = chunk.content.last_active_ago; } } }; @@ -211,13 +211,12 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) var member = $scope.members[chunk.content.user_id]; // XXX: why not just pass the chunk straight through? - if ("state" in chunk.content) { - member.presenceState = chunk.content.state; + if ("presence" in chunk.content) { + member.presence = chunk.content.presence; } - if ("mtime_age" in chunk.content) { - // FIXME: should probably keep updating mtime_age in realtime like FB does - member.mtime_age = chunk.content.mtime_age; + if ("last_active_ago" in chunk.content) { + member.last_active_ago = chunk.content.last_active_ago; } // this may also contain a new display name or avatar url, so check. diff --git a/webclient/room/room.html b/webclient/room/room.html index f118461e6b..e25c837aa0 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -26,8 +26,8 @@
{{ member.displayname || member.id.substr(0, member.id.indexOf(':')) }}
{{ member.displayname ? "" : member.id.substr(member.id.indexOf(':')) }}
- - {{ member.mtime_age + (now - member.last_updated) | duration }}
ago
+ + {{ member.last_active_ago + (now - member.last_updated) | duration }}
ago