From 76217890c01a282aa541e9005e0bdfbb7cb65cd2 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 15 Sep 2014 11:14:10 +0200 Subject: BF: inviter field has moved to the room root object --- webclient/recents/recents.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webclient/recents') diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index 3d736b6694..ca7636e36a 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -22,7 +22,7 @@
- {{ room.lastMsg.inviter | mUserDisplayName: room.room_id }} invited you + {{ room.inviter | mUserDisplayName: room.room_id }} invited you
-- cgit 1.5.1 From 42f5b0a6b855d76812f3772b07d1b9fae4987c34 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 15 Sep 2014 16:31:59 +0200 Subject: Recents uses data directly from $rootscope.events --- .../components/matrix/event-handler-service.js | 43 +++++-- webclient/recents/recents-controller.js | 127 +-------------------- webclient/recents/recents-filter.js | 30 +++-- webclient/recents/recents.html | 66 ++++++----- 4 files changed, 95 insertions(+), 171 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 4604ff6192..a2c807b3f0 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -63,13 +63,14 @@ angular.module('eventHandlerService', []) var initRoom = function(room_id) { if (!(room_id in $rootScope.events.rooms)) { console.log("Creating new handler entry for " + room_id); - $rootScope.events.rooms[room_id] = {}; - $rootScope.events.rooms[room_id].messages = []; - $rootScope.events.rooms[room_id].members = {}; - - // Pagination information - $rootScope.events.rooms[room_id].pagination = { - earliest_token: "END" // how far back we've paginated + $rootScope.events.rooms[room_id] = { + room_id: room_id, + messages: [], + members: {}, + // Pagination information + pagination: { + earliest_token: "END" // how far back we've paginated + } }; } }; @@ -257,7 +258,9 @@ angular.module('eventHandlerService', []) // FIXME: /initialSync on a particular room is not yet available // So initRoom on a new room is not called. Make sure the room data is initialised here - initRoom(event.room_id); + if (event.room_id) { + initRoom(event.room_id); + } // Avoid duplicated events // Needed for rooms where initialSync has not been done. @@ -347,6 +350,30 @@ angular.module('eventHandlerService', []) resetRoomMessages: function(room_id) { resetRoomMessages(room_id); + }, + + /** + * Compute the room users number, ie the number of members who has joined the room. + * @param {String} room_id the room id + * @returns {undefined | Number} the room users number if available + */ + getUsersCountInRoom: function(room_id) { + var memberCount; + + var room = $rootScope.events.rooms[room_id]; + if (room) { + memberCount = 0; + + for (var i in room.members) { + var member = room.members[i]; + + if ("join" === member.membership) { + memberCount = memberCount + 1; + } + } + } + + return memberCount; } }; }]); diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js index a0db0538f3..2006f13a57 100644 --- a/webclient/recents/recents-controller.js +++ b/webclient/recents/recents-controller.js @@ -16,134 +16,13 @@ 'use strict'; -angular.module('RecentsController', ['matrixService', 'matrixFilter', 'eventHandlerService']) -.controller('RecentsController', ['$rootScope', '$scope', 'matrixService', 'eventHandlerService', - function($rootScope, $scope, matrixService, eventHandlerService) { - - // FIXME: Angularjs reloads the controller (and resets its $scope) each time - // the page URL changes, use $rootScope to avoid to have to reload data - $rootScope.rooms; +angular.module('RecentsController', ['matrixService', 'matrixFilter']) +.controller('RecentsController', ['$rootScope', + function($rootScope) { // $rootScope of the parent where the recents component is included can override this value // in order to highlight a specific room in the list $rootScope.recentsSelectedRoomID; - - var listenToEventStream = function() { - // Refresh the list on matrix invitation and message event - $rootScope.$on(eventHandlerService.MEMBER_EVENT, function(ngEvent, event, isLive) { - if (isLive) { - if (!$rootScope.rooms[event.room_id]) { - // The user has joined a new room, which we do not have data yet. The reason is that - // the room has appeared in the scope of the user rooms after the global initialSync - // FIXME: an initialSync on this specific room should be done - $rootScope.rooms[event.room_id] = { - room_id:event.room_id - }; - } - else if (event.state_key === matrixService.config().user_id && "invite" !== event.membership && "join" !== event.membership) { - // The user has been kicked or banned from the room, remove this room from the recents - delete $rootScope.rooms[event.room_id]; - } - - if ($rootScope.rooms[event.room_id]) { - $rootScope.rooms[event.room_id].lastMsg = event; - } - - // Update room users count - $rootScope.rooms[event.room_id].numUsersInRoom = getUsersCountInRoom(event.room_id); - } - }); - $rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { - if (isLive) { - $rootScope.rooms[event.room_id].lastMsg = event; - } - }); - $rootScope.$on(eventHandlerService.CALL_EVENT, function(ngEvent, event, isLive) { - if (isLive) { - $rootScope.rooms[event.room_id].lastMsg = event; - } - }); - $rootScope.$on(eventHandlerService.ROOM_CREATE_EVENT, function(ngEvent, event, isLive) { - if (isLive) { - $rootScope.rooms[event.room_id] = event; - } - }); - $rootScope.$on(eventHandlerService.NAME_EVENT, function(ngEvent, event, isLive) { - if (isLive) { - $rootScope.rooms[event.room_id].lastMsg = event; - } - }); - $rootScope.$on(eventHandlerService.TOPIC_EVENT, function(ngEvent, event, isLive) { - if (isLive) { - $rootScope.rooms[event.room_id].lastMsg = event; - } - }); - }; - - /** - * Compute the room users number, ie the number of members who has joined the room. - * @param {String} room_id the room id - * @returns {undefined | Number} the room users number if available - */ - var getUsersCountInRoom = function(room_id) { - var memberCount; - - var room = $rootScope.events.rooms[room_id]; - if (room) { - memberCount = 0; - - for (var i in room.members) { - var member = room.members[i]; - - if ("join" === member.membership) { - memberCount = memberCount + 1; - } - } - } - - return memberCount; - }; - $scope.onInit = function() { - // Init recents list only once - if ($rootScope.rooms) { - return; - } - - $rootScope.rooms = {}; - - // Use initialSync data to init the recents list - eventHandlerService.waitForInitialSyncCompletion().then( - function(initialSyncData) { - - var rooms = initialSyncData.data.rooms; - for (var i=0; i +
- + ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}"> @@ -25,67 +29,67 @@ {{ room.inviter | mUserDisplayName: room.room_id }} invited you -
+
- - {{ room.lastMsg.state_key | mUserDisplayName: room.room_id}} joined + + {{ lastMsg.state_key | mUserDisplayName: room.room_id}} joined - - - {{room.lastMsg.state_key | mUserDisplayName: room.room_id }} left + + + {{lastMsg.state_key | mUserDisplayName: room.room_id }} left - - {{ room.lastMsg.user_id | mUserDisplayName: room.room_id }} - {{ {"join": "kicked", "ban": "unbanned"}[room.lastMsg.content.prev] }} - {{ room.lastMsg.state_key | mUserDisplayName: room.room_id }} + + {{ lastMsg.user_id | mUserDisplayName: room.room_id }} + {{ {"join": "kicked", "ban": "unbanned"}[lastMsg.content.prev] }} + {{ lastMsg.state_key | mUserDisplayName: room.room_id }} - - : {{ room.lastMsg.content.reason }} + + : {{ lastMsg.content.reason }} - - {{ room.lastMsg.user_id | mUserDisplayName: room.room_id }} - {{ {"invite": "invited", "ban": "banned"}[room.lastMsg.content.membership] }} - {{ room.lastMsg.state_key | mUserDisplayName: room.room_id }} - - : {{ room.lastMsg.content.reason }} + + {{ lastMsg.user_id | mUserDisplayName: room.room_id }} + {{ {"invite": "invited", "ban": "banned"}[lastMsg.content.membership] }} + {{ lastMsg.state_key | mUserDisplayName: room.room_id }} + + : {{ lastMsg.content.reason }}
-
+
- {{ room.lastMsg.user_id | mUserDisplayName: room.room_id }} : - + {{ lastMsg.user_id | mUserDisplayName: room.room_id }} : +
- {{ room.lastMsg.user_id | mUserDisplayName: room.room_id }} sent an image + {{ lastMsg.user_id | mUserDisplayName: room.room_id }} sent an image
- +
- {{ room.lastMsg.content }} + {{ lastMsg.content }}
- {{ room.lastMsg.user_id | mUserDisplayName: room.room_id }} changed the topic to: {{ room.lastMsg.content.topic }} + {{ lastMsg.user_id | mUserDisplayName: room.room_id }} changed the topic to: {{ lastMsg.content.topic }}
- {{ room.lastMsg.user_id | mUserDisplayName: room.room_id }} changed the room name to: {{ room.lastMsg.content.name }} + {{ lastMsg.user_id | mUserDisplayName: room.room_id }} changed the room name to: {{ lastMsg.content.name }}
-
+
Call
-- cgit 1.5.1 From 8aa4b7bf7fdc31b3a146fe8fdc07922a4bfb1f78 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 15 Sep 2014 17:31:07 +0200 Subject: Recents must not show temporary fake messages --- .../components/matrix/event-handler-service.js | 24 ++++++++++++++++++++++ webclient/recents/recents-controller.js | 7 +++++-- webclient/recents/recents-filter.js | 9 ++------ webclient/recents/recents.html | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index a2c807b3f0..6fd77c4f29 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -352,6 +352,30 @@ angular.module('eventHandlerService', []) resetRoomMessages(room_id); }, + /** + * Return the last message event of a room + * @param {String} room_id the room id + * @param {Boolean} filterFake true to not take into account fake messages + * @returns {undefined | Event} the last message event if available + */ + getLastMessage: function(room_id, filterEcho) { + var lastMessage; + + var room = $rootScope.events.rooms[room_id]; + if (room) { + for (var i = room.messages.length - 1; i >= 0; i--) { + var message = room.messages[i]; + + if (!filterEcho || undefined === message.echo_msg_state) { + lastMessage = message; + break; + } + } + } + + return lastMessage; + }, + /** * Compute the room users number, ie the number of members who has joined the room. * @param {String} room_id the room id diff --git a/webclient/recents/recents-controller.js b/webclient/recents/recents-controller.js index 2006f13a57..ee8a41c366 100644 --- a/webclient/recents/recents-controller.js +++ b/webclient/recents/recents-controller.js @@ -17,8 +17,11 @@ 'use strict'; angular.module('RecentsController', ['matrixService', 'matrixFilter']) -.controller('RecentsController', ['$rootScope', - function($rootScope) { +.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', + function($rootScope, $scope, eventHandlerService) { + + // Expose the service to the view + $scope.eventHandlerService = eventHandlerService; // $rootScope of the parent where the recents component is included can override this value // in order to highlight a specific room in the list diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index e8a706a5d5..67fe49d4b6 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -35,14 +35,9 @@ angular.module('RecentsController') // And time sort them // The room with the lastest message at first filtered.sort(function (roomA, roomB) { - var lastMsgRoomA, lastMsgRoomB; - if (roomA.messages && 0 < roomA.messages.length) { - lastMsgRoomA = roomA.messages[roomA.messages.length - 1]; - } - if (roomB.messages && 0 < roomB.messages.length) { - lastMsgRoomB = roomB.messages[roomB.messages.length - 1]; - } + var lastMsgRoomA = eventHandlerService.getLastMessage(roomA.room_id, true); + var lastMsgRoomB = eventHandlerService.getLastMessage(roomB.room_id, true); // Invite message does not have a body message nor ts // Puth them at the top of the list diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index eb9e269a4b..789ffc9d20 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -16,7 +16,7 @@
-- cgit 1.5.1 From b0483cd47d72ea73760c8301f5729d840ceb7683 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Mon, 15 Sep 2014 18:22:38 +0200 Subject: Filter room where the user has been banned --- webclient/components/matrix/event-handler-service.js | 16 ++++++++++++++++ webclient/recents/recents-filter.js | 18 +++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 6fd77c4f29..4b0566fe33 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -398,6 +398,22 @@ angular.module('eventHandlerService', []) } return memberCount; + }, + + /** + * Get the member object of a room member + * @param {String} room_id the room id + * @param {String} user_id the id of the user + * @returns {undefined | Object} the member object of this user in this room if he is part of the room + */ + getMember: function(room_id, user_id) { + var member; + + var room = $rootScope.events.rooms[room_id]; + if (room) { + member = room.members[user_id]; + } + return member; } }; }]); diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index 67fe49d4b6..2fd4dbe98b 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -17,19 +17,27 @@ 'use strict'; angular.module('RecentsController') -.filter('orderRecents', ["eventHandlerService", function(eventHandlerService) { +.filter('orderRecents', ["matrixService", "eventHandlerService", function(matrixService, eventHandlerService) { return function(rooms) { + var user_id = matrixService.config().user_id; + // Transform the dict into an array // The key, room_id, is already in value objects var filtered = []; angular.forEach(rooms, function(room, room_id) { - // Count users here - // TODO: Compute it directly in eventHandlerService - room.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id); + // Show the room only if the user has joined it or has been invited + // (ie, do not show it if he has been banned) + var member = eventHandlerService.getMember(room_id, user_id); + if (member && ("invite" === member.membership || "join" === member.membership)) { + + // Count users here + // TODO: Compute it directly in eventHandlerService + room.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id); - filtered.push(room); + filtered.push(room); + } }); // And time sort them -- cgit 1.5.1 From 06dfbdf7c8eb7e810f9ad56621ce709ee66b210a Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Tue, 16 Sep 2014 17:07:47 +0200 Subject: WEB-27: We don't need to show the user-count in Recents in the room sidepanel - takes up too much room --- webclient/app.css | 7 ++++++- webclient/recents/recents.html | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/app.css b/webclient/app.css index b947d8b663..704cd83947 100755 --- a/webclient/app.css +++ b/webclient/app.css @@ -603,7 +603,7 @@ a:active { color: #000; } width: auto; } -.recentsRoomSummaryTS { +.recentsRoomSummaryUsersCount, .recentsRoomSummaryTS { color: #888; font-size: 12px; width: 7em; @@ -616,6 +616,11 @@ a:active { color: #000; } padding-bottom: 5px; } +/* Do not show users count in the recents fragment displayed on the room page */ +#roomPage .recentsRoomSummaryUsersCount { + width: 0em; +} + /*** Recents in the room page ***/ #roomRecentsTableWrapper { diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index 789ffc9d20..e783d3a6b4 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -8,7 +8,7 @@ - - -
{{ room.room_id | mRoomName }} @@ -14,7 +14,11 @@ - {{ (room.lastMsg.ts) | date:'MMM d HH:mm' }} + + {{lastMsg = room.messages[room.messages.length - 1];""}} + + {{ (lastMsg.ts) | date:'MMM d HH:mm' }}
- {{lastMsg = room.messages[room.messages.length - 1];""}} + {{ lastMsg = eventHandlerService.getLastMessage(room.room_id, true);"" }} {{ (lastMsg.ts) | date:'MMM d HH:mm' }} {{ room.room_id | mRoomName }} + {{ room.numUsersInRoom || '1' }} {{ room.numUsersInRoom == 1 ? 'user' : 'users' }} -- cgit 1.5.1 From 16f55d42752ad8feb473963457834c4fa752245a Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 17 Sep 2014 16:29:21 +0100 Subject: webclient SYWEB-3 : Public rooms are bold. Can't think of a nicer way which doesn't clutter the recents list. --- webclient/app.css | 4 ++++ webclient/components/matrix/event-handler-service.js | 11 +++++++++++ webclient/components/matrix/event-stream-service.js | 2 ++ webclient/recents/recents.html | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'webclient/recents') diff --git a/webclient/app.css b/webclient/app.css index 704cd83947..736aea660c 100755 --- a/webclient/app.css +++ b/webclient/app.css @@ -603,6 +603,10 @@ a:active { color: #000; } width: auto; } +.recentsPublicRoom { + font-weight: bold; +} + .recentsRoomSummaryUsersCount, .recentsRoomSummaryTS { color: #888; font-size: 12px; diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 8eb8a6b180..0be294d745 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -511,6 +511,17 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) { member = room.members[user_id]; } return member; + }, + + setRoomVisibility: function(room_id, visible) { + if (!visible) { + return; + } + + var room = $rootScope.events.rooms[room_id]; + if (room) { + room.visibility = visible; + } } }; }]); diff --git a/webclient/components/matrix/event-stream-service.js b/webclient/components/matrix/event-stream-service.js index 6f92332246..5af1ab2911 100644 --- a/webclient/components/matrix/event-stream-service.js +++ b/webclient/components/matrix/event-stream-service.js @@ -120,6 +120,8 @@ angular.module('eventStreamService', []) if ("state" in room) { eventHandlerService.handleEvents(room.state, false, true); } + + eventHandlerService.setRoomVisibility(room.room_id, room.visibility); } var presence = response.data.presence; diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index e783d3a6b4..7fec8f03e5 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -5,7 +5,7 @@ class ="recentsRoom" ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}">
+ {{ room.room_id | mRoomName }} -- cgit 1.5.1 From a6f5c88b47d36d811628449afad5355489386e92 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 18 Sep 2014 10:05:34 +0100 Subject: Still add the room to the filtered list even if you can't work out the number of users in the room. --- webclient/recents/recents-filter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'webclient/recents') diff --git a/webclient/recents/recents-filter.js b/webclient/recents/recents-filter.js index 2fd4dbe98b..d948205e19 100644 --- a/webclient/recents/recents-filter.js +++ b/webclient/recents/recents-filter.js @@ -35,9 +35,8 @@ angular.module('RecentsController') // Count users here // TODO: Compute it directly in eventHandlerService room.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id); - - filtered.push(room); } + filtered.push(room); }); // And time sort them @@ -61,4 +60,4 @@ angular.module('RecentsController') }); return filtered; }; -}]); \ No newline at end of file +}]); -- cgit 1.5.1 From a64ff63a41a5d49bccec24071587295596016b05 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 18 Sep 2014 11:35:59 +0100 Subject: SYWEB-3 : Boldify if the join_rule is public, rather than visibility so it plays nicer with federation. --- webclient/recents/recents.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webclient/recents') diff --git a/webclient/recents/recents.html b/webclient/recents/recents.html index 7fec8f03e5..edfc1677eb 100644 --- a/webclient/recents/recents.html +++ b/webclient/recents/recents.html @@ -5,7 +5,7 @@ class ="recentsRoom" ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID)}">
+ {{ room.room_id | mRoomName }} -- cgit 1.5.1