From ac2a17707037438015560265c1267f6665f5bbd2 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 31 Oct 2014 11:20:07 +0000 Subject: Add notification-service.js to handle binging/notifications. Shift logic to this service. --- webclient/room/room-controller.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'webclient/room/room-controller.js') diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 59274baccb..2af1e8ae29 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -15,11 +15,21 @@ limitations under the License. */ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) -.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', - function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall) { +.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', 'notificationService', + function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, notificationService) { 'use strict'; var MESSAGES_PER_PAGINATION = 30; 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 + ); + }; // Room ids. Computed and resolved in onInit $scope.room_id = undefined; -- cgit 1.4.1 From 20cf0b7aeb42c49bce199206130b5498b0fc293c Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 31 Oct 2014 11:54:04 +0000 Subject: Factor out notification logic. --- .../components/matrix/event-handler-service.js | 25 ++++++++-------------- .../components/matrix/notification-service.js | 22 +++++++++++++++++-- webclient/room/room-controller.js | 19 ++++++++-------- 3 files changed, 39 insertions(+), 27 deletions(-) (limited to 'webclient/room/room-controller.js') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index bcf805fc73..e63584510b 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -212,22 +212,15 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService roomTitle = event.room_id; } - var notification = new window.Notification( - displayname + - " (" + roomTitle + ")", - { - "body": message, - "icon": member ? member.avatar_url : undefined - }); - - notification.onclick = function() { - console.log("notification.onclick() room=" + event.room_id); - $rootScope.goToPage('room/' + (event.room_id)); - }; - - $timeout(function() { - notification.close(); - }, 5 * 1000); + notificationService.showNotification( + displayname + " (" + roomTitle + ")", + message, + member ? member.avatar_url : undefined, + function() { + console.log("notification.onclick() room=" + event.room_id); + $rootScope.goToPage('room/' + event.room_id); + } + ); } } } diff --git a/webclient/components/matrix/notification-service.js b/webclient/components/matrix/notification-service.js index 7821248846..9a911413c3 100644 --- a/webclient/components/matrix/notification-service.js +++ b/webclient/components/matrix/notification-service.js @@ -21,7 +21,7 @@ This service manages notifications: enabling, creating and showing them. This also contains 'bing word' logic. */ angular.module('notificationService', []) -.factory('notificationService', function($rootScope) { +.factory('notificationService', ['$timeout', function($timeout) { var getLocalPartFromUserId = function(user_id) { if (!user_id) { @@ -80,7 +80,25 @@ angular.module('notificationService', []) } } return false; + }, + + showNotification: function(title, body, icon, onclick) { + var notification = new window.Notification( + title, + { + "body": body, + "icon": icon + } + ); + + if (onclick) { + notification.onclick = onclick; + } + + $timeout(function() { + notification.close(); + }, 5 * 1000); } }; -}); +}]); diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 2af1e8ae29..45638acaa6 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -201,16 +201,17 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) // Notify when a user joins if ((document.hidden || matrixService.presence.unavailable === mPresence.getState()) && event.state_key !== $scope.state.user_id && "join" === event.membership) { - var notification = new window.Notification( + + notificationService.showNotification( event.content.displayname + - " (" + (matrixService.getRoomIdToAliasMapping(event.room_id) || event.room_id) + ")", // FIXME: don't leak room_ids here - { - "body": event.content.displayname + " joined", - "icon": event.content.avatar_url ? event.content.avatar_url : undefined - }); - $timeout(function() { - notification.close(); - }, 5 * 1000); + " (" + (matrixService.getRoomIdToAliasMapping(event.room_id) || event.room_id) + ")", + event.content.displayname + " joined", + event.content.avatar_url ? event.content.avatar_url : undefined, + function() { + console.log("notification.onclick() room=" + event.room_id); + $rootScope.goToPage('room/' + event.room_id); + } + ); } } } -- cgit 1.4.1 From 71ef8f0636428ec08aa4ec5394cac2cbb77fd96b Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 31 Oct 2014 11:56:36 +0000 Subject: SYWEB-102: Fix desktop notification msg when a user with no display name joins a room. --- webclient/room/room-controller.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'webclient/room/room-controller.js') diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 45638acaa6..486ead0da9 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -201,11 +201,14 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput']) // Notify when a user joins if ((document.hidden || matrixService.presence.unavailable === mPresence.getState()) && event.state_key !== $scope.state.user_id && "join" === event.membership) { - + var userName = event.content.displayname; + if (!userName) { + userName = event.state_key; + } notificationService.showNotification( - event.content.displayname + + userName + " (" + (matrixService.getRoomIdToAliasMapping(event.room_id) || event.room_id) + ")", - event.content.displayname + " joined", + userName + " joined", event.content.avatar_url ? event.content.avatar_url : undefined, function() { console.log("notification.onclick() room=" + event.room_id); -- cgit 1.4.1