0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 22:33:50 +01:00

Factor out notification logic.

This commit is contained in:
Kegan Dougal 2014-10-31 11:54:04 +00:00
parent ac2a177070
commit 20cf0b7aeb
3 changed files with 39 additions and 27 deletions

View file

@ -212,22 +212,15 @@ function(matrixService, $rootScope, $q, $timeout, mPresence, notificationService
roomTitle = event.room_id; roomTitle = event.room_id;
} }
var notification = new window.Notification( notificationService.showNotification(
displayname + displayname + " (" + roomTitle + ")",
" (" + roomTitle + ")", message,
{ member ? member.avatar_url : undefined,
"body": message, function() {
"icon": member ? member.avatar_url : undefined console.log("notification.onclick() room=" + event.room_id);
}); $rootScope.goToPage('room/' + event.room_id);
}
notification.onclick = function() { );
console.log("notification.onclick() room=" + event.room_id);
$rootScope.goToPage('room/' + (event.room_id));
};
$timeout(function() {
notification.close();
}, 5 * 1000);
} }
} }
} }

View file

@ -21,7 +21,7 @@ This service manages notifications: enabling, creating and showing them. This
also contains 'bing word' logic. also contains 'bing word' logic.
*/ */
angular.module('notificationService', []) angular.module('notificationService', [])
.factory('notificationService', function($rootScope) { .factory('notificationService', ['$timeout', function($timeout) {
var getLocalPartFromUserId = function(user_id) { var getLocalPartFromUserId = function(user_id) {
if (!user_id) { if (!user_id) {
@ -80,7 +80,25 @@ angular.module('notificationService', [])
} }
} }
return false; 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);
} }
}; };
}); }]);

View file

@ -201,16 +201,17 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
// Notify when a user joins // Notify when a user joins
if ((document.hidden || matrixService.presence.unavailable === mPresence.getState()) if ((document.hidden || matrixService.presence.unavailable === mPresence.getState())
&& event.state_key !== $scope.state.user_id && "join" === event.membership) { && event.state_key !== $scope.state.user_id && "join" === event.membership) {
var notification = new window.Notification(
notificationService.showNotification(
event.content.displayname + event.content.displayname +
" (" + (matrixService.getRoomIdToAliasMapping(event.room_id) || event.room_id) + ")", // FIXME: don't leak room_ids here " (" + (matrixService.getRoomIdToAliasMapping(event.room_id) || event.room_id) + ")",
{ event.content.displayname + " joined",
"body": event.content.displayname + " joined", event.content.avatar_url ? event.content.avatar_url : undefined,
"icon": event.content.avatar_url ? event.content.avatar_url : undefined function() {
}); console.log("notification.onclick() room=" + event.room_id);
$timeout(function() { $rootScope.goToPage('room/' + event.room_id);
notification.close(); }
}, 5 * 1000); );
} }
} }
} }