forked from MirrorHub/synapse
Migrate random bits of desktop notification logic out of roomController and into eventHandlerService where everything else is.
This commit is contained in:
parent
58ddff0881
commit
d085807070
2 changed files with 33 additions and 32 deletions
|
@ -110,7 +110,33 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||||
|
|
||||||
var displayNotification = function(event) {
|
var displayNotification = function(event) {
|
||||||
if (window.Notification && event.user_id != matrixService.config().user_id) {
|
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).
|
// Ideally we would notify only when the window is hidden (i.e. document.hidden = true).
|
||||||
//
|
//
|
||||||
|
@ -133,16 +159,6 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||||
|
|
||||||
if (shouldBing && isIdle) {
|
if (shouldBing && isIdle) {
|
||||||
console.log("Displaying notification for "+JSON.stringify(event));
|
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);
|
var roomTitle = $filter("mRoomName")(event.room_id);
|
||||||
|
|
||||||
|
@ -240,6 +256,10 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
|
||||||
// list. This has to be done after room state is updated.
|
// list. This has to be done after room state is updated.
|
||||||
if (memberChanges) {
|
if (memberChanges) {
|
||||||
room.addMessageEvent(event, !isLiveEvent);
|
room.addMessageEvent(event, !isLiveEvent);
|
||||||
|
|
||||||
|
if (memberChanges === "membership" && isLiveEvent) {
|
||||||
|
displayNotification(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'angular-peity'])
|
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',
|
.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, notificationService, modelService, recentsService, commandsService) {
|
function($modal, $filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, mPresence, eventHandlerService, mFileUpload, matrixPhoneService, MatrixCall, modelService, recentsService, commandsService) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var MESSAGES_PER_PAGINATION = 30;
|
var MESSAGES_PER_PAGINATION = 30;
|
||||||
var THUMBNAIL_SIZE = 320;
|
var THUMBNAIL_SIZE = 320;
|
||||||
|
@ -185,25 +185,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
|
||||||
else {
|
else {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
updateMemberList(event);
|
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);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue