summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-09-16 15:15:19 +0100
committerKegan Dougal <kegan@matrix.org>2014-09-16 15:35:23 +0100
commita402e0c5e6e432a175b48279c972bc9ae7e944bc (patch)
tree5611d5d4bb86b546f27485c14086a6cdd2ad5288
parentMove the notification logic out of an individual room controller and into the... (diff)
downloadsynapse-a402e0c5e6e432a175b48279c972bc9ae7e944bc.tar.xz
Added bing detection logic. Persist the display name of the user in localstorage for use when binging.
-rw-r--r--webclient/components/matrix/event-handler-service.js37
-rw-r--r--webclient/home/home-controller.js4
-rw-r--r--webclient/room/room-controller.js4
-rw-r--r--webclient/settings/settings.html6
4 files changed, 44 insertions, 7 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index 8783b9b1e0..16d5763ed2 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -140,8 +140,41 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
             }
             
             if (window.Notification) {
-                // Show notification when the window is hidden, or the user is idle
-                if (document.hidden || matrixService.presence.unavailable === mPresence.getState()) {
+                var bingWords = matrixService.config().bingWords;
+                var content = event.content.body;
+                var shouldBing = false;
+                
+                // case-insensitive name check for user_id OR display_name if they exist
+                var myUserId = matrixService.config().user_id;
+                if (myUserId) {
+                    myUserId = myUserId.toLocaleLowerCase();
+                }
+                var myDisplayName = matrixService.config().display_name;
+                if (myDisplayName) {
+                    myDisplayName = myDisplayName.toLocaleLowerCase();
+                }
+                if ( (myDisplayName && content.toLocaleLowerCase().indexOf(myDisplayName) != -1) ||
+                     (myUserId && content.toLocaleLowerCase().indexOf(myUserId) != -1) ) {
+                    shouldBing = true;
+                }
+                
+                // bing word list check
+                if (bingWords && !shouldBing) {
+                    for (var i=0; i<bingWords.length; i++) {
+                        // TODO: Should really be a word check, not a string of characters check.
+                        // E.g. bing word is "coffee", "I have coffee" = bing, "I am a coffeepot" = no bing
+                        // Currently it will bing for both.
+                        if (content.indexOf(bingWords[i]) != -1) {
+                            shouldBing = true;
+                            break;
+                        }
+                    }
+                }
+            
+                // TODO: Binging every message when idle doesn't make much sense. Can we use this more sensibly?
+                var isIdle = (document.hidden || matrixService.presence.unavailable === mPresence.getState());
+                
+                if (shouldBing) {
                     console.log("Displaying notification for "+JSON.stringify(event));
                     var notification = new window.Notification(
                         ($rootScope.events.rooms[event.room_id].members[event.user_id].displayname || event.user_id) +
diff --git a/webclient/home/home-controller.js b/webclient/home/home-controller.js
index c0c4ea11aa..8ba817ca68 100644
--- a/webclient/home/home-controller.js
+++ b/webclient/home/home-controller.js
@@ -117,6 +117,10 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
         matrixService.getDisplayName($scope.config.user_id).then(
             function(response) {
                 $scope.profile.displayName = response.data.displayname;
+                var config = matrixService.config();
+                config.display_name = response.data.displayname;
+                matrixService.setConfig(config);
+                matrixService.saveConfig();
             },
             function(error) {
                 $scope.feedback = "Can't load display name";
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 4a1dfd6aac..f82f4aed27 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -15,8 +15,8 @@ limitations under the License.
 */
 
 angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
-.controller('RoomController', ['$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'eventHandlerService', 'mFileUpload', 'mPresence', 'matrixPhoneService', 'MatrixCall',
-                               function($filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, eventHandlerService, mFileUpload, mPresence, matrixPhoneService, MatrixCall) {
+.controller('RoomController', ['$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall',
+                               function($filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall) {
    'use strict';
     var MESSAGES_PER_PAGINATION = 30;
     var THUMBNAIL_SIZE = 320;
diff --git a/webclient/settings/settings.html b/webclient/settings/settings.html
index 3b3dd3dadd..1a42ae435a 100644
--- a/webclient/settings/settings.html
+++ b/webclient/settings/settings.html
@@ -51,10 +51,10 @@
         <h3>Desktop notifications</h3>
         <div class="section" ng-switch="settings.notifications">
             <div ng-switch-when="granted">
-                Notifications are enabled.
+                Notifications are enabled. You will be alerted when a message contains your user ID or display name.
                 <div class="section">
-                    <h4>Words to alert on:</h4>
-                    <input size=40 name="bingWords" ng-model="settings.bingWords" ng-list placeholder="Enter words separated with ,"
+                    <h4>Additional words to alert on:</h4>
+                    <input size=40 name="bingWords" ng-model="settings.bingWords" ng-list placeholder="Enter case-sensitive words separated with ,"
                     ng-blur="saveBingWords()"/>
                     <ul>
                         <li ng-repeat="word in settings.bingWords">{{word}}</li>