summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--syweb/webclient/components/matrix/event-handler-service.js42
-rw-r--r--syweb/webclient/room/room-controller.js23
2 files changed, 33 insertions, 32 deletions
diff --git a/syweb/webclient/components/matrix/event-handler-service.js b/syweb/webclient/components/matrix/event-handler-service.js
index 6645d20374..e97350005e 100644
--- a/syweb/webclient/components/matrix/event-handler-service.js
+++ b/syweb/webclient/components/matrix/event-handler-service.js
@@ -110,7 +110,33 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
     
     var displayNotification = function(event) {
         if (window.Notification && event.user_id != matrixService.config().user_id) {
-            var shouldBing = containsBingWord(event);
+            var member = modelService.getMember(event.room_id, event.user_id);
+            var displayname = getUserDisplayName(event.room_id, event.user_id);
+            var message;
+            var shouldBing = false;
+            
+            if (event.type === "m.room.message") {
+                shouldBing = containsBingWord(event);
+                message = event.content.body;
+                if (event.content.msgtype === "m.emote") {
+                    message = "* " + displayname + " " + message;
+                }
+                else if (event.content.msgtype === "m.image") {
+                    message = displayname + " sent an image.";
+                }
+            }
+            else if (event.type == "m.room.member") {
+                // Notify when another user joins only
+                if (event.state_key !== matrixService.config().user_id  && "join" === event.content.membership) {
+                    member = modelService.getMember(event.room_id, event.state_key);
+                    displayname = getUserDisplayName(event.room_id, event.state_key);
+                    message = displayname + " joined";
+                    shouldBing = true;
+                }
+                else {
+                    return;
+                }
+            }
 
             // Ideally we would notify only when the window is hidden (i.e. document.hidden = true).
             //
@@ -133,17 +159,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
             
             if (shouldBing && isIdle) {
                 console.log("Displaying notification for "+JSON.stringify(event));
-                var member = modelService.getMember(event.room_id, event.user_id);
-                var displayname = getUserDisplayName(event.room_id, event.user_id);
 
-                var message = event.content.body;
-                if (event.content.msgtype === "m.emote") {
-                    message = "* " + displayname + " " + message;
-                }
-                else if (event.content.msgtype === "m.image") {
-                    message = displayname + " sent an image.";
-                }
-                
                 var roomTitle = $filter("mRoomName")(event.room_id);
                 
                 notificationService.showNotification(
@@ -240,6 +256,10 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
         // list. This has to be done after room state is updated.
         if (memberChanges) {
             room.addMessageEvent(event, !isLiveEvent);
+            
+            if (memberChanges === "membership" && isLiveEvent) {
+                displayNotification(event);
+            }
         }
         
         
diff --git a/syweb/webclient/room/room-controller.js b/syweb/webclient/room/room-controller.js
index 7094a703f0..f68a2b504d 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', 'recentsService', 'commandsService',
-                               function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, notificationService, modelService, recentsService, commandsService) {
+.controller('RoomController', ['$modal', '$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'mPresence', 'eventHandlerService', 'mFileUpload', 'matrixPhoneService', 'MatrixCall', 'modelService', 'recentsService', 'commandsService',
+                               function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, modelService, recentsService, commandsService) {
    'use strict';
     var MESSAGES_PER_PAGINATION = 30;
     var THUMBNAIL_SIZE = 320;
@@ -185,25 +185,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
             else {
                 scrollToBottom();
                 updateMemberList(event); 
-
-                // 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(
-                        userName +
-                        " (" + $filter("mRoomName")(event.room_id) + ")",
-                        userName + " 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); 
-                        }
-                    );
-                }
             }
         }
     });