forked from MirrorHub/synapse
implement html5 notifications. (have to be explicitly requested under Config)
This commit is contained in:
parent
48f4497fe9
commit
60245c4f90
4 changed files with 37 additions and 3 deletions
|
@ -45,6 +45,12 @@ angular.module('MatrixWebClientController', ['matrixService'])
|
||||||
$scope.config = matrixService.config();
|
$scope.config = matrixService.config();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.closeConfig = function() {
|
||||||
|
if ($scope.config) {
|
||||||
|
$scope.config = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (matrixService.config()) {
|
if (matrixService.config()) {
|
||||||
eventStreamService.resume();
|
eventStreamService.resume();
|
||||||
|
@ -69,6 +75,15 @@ angular.module('MatrixWebClientController', ['matrixService'])
|
||||||
console.log("Invalid access token -> log user out");
|
console.log("Invalid access token -> log user out");
|
||||||
$scope.logout();
|
$scope.logout();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.requestNotifications = function() {
|
||||||
|
if (window.Notification) {
|
||||||
|
console.log("Notification.permission: " + window.Notification.permission);
|
||||||
|
window.Notification.requestPermission(function(){});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -260,8 +260,8 @@ h1 {
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
top: 100px;
|
top: 100px;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
width: 400px;
|
width: 500px;
|
||||||
margin-left: -200px;
|
margin-left: -250px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
background-color: #aaa;
|
background-color: #aaa;
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
<div>Home server: {{ config.homeserver }} </div>
|
<div>Home server: {{ config.homeserver }} </div>
|
||||||
<div>User ID: {{ config.user_id }} </div>
|
<div>User ID: {{ config.user_id }} </div>
|
||||||
<div>Access token: {{ config.access_token }} </div>
|
<div>Access token: {{ config.access_token }} </div>
|
||||||
|
<div><button ng-click="requestNotifications()">Request notifications</button></div>
|
||||||
|
<div><button ng-click="closeConfig()">Close</button></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,23 @@ angular.module('RoomController', ['ngSanitize'])
|
||||||
$scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
|
$scope.$on(eventHandlerService.MSG_EVENT, function(ngEvent, event, isLive) {
|
||||||
if (isLive && event.room_id === $scope.room_id) {
|
if (isLive && event.room_id === $scope.room_id) {
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
|
|
||||||
|
if (window.Notification) {
|
||||||
|
// FIXME: we should also notify based on a timer or other heuristics
|
||||||
|
// rather than the window being minimised
|
||||||
|
if (document.hidden) {
|
||||||
|
var notification = new window.Notification(
|
||||||
|
($scope.members[event.user_id].displayname || event.user_id) +
|
||||||
|
" (" + $scope.room_alias + ")",
|
||||||
|
{
|
||||||
|
"body": event.content.body,
|
||||||
|
"icon": $scope.members[event.user_id].avatar_url,
|
||||||
|
});
|
||||||
|
$timeout(function() {
|
||||||
|
notification.close();
|
||||||
|
}, 5 * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -154,7 +171,7 @@ angular.module('RoomController', ['ngSanitize'])
|
||||||
paginate(MESSAGES_PER_PAGINATION);
|
paginate(MESSAGES_PER_PAGINATION);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var paginate = function(numItems) {
|
var paginate = function(numItems) {
|
||||||
// console.log("paginate " + numItems);
|
// console.log("paginate " + numItems);
|
||||||
if ($scope.state.paginating) {
|
if ($scope.state.paginating) {
|
||||||
|
|
Loading…
Reference in a new issue