From e632fcd933b7259853ba0522e052e73fd4f4e71a Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 14:31:30 +0000 Subject: SYWEB-57: Highlight rooms where the history has changed. This highlights rooms when something has happened and you haven't viewed it yet. It highlights entries in a slightly red background colour. --- syweb/webclient/app.css | 4 ++++ syweb/webclient/recents/recents-controller.js | 28 ++++++++++++++++++++++++--- syweb/webclient/recents/recents.html | 6 +++--- syweb/webclient/room/room-controller.js | 2 +- 4 files changed, 33 insertions(+), 7 deletions(-) (limited to 'syweb') diff --git a/syweb/webclient/app.css b/syweb/webclient/app.css index 403d615bf1..7a4ff0467b 100755 --- a/syweb/webclient/app.css +++ b/syweb/webclient/app.css @@ -812,6 +812,10 @@ textarea, input { background-color: #eee; } +.recentsRoomUnread { + background-color: #fee; +} + .recentsRoomName { font-size: 16px; padding-top: 7px; diff --git a/syweb/webclient/recents/recents-controller.js b/syweb/webclient/recents/recents-controller.js index 6f0be18f1a..062d106018 100644 --- a/syweb/webclient/recents/recents-controller.js +++ b/syweb/webclient/recents/recents-controller.js @@ -25,10 +25,32 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter']) // retrieve all rooms and expose them $scope.rooms = modelService.getRooms(); + + if (!$rootScope.unreadMessages) { + $rootScope.unreadMessages = { + // room_id: + }; + } - // $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; + // $rootScope.recentsSelectedRoomID is used in the html, and is set by room-controller. + + + $scope.selectRoom = function(room) { + if ($rootScope.unreadMessages[room.room_id]) { + $rootScope.unreadMessages[room.room_id] = 0; + } + $rootScope.goToPage('room/' + (room.room_alias ? room.room_alias : room.room_id) ); + }; + + $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { + if (isLive && event.room_id !== $rootScope.recentsSelectedRoomID) { + if (!$rootScope.unreadMessages[event.room_id]) { + $rootScope.unreadMessages[event.room_id] = 0; + } + $rootScope.unreadMessages[event.room_id] += 1; + console.log("sel="+$rootScope.recentsSelectedRoomID+" unread:"+JSON.stringify($rootScope.unreadMessages, undefined, 2)); + } + }); }]); diff --git a/syweb/webclient/recents/recents.html b/syweb/webclient/recents/recents.html index 7297e23703..386edb1417 100644 --- a/syweb/webclient/recents/recents.html +++ b/syweb/webclient/recents/recents.html @@ -1,9 +1,9 @@
+ ng-click="selectRoom(room)" + class="recentsRoom" + ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID), 'recentsRoomUnread': (unreadMessages[room.room_id])}"> + ng-class="{'recentsRoomSelected': (room.room_id === recentsSelectedRoomID), 'recentsRoomBing': (unreadBings[room.room_id]), 'recentsRoomUnread': (unreadMessages[room.room_id])}">
{{ room.room_id | mRoomName }} diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js index 6928754c5d..cf6ec08932 100644 --- a/syweb/webclient/room/room-controller.js +++ b/syweb/webclient/room/room-controller.js @@ -804,7 +804,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a console.log("onInit3"); // Make recents highlight the current room - $scope.recentsSelectedRoomID = $scope.room_id; + $rootScope.recentsSelectedRoomID = $scope.room_id; // Init the history for this room history.init(); -- cgit 1.5.1 From 96cd467cfa129acaf8814e574c7cc2a9a94459c5 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 14:55:57 +0000 Subject: Add recents-service to store shared state between recents-controllers. Remove the selectedRoomId from rootScope and instead store it in recents-service. Add a broadcast to notify listeners (recents-controller) to updates of this. --- syweb/webclient/app.js | 1 + .../webclient/components/matrix/recents-service.js | 51 ++++++++++++++++++++++ syweb/webclient/index.html | 1 + syweb/webclient/recents/recents-controller.js | 15 ++++--- syweb/webclient/room/room-controller.js | 6 +-- 5 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 syweb/webclient/components/matrix/recents-service.js (limited to 'syweb') diff --git a/syweb/webclient/app.js b/syweb/webclient/app.js index 17b2bb6e8f..35190a71f4 100644 --- a/syweb/webclient/app.js +++ b/syweb/webclient/app.js @@ -31,6 +31,7 @@ var matrixWebClient = angular.module('matrixWebClient', [ 'eventStreamService', 'eventHandlerService', 'notificationService', + 'recentsService', 'modelService', 'infinite-scroll', 'ui.bootstrap', diff --git a/syweb/webclient/components/matrix/recents-service.js b/syweb/webclient/components/matrix/recents-service.js new file mode 100644 index 0000000000..64d1ab93b4 --- /dev/null +++ b/syweb/webclient/components/matrix/recents-service.js @@ -0,0 +1,51 @@ +/* +Copyright 2014 OpenMarket Ltd + +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'; + +/* +This service manages shared state between *instances* of recent lists. The +recents controller will hook into this central service to get things like: +- which rooms should be highlighted +- which rooms have been binged +- which room is currently selected +- etc. +This is preferable to polluting the $rootScope with recents specific info, and +makes the dependency on this shared state *explicit*. +*/ +angular.module('recentsService', []) +.factory('recentsService', ['$rootScope', function($rootScope) { + // notify listeners when variables in the service are updated. We need to do + // this since we do not tie them to any scope. + var BROADCAST_SELECTED_ROOM_ID = "recentsService:BROADCAST_SELECTED_ROOM_ID"; + var selectedRoomId = undefined; + + + return { + BROADCAST_SELECTED_ROOM_ID: BROADCAST_SELECTED_ROOM_ID, + + getSelectedRoomId: function() { + return selectedRoomId; + }, + + setSelectedRoomId: function(room_id) { + selectedRoomId = room_id; + $rootScope.$broadcast(BROADCAST_SELECTED_ROOM_ID, room_id); + } + + }; + +}]); diff --git a/syweb/webclient/index.html b/syweb/webclient/index.html index f6487f381d..4bca320e77 100644 --- a/syweb/webclient/index.html +++ b/syweb/webclient/index.html @@ -44,6 +44,7 @@ + diff --git a/syweb/webclient/recents/recents-controller.js b/syweb/webclient/recents/recents-controller.js index 062d106018..78aeca128d 100644 --- a/syweb/webclient/recents/recents-controller.js +++ b/syweb/webclient/recents/recents-controller.js @@ -17,8 +17,8 @@ 'use strict'; angular.module('RecentsController', ['matrixService', 'matrixFilter']) -.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', - function($rootScope, $scope, eventHandlerService, modelService) { +.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', 'recentsService', + function($rootScope, $scope, eventHandlerService, modelService, recentsService) { // Expose the service to the view $scope.eventHandlerService = eventHandlerService; @@ -31,8 +31,11 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter']) // room_id: }; } - - // $rootScope.recentsSelectedRoomID is used in the html, and is set by room-controller. + + $scope.recentsSelectedRoomID = recentsService.getSelectedRoomId(); + $scope.$on(recentsService.BROADCAST_SELECTED_ROOM_ID, function(ngEvent, room_id) { + $scope.recentsSelectedRoomID = room_id; + }); $scope.selectRoom = function(room) { @@ -43,12 +46,12 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter']) }; $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { - if (isLive && event.room_id !== $rootScope.recentsSelectedRoomID) { + if (isLive && event.room_id !== $scope.recentsSelectedRoomID) { if (!$rootScope.unreadMessages[event.room_id]) { $rootScope.unreadMessages[event.room_id] = 0; } $rootScope.unreadMessages[event.room_id] += 1; - console.log("sel="+$rootScope.recentsSelectedRoomID+" unread:"+JSON.stringify($rootScope.unreadMessages, undefined, 2)); + console.log("sel="+$scope.recentsSelectedRoomID+" unread:"+JSON.stringify($rootScope.unreadMessages, undefined, 2)); } }); diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js index cf6ec08932..ab1772e9e3 100644 --- a/syweb/webclient/room/room-controller.js +++ b/syweb/webclient/room/room-controller.js @@ -15,8 +15,8 @@ limitations under the License. */ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'angular-peity']) -.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', 'notificationService', 'modelService', - function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, notificationService, modelService) { +.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', 'notificationService', 'modelService', 'recentsService', + function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, notificationService, modelService, recentsService) { 'use strict'; var MESSAGES_PER_PAGINATION = 30; var THUMBNAIL_SIZE = 320; @@ -804,7 +804,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a console.log("onInit3"); // Make recents highlight the current room - $rootScope.recentsSelectedRoomID = $scope.room_id; + recentsService.setSelectedRoomId($scope.room_id); // Init the history for this room history.init(); -- cgit 1.5.1 From 99c445a6d69f0560c08c0264d9b844a4b03599b6 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 15:11:34 +0000 Subject: Migrate unread messages logic to recentsService. --- .../webclient/components/matrix/recents-service.js | 31 ++++++++++++++++++++-- syweb/webclient/recents/recents-controller.js | 26 +++++------------- 2 files changed, 36 insertions(+), 21 deletions(-) (limited to 'syweb') diff --git a/syweb/webclient/components/matrix/recents-service.js b/syweb/webclient/components/matrix/recents-service.js index 64d1ab93b4..237f1e3912 100644 --- a/syweb/webclient/components/matrix/recents-service.js +++ b/syweb/webclient/components/matrix/recents-service.js @@ -27,15 +27,31 @@ This is preferable to polluting the $rootScope with recents specific info, and makes the dependency on this shared state *explicit*. */ angular.module('recentsService', []) -.factory('recentsService', ['$rootScope', function($rootScope) { +.factory('recentsService', ['$rootScope', 'eventHandlerService', function($rootScope, eventHandlerService) { // notify listeners when variables in the service are updated. We need to do // this since we do not tie them to any scope. - var BROADCAST_SELECTED_ROOM_ID = "recentsService:BROADCAST_SELECTED_ROOM_ID"; + var BROADCAST_SELECTED_ROOM_ID = "recentsService:BROADCAST_SELECTED_ROOM_ID(room_id)"; var selectedRoomId = undefined; + var BROADCAST_UNREAD_MESSAGES = "recentsService:BROADCAST_UNREAD_MESSAGES(room_id, unreadCount)"; + var unreadMessages = { + // room_id: + }; + + // listen for new unread messages + $rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { + if (isLive && event.room_id !== selectedRoomId) { + if (!unreadMessages[event.room_id]) { + unreadMessages[event.room_id] = 0; + } + unreadMessages[event.room_id] += 1; + $rootScope.$broadcast(BROADCAST_UNREAD_MESSAGES, event.room_id, unreadMessages[event.room_id]); + } + }); return { BROADCAST_SELECTED_ROOM_ID: BROADCAST_SELECTED_ROOM_ID, + BROADCAST_UNREAD_MESSAGES: BROADCAST_UNREAD_MESSAGES, getSelectedRoomId: function() { return selectedRoomId; @@ -44,6 +60,17 @@ angular.module('recentsService', []) setSelectedRoomId: function(room_id) { selectedRoomId = room_id; $rootScope.$broadcast(BROADCAST_SELECTED_ROOM_ID, room_id); + }, + + getUnreadMessages: function() { + return unreadMessages; + }, + + markAsRead: function(room_id) { + if (unreadMessages[room_id]) { + unreadMessages[room_id] = 0; + } + $rootScope.$broadcast(BROADCAST_UNREAD_MESSAGES, room_id, 0); } }; diff --git a/syweb/webclient/recents/recents-controller.js b/syweb/webclient/recents/recents-controller.js index 78aeca128d..5c2cf270c3 100644 --- a/syweb/webclient/recents/recents-controller.js +++ b/syweb/webclient/recents/recents-controller.js @@ -26,34 +26,22 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter']) // retrieve all rooms and expose them $scope.rooms = modelService.getRooms(); - if (!$rootScope.unreadMessages) { - $rootScope.unreadMessages = { - // room_id: - }; - } - + // track the selected room ID: the html will use this $scope.recentsSelectedRoomID = recentsService.getSelectedRoomId(); $scope.$on(recentsService.BROADCAST_SELECTED_ROOM_ID, function(ngEvent, room_id) { $scope.recentsSelectedRoomID = room_id; }); + // track the list of unread messages: the html will use this + $scope.unreadMessages = recentsService.getUnreadMessages(); + $scope.$on(recentsService.BROADCAST_UNREAD_MESSAGES, function(ngEvent, room_id, unreadCount) { + $scope.unreadMessages = recentsService.getUnreadMessages(); + }); $scope.selectRoom = function(room) { - if ($rootScope.unreadMessages[room.room_id]) { - $rootScope.unreadMessages[room.room_id] = 0; - } + recentsService.markAsRead(room.room_id); $rootScope.goToPage('room/' + (room.room_alias ? room.room_alias : room.room_id) ); }; - - $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { - if (isLive && event.room_id !== $scope.recentsSelectedRoomID) { - if (!$rootScope.unreadMessages[event.room_id]) { - $rootScope.unreadMessages[event.room_id] = 0; - } - $rootScope.unreadMessages[event.room_id] += 1; - console.log("sel="+$scope.recentsSelectedRoomID+" unread:"+JSON.stringify($rootScope.unreadMessages, undefined, 2)); - } - }); }]); -- cgit 1.5.1 From 960b28c90a6ca8b9c61a3b376b4f9223203f4f06 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 15:31:06 +0000 Subject: SYWEB-57: Highlight rooms which have had their bingers go off in blue. Priority is the same as xchat so selected > blue > red. --- syweb/webclient/app.css | 4 ++++ .../components/matrix/event-handler-service.js | 24 ++++++++++++++++------ .../webclient/components/matrix/recents-service.js | 21 +++++++++++++++++++ syweb/webclient/recents/recents-controller.js | 6 ++++++ syweb/webclient/recents/recents.html | 2 +- 5 files changed, 50 insertions(+), 7 deletions(-) (limited to 'syweb') diff --git a/syweb/webclient/app.css b/syweb/webclient/app.css index 7a4ff0467b..648388cdb9 100755 --- a/syweb/webclient/app.css +++ b/syweb/webclient/app.css @@ -816,6 +816,10 @@ textarea, input { background-color: #fee; } +.recentsRoomBing { + background-color: #eef; +} + .recentsRoomName { font-size: 16px; padding-top: 7px; diff --git a/syweb/webclient/components/matrix/event-handler-service.js b/syweb/webclient/components/matrix/event-handler-service.js index 7b2a75507d..6645d20374 100644 --- a/syweb/webclient/components/matrix/event-handler-service.js +++ b/syweb/webclient/components/matrix/event-handler-service.js @@ -95,14 +95,22 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati modelService.createRoomIdToAliasMapping(event.room_id, event.content.aliases[0]); }; + var containsBingWord = function(event) { + if (!event.content || !event.content.body) { + return false; + } + + return notificationService.containsBingWord( + matrixService.config().user_id, + matrixService.config().display_name, + matrixService.config().bingWords, + event.content.body + ); + }; + var displayNotification = function(event) { if (window.Notification && event.user_id != matrixService.config().user_id) { - var shouldBing = notificationService.containsBingWord( - matrixService.config().user_id, - matrixService.config().display_name, - matrixService.config().bingWords, - event.content.body - ); + var shouldBing = containsBingWord(event); // Ideally we would notify only when the window is hidden (i.e. document.hidden = true). // @@ -529,6 +537,10 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati resetRoomMessages(room_id); }, + eventContainsBingWord: function(event) { + return containsBingWord(event); + }, + /** * Return the last message event of a room * @param {String} room_id the room id diff --git a/syweb/webclient/components/matrix/recents-service.js b/syweb/webclient/components/matrix/recents-service.js index 237f1e3912..3d82b8218b 100644 --- a/syweb/webclient/components/matrix/recents-service.js +++ b/syweb/webclient/components/matrix/recents-service.js @@ -38,9 +38,22 @@ angular.module('recentsService', []) // room_id: }; + var BROADCAST_UNREAD_BING_MESSAGES = "recentsService:BROADCAST_UNREAD_BING_MESSAGES(room_id, event)"; + var unreadBingMessages = { + // room_id: bingEvent + }; + // listen for new unread messages $rootScope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { if (isLive && event.room_id !== selectedRoomId) { + if (eventHandlerService.eventContainsBingWord(event)) { + if (!unreadBingMessages[event.room_id]) { + unreadBingMessages[event.room_id] = {}; + } + unreadBingMessages[event.room_id] = event; + $rootScope.$broadcast(BROADCAST_UNREAD_BING_MESSAGES, event.room_id, event); + } + if (!unreadMessages[event.room_id]) { unreadMessages[event.room_id] = 0; } @@ -66,11 +79,19 @@ angular.module('recentsService', []) return unreadMessages; }, + getUnreadBingMessages: function() { + return unreadBingMessages; + }, + markAsRead: function(room_id) { if (unreadMessages[room_id]) { unreadMessages[room_id] = 0; } + if (unreadBingMessages[room_id]) { + unreadBingMessages[room_id] = undefined; + } $rootScope.$broadcast(BROADCAST_UNREAD_MESSAGES, room_id, 0); + $rootScope.$broadcast(BROADCAST_UNREAD_BING_MESSAGES, room_id, undefined); } }; diff --git a/syweb/webclient/recents/recents-controller.js b/syweb/webclient/recents/recents-controller.js index 5c2cf270c3..41720d4cb0 100644 --- a/syweb/webclient/recents/recents-controller.js +++ b/syweb/webclient/recents/recents-controller.js @@ -38,6 +38,12 @@ angular.module('RecentsController', ['matrixService', 'matrixFilter']) $scope.unreadMessages = recentsService.getUnreadMessages(); }); + // track the list of unread BING messages: the html will use this + $scope.unreadBings = recentsService.getUnreadBingMessages(); + $scope.$on(recentsService.BROADCAST_UNREAD_BING_MESSAGES, function(ngEvent, room_id, event) { + $scope.unreadBings = recentsService.getUnreadBingMessages(); + }); + $scope.selectRoom = function(room) { recentsService.markAsRead(room.room_id); $rootScope.goToPage('room/' + (room.room_alias ? room.room_alias : room.room_id) ); diff --git a/syweb/webclient/recents/recents.html b/syweb/webclient/recents/recents.html index 386edb1417..0b3a77ca11 100644 --- a/syweb/webclient/recents/recents.html +++ b/syweb/webclient/recents/recents.html @@ -3,7 +3,7 @@
{{ room.room_id | mRoomName }} -- cgit 1.5.1 From 9412110c825915f5323d7d266c488c006d26afe3 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 12 Nov 2014 15:35:46 +0000 Subject: comment typo --- syweb/webclient/components/matrix/matrix-call.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'syweb') diff --git a/syweb/webclient/components/matrix/matrix-call.js b/syweb/webclient/components/matrix/matrix-call.js index b560cf7daa..7687cb6971 100644 --- a/syweb/webclient/components/matrix/matrix-call.js +++ b/syweb/webclient/components/matrix/matrix-call.js @@ -82,7 +82,7 @@ angular.module('MatrixCall', []) }); } - // FIXME: we should prevent any class from being placed or accepted before this has finished + // FIXME: we should prevent any calls from being placed or accepted before this has finished MatrixCall.getTurnServer(); MatrixCall.CALL_TIMEOUT = 60000; -- cgit 1.5.1 From 92ea45070ce79122d2d3ddc80c868e5ad20f6656 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 15:58:22 +0000 Subject: Add recentsService unit tests. --- syweb/webclient/test/unit/recents-service.spec.js | 114 ++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 syweb/webclient/test/unit/recents-service.spec.js (limited to 'syweb') diff --git a/syweb/webclient/test/unit/recents-service.spec.js b/syweb/webclient/test/unit/recents-service.spec.js new file mode 100644 index 0000000000..6aba140ef5 --- /dev/null +++ b/syweb/webclient/test/unit/recents-service.spec.js @@ -0,0 +1,114 @@ +describe('RecentsService', function() { + var scope; + var MSG_EVENT = "__test__"; + + var testEventContainsBingWord, testIsLive, testEvent; + + var eventHandlerService = { + MSG_EVENT: MSG_EVENT, + eventContainsBingWord: function(event) { + return testEventContainsBingWord; + } + }; + + // setup the service and mocked dependencies + beforeEach(function() { + + // set default mock values + testEventContainsBingWord = false; + testIsLive = true; + testEvent = { + content: { + body: "Hello world", + msgtype: "m.text" + }, + user_id: "@alfred:localhost", + room_id: "!fl1bb13:localhost", + event_id: "fwuegfw@localhost" + } + + // mocked dependencies + module(function ($provide) { + $provide.value('eventHandlerService', eventHandlerService); + }); + + // tested service + module('recentsService'); + }); + + beforeEach(inject(function($rootScope) { + scope = $rootScope; + })); + + it('should start with no unread messages.', inject( + function(recentsService) { + expect(recentsService.getUnreadMessages()).toEqual({}); + expect(recentsService.getUnreadBingMessages()).toEqual({}); + })); + + it('should NOT add an unread message to the room currently selected.', inject( + function(recentsService) { + recentsService.setSelectedRoomId(testEvent.room_id); + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + expect(recentsService.getUnreadMessages()).toEqual({}); + expect(recentsService.getUnreadBingMessages()).toEqual({}); + })); + + it('should add an unread message to the room NOT currently selected.', inject( + function(recentsService) { + recentsService.setSelectedRoomId("!someotherroomid:localhost"); + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + var unread = {}; + unread[testEvent.room_id] = 1; + expect(recentsService.getUnreadMessages()).toEqual(unread); + })); + + it('should add an unread message and an unread bing message if a message contains a bing word.', inject( + function(recentsService) { + recentsService.setSelectedRoomId("!someotherroomid:localhost"); + testEventContainsBingWord = true; + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + var unread = {}; + unread[testEvent.room_id] = 1; + expect(recentsService.getUnreadMessages()).toEqual(unread); + + var bing = {}; + bing[testEvent.room_id] = testEvent; + expect(recentsService.getUnreadBingMessages()).toEqual(bing); + })); + + it('should clear both unread and unread bing messages when markAsRead is called.', inject( + function(recentsService) { + recentsService.setSelectedRoomId("!someotherroomid:localhost"); + testEventContainsBingWord = true; + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + var unread = {}; + unread[testEvent.room_id] = 1; + expect(recentsService.getUnreadMessages()).toEqual(unread); + + var bing = {}; + bing[testEvent.room_id] = testEvent; + expect(recentsService.getUnreadBingMessages()).toEqual(bing); + + recentsService.markAsRead(testEvent.room_id); + + unread[testEvent.room_id] = 0; + expect(recentsService.getUnreadMessages()).toEqual(unread); + expect(recentsService.getUnreadBingMessages()).toEqual({}); + })); + + it('should not add messages as unread if they are not live.', inject( + function(recentsService) { + testIsLive = false; + + recentsService.setSelectedRoomId("!someotherroomid:localhost"); + testEventContainsBingWord = true; + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + expect(recentsService.getUnreadMessages()).toEqual({}); + expect(recentsService.getUnreadBingMessages()).toEqual({}); + })); +}); -- cgit 1.5.1 From 813125e122d395fb199fc6fd52aca5b252b960c0 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 16:01:01 +0000 Subject: Make earlier versions of jasmine happy by doing explicit object comparisons --- syweb/webclient/test/unit/recents-service.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'syweb') diff --git a/syweb/webclient/test/unit/recents-service.spec.js b/syweb/webclient/test/unit/recents-service.spec.js index 6aba140ef5..93d351d45f 100644 --- a/syweb/webclient/test/unit/recents-service.spec.js +++ b/syweb/webclient/test/unit/recents-service.spec.js @@ -96,8 +96,9 @@ describe('RecentsService', function() { recentsService.markAsRead(testEvent.room_id); unread[testEvent.room_id] = 0; + bing[testEvent.room_id] = undefined; expect(recentsService.getUnreadMessages()).toEqual(unread); - expect(recentsService.getUnreadBingMessages()).toEqual({}); + expect(recentsService.getUnreadBingMessages()).toEqual(bing); })); it('should not add messages as unread if they are not live.', inject( -- cgit 1.5.1 From 3d3f692fd8a3fe07daf2f5b8811ebc00846b60c1 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 16:22:14 +0000 Subject: Add test coverage to the webclient. Update .gitignore --- .gitignore | 3 ++- syweb/webclient/components/matrix/matrix-service.js | 2 +- syweb/webclient/test/karma.conf.js | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'syweb') diff --git a/.gitignore b/.gitignore index 3d14ac8c03..339a99e0d6 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ graph/*.png graph/*.dot **/webclient/config.js -webclient/test/environment-protractor.js +**/webclient/test/coverage/ +**/webclient/test/environment-protractor.js uploads diff --git a/syweb/webclient/components/matrix/matrix-service.js b/syweb/webclient/components/matrix/matrix-service.js index c1264887c8..cfe8691f85 100644 --- a/syweb/webclient/components/matrix/matrix-service.js +++ b/syweb/webclient/components/matrix/matrix-service.js @@ -23,7 +23,7 @@ This serves to isolate the caller from changes to the underlying url paths, as well as attach common params (e.g. access_token) to requests. */ angular.module('matrixService', []) -.factory('matrixService', ['$http', '$q', '$rootScope', function($http, $q, $rootScope) { +.factory('matrixService', ['$http', '$q', function($http, $q) { /* * Permanent storage of user information diff --git a/syweb/webclient/test/karma.conf.js b/syweb/webclient/test/karma.conf.js index 5f0642ca33..37a9eaf1c1 100644 --- a/syweb/webclient/test/karma.conf.js +++ b/syweb/webclient/test/karma.conf.js @@ -52,18 +52,32 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { + '../login/**/*.js': 'coverage', + '../room/**/*.js': 'coverage', + '../components/**/*.js': 'coverage', + '../user/**/*.js': 'coverage', + '../home/**/*.js': 'coverage', + '../recents/**/*.js': 'coverage', + '../settings/**/*.js': 'coverage', + '../app.js': 'coverage' }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress', 'junit'], + reporters: ['progress', 'junit', 'coverage'], junitReporter: { outputFile: 'test-results.xml', suite: '' }, + coverageReporter: { + type: 'cobertura', + dir: 'coverage/', + file: 'coverage.xml' + }, + // web server port port: 9876, -- cgit 1.5.1 From 59cf6f5ec90ab0beac74739934b93c2c3163147e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 16:32:17 +0000 Subject: Add more recents service unit tests. --- syweb/webclient/test/unit/recents-service.spec.js | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'syweb') diff --git a/syweb/webclient/test/unit/recents-service.spec.js b/syweb/webclient/test/unit/recents-service.spec.js index 93d351d45f..a2f9ecbaf8 100644 --- a/syweb/webclient/test/unit/recents-service.spec.js +++ b/syweb/webclient/test/unit/recents-service.spec.js @@ -112,4 +112,42 @@ describe('RecentsService', function() { expect(recentsService.getUnreadMessages()).toEqual({}); expect(recentsService.getUnreadBingMessages()).toEqual({}); })); + + it('should increment the unread message count.', inject( + function(recentsService) { + recentsService.setSelectedRoomId("!someotherroomid:localhost"); + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + var unread = {}; + unread[testEvent.room_id] = 1; + expect(recentsService.getUnreadMessages()).toEqual(unread); + + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + unread[testEvent.room_id] = 2; + expect(recentsService.getUnreadMessages()).toEqual(unread); + })); + + it('should set the bing event to the latest message to contain a bing word.', inject( + function(recentsService) { + recentsService.setSelectedRoomId("!someotherroomid:localhost"); + testEventContainsBingWord = true; + scope.$broadcast(MSG_EVENT, testEvent, testIsLive); + + var nextEvent = angular.copy(testEvent); + nextEvent.content.body = "Goodbye cruel world."; + nextEvent.event_id = "erfuerhfeaaaa@localhost"; + scope.$broadcast(MSG_EVENT, nextEvent, testIsLive); + + var bing = {}; + bing[testEvent.room_id] = nextEvent; + expect(recentsService.getUnreadBingMessages()).toEqual(bing); + })); + + it('should do nothing when marking an unknown room ID as read.', inject( + function(recentsService) { + recentsService.markAsRead("!someotherroomid:localhost"); + expect(recentsService.getUnreadMessages()).toEqual({}); + expect(recentsService.getUnreadBingMessages()).toEqual({}); + })); }); -- cgit 1.5.1 From f4a3b194da7e599863534fc8444a4f6fe9b6ee90 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 12 Nov 2014 17:06:03 +0000 Subject: Fix ability to invite users. Remove unused variables. --- syweb/webclient/room/room-controller.js | 42 +++++++++++++-------------------- syweb/webclient/room/room.html | 2 +- 2 files changed, 17 insertions(+), 27 deletions(-) (limited to 'syweb') diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js index ab1772e9e3..fa542129b7 100644 --- a/syweb/webclient/room/room-controller.js +++ b/syweb/webclient/room/room-controller.js @@ -22,14 +22,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a var THUMBNAIL_SIZE = 320; // .html needs this - $scope.containsBingWord = function(content) { - return notificationService.containsBingWord( - matrixService.config().user_id, - matrixService.config().display_name, - matrixService.config().bingWords, - content - ); - }; + $scope.containsBingWord = eventHandlerService.eventContainsBingWord; // Room ids. Computed and resolved in onInit $scope.room_id = undefined; @@ -46,12 +39,8 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a messages_visibility: "hidden", // In order to avoid flickering when scrolling down the message table at the page opening, delay the message table display }; $scope.members = {}; - $scope.autoCompleting = false; - $scope.autoCompleteIndex = 0; - $scope.autoCompleteOriginal = ""; $scope.imageURLToSend = ""; - $scope.userIDToInvite = ""; // vars and functions for updating the name @@ -162,7 +151,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a $scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) { if (isLive && event.room_id === $scope.room_id) { - scrollToBottom(); } }); @@ -841,19 +829,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a } ); }; - - $scope.inviteUser = function() { - - matrixService.invite($scope.room_id, $scope.userIDToInvite).then( - function() { - console.log("Invited."); - $scope.feedback = "Invite successfully sent to " + $scope.userIDToInvite; - $scope.userIDToInvite = ""; - }, - function(reason) { - $scope.feedback = "Failure: " + reason.data.error; - }); - }; $scope.leaveRoom = function() { @@ -1091,6 +1066,21 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a }) .controller('RoomInfoController', function($scope, $modalInstance, $filter, matrixService) { console.log("Displaying room info."); + + $scope.userIDToInvite = ""; + + $scope.inviteUser = function() { + + matrixService.invite($scope.room_id, $scope.userIDToInvite).then( + function() { + console.log("Invited."); + $scope.feedback = "Invite successfully sent to " + $scope.userIDToInvite; + $scope.userIDToInvite = ""; + }, + function(reason) { + $scope.feedback = "Failure: " + reason.data.error; + }); + }; $scope.submit = function(event) { if (event.content) { diff --git a/syweb/webclient/room/room.html b/syweb/webclient/room/room.html index 1f1cd9baef..b97b839b41 100644 --- a/syweb/webclient/room/room.html +++ b/syweb/webclient/room/room.html @@ -203,7 +203,7 @@ -- cgit 1.5.1 From 2b64c573c3ad9fcfe3d884047804c5b5f1e19967 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 12 Nov 2014 17:27:41 +0000 Subject: Oops, change videoElement / selector in audio call too. --- syweb/webclient/room/room-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'syweb') diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js index fa542129b7..6670201707 100644 --- a/syweb/webclient/room/room-controller.js +++ b/syweb/webclient/room/room-controller.js @@ -898,7 +898,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a call.onError = $rootScope.onCallError; call.onHangup = $rootScope.onCallHangup; // remote video element is used for playing audio in voice calls - call.remoteVideoElement = angular.element('#remoteVideo')[0]; + call.remoteVideoSelector = angular.element('#remoteVideo')[0]; call.placeVoiceCall(); $rootScope.currentCall = call; }; -- cgit 1.5.1 From 9950ce23342a754e9598419fc1b71cb1dc5c4de6 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 12 Nov 2014 17:34:00 +0000 Subject: Detect OpenWebRTC and add workarounds, but comment out the turn server removal for now so we have a live demo of it not working. --- syweb/webclient/components/matrix/matrix-call.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'syweb') diff --git a/syweb/webclient/components/matrix/matrix-call.js b/syweb/webclient/components/matrix/matrix-call.js index 7687cb6971..a1c3aaa103 100644 --- a/syweb/webclient/components/matrix/matrix-call.js +++ b/syweb/webclient/components/matrix/matrix-call.js @@ -92,7 +92,8 @@ angular.module('MatrixCall', []) var pc; if (window.mozRTCPeerConnection) { var iceServers = []; - if (MatrixCall.turnServer) { + // https://github.com/EricssonResearch/openwebrtc/issues/85 + if (MatrixCall.turnServer /*&& !this.isOpenWebRTC()*/) { if (MatrixCall.turnServer.uris) { for (var i = 0; i < MatrixCall.turnServer.uris.length; i++) { iceServers.push({ @@ -110,7 +111,8 @@ angular.module('MatrixCall', []) pc = new window.mozRTCPeerConnection({"iceServers":iceServers}); } else { var iceServers = []; - if (MatrixCall.turnServer) { + // https://github.com/EricssonResearch/openwebrtc/issues/85 + if (MatrixCall.turnServer /*&& !this.isOpenWebRTC()*/) { if (MatrixCall.turnServer.uris) { iceServers.push({ 'urls': MatrixCall.turnServer.uris, @@ -492,6 +494,8 @@ angular.module('MatrixCall', []) $timeout(function() { var vel = self.getRemoteVideoElement(); if (vel.play) vel.play(); + // OpenWebRTC does not support oniceconnectionstatechange yet + if (self.isOpenWebRTC()) self.state = 'connected'; }); } }; @@ -641,5 +645,15 @@ angular.module('MatrixCall', []) return null; }; + MatrixCall.prototype.isOpenWebRTC = function() { + var scripts = angular.element('script'); + for (var i = 0; i < scripts.length; i++) { + if (scripts[i].src.indexOf("owr.js") > -1) { + return true; + } + } + return false; + }; + return MatrixCall; }]); -- cgit 1.5.1