summary refs log tree commit diff
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-09-16 15:31:18 +0100
committerKegan Dougal <kegan@matrix.org>2014-09-16 15:35:23 +0100
commitb36a0c71d1da1fd23a154389c692f6644a3e7ac2 (patch)
tree0fd3d454ae37fb2d220dd05b6ec9799d8b9d1dcf
parentAdded bing detection logic. Persist the display name of the user in localstor... (diff)
downloadsynapse-b36a0c71d1da1fd23a154389c692f6644a3e7ac2.tar.xz
Added utility function containsBingWord and hook up some css to it.
-rwxr-xr-xwebclient/app.css4
-rw-r--r--webclient/components/matrix/event-handler-service.js71
-rw-r--r--webclient/room/room.html2
3 files changed, 46 insertions, 31 deletions
diff --git a/webclient/app.css b/webclient/app.css
index 4a4ba7b8f4..b947d8b663 100755
--- a/webclient/app.css
+++ b/webclient/app.css
@@ -538,6 +538,10 @@ a:active  { color: #000; }
     color: #F00;
 }
 
+.messageBing {
+    color: #00F;
+}
+
 #room-fullscreen-image {
     position: absolute;
     top: 0px;
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js
index 16d5763ed2..389eee5471 100644
--- a/webclient/components/matrix/event-handler-service.js
+++ b/webclient/components/matrix/event-handler-service.js
@@ -45,6 +45,46 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
     var eventMap = {};
 
     $rootScope.presence = {};
+    
+    // TODO: This is attached to the rootScope so .html can just go containsBingWord
+    // for determining classes so it is easy to highlight bing messages. It seems a
+    // bit strange to put the impl in this service though, but I can't think of a better
+    // file to put it in.
+    $rootScope.containsBingWord = function(content) {
+        if (!content) {
+            return false;
+        }
+        var bingWords = matrixService.config().bingWords;
+        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;
+                }
+            }
+        }
+        return shouldBing;
+    };
 
     var initialSyncDeferred;
 
@@ -140,36 +180,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) {
             }
             
             if (window.Notification) {
-                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;
-                        }
-                    }
-                }
+                var shouldBing = $rootScope.containsBingWord(event.content.body);
             
                 // 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());
diff --git a/webclient/room/room.html b/webclient/room/room.html
index 9d617eadd8..86ec2e51ca 100644
--- a/webclient/room/room.html
+++ b/webclient/room/room.html
@@ -105,7 +105,7 @@
                         
                         <span ng-show='msg.content.msgtype === "m.text"' 
                               class="message"
-                              ng-class="msg.echo_msg_state"
+                              ng-class="containsBingWord(msg.content.body) ? msg.echo_msg_state + ' messageBing' : msg.echo_msg_state"
                               ng-bind-html="((msg.content.msgtype === 'm.text') ? msg.content.body : '') | linky:'_blank'"/>
 
                         <span ng-show='msg.type === "m.call.invite" && msg.user_id == state.user_id'>Outgoing Call</span>