add notifications, fix too many seen requests and misc fixes

This commit is contained in:
Matteo Pagliazzi
2016-09-09 20:12:17 +02:00
parent a748e57cd7
commit 98df0f26e7
5 changed files with 46 additions and 18 deletions

View File

@@ -194,5 +194,7 @@
"canOnlyInviteMaxInvites": "You can only invite \"<%= maxInvites %>\" at a time", "canOnlyInviteMaxInvites": "You can only invite \"<%= maxInvites %>\" at a time",
"onlyCreatorOrAdminCanDeleteChat": "Not authorized to delete this message!", "onlyCreatorOrAdminCanDeleteChat": "Not authorized to delete this message!",
"onlyGroupLeaderCanEditTasks": "Not authorized to manage tasks!", "onlyGroupLeaderCanEditTasks": "Not authorized to manage tasks!",
"onlyGroupTasksCanBeAssigned": "Only group tasks can be assigned" "onlyGroupTasksCanBeAssigned": "Only group tasks can be assigned",
"newChatMessagePlainNotification": "New message in <%= groupName %> by <%= authorName %>. Click here to open the chat page!",
"newChatMessageTitle": "New message in <%= groupName %>"
} }

View File

@@ -2,9 +2,6 @@
habitrpg.controller('ChatCtrl', ['$scope', 'Groups', 'Chat', 'User', '$http', 'ApiUrl', 'Notification', 'Members', '$rootScope', 'Analytics', habitrpg.controller('ChatCtrl', ['$scope', 'Groups', 'Chat', 'User', '$http', 'ApiUrl', 'Notification', 'Members', '$rootScope', 'Analytics',
function($scope, Groups, Chat, User, $http, ApiUrl, Notification, Members, $rootScope, Analytics){ function($scope, Groups, Chat, User, $http, ApiUrl, Notification, Members, $rootScope, Analytics){
if ($scope.group) {
Chat.markChatSeen($scope.group.id);
}
$scope.message = {content:''}; $scope.message = {content:''};
$scope._sending = false; $scope._sending = false;

View File

@@ -24,6 +24,12 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
$scope.group = $rootScope.party; $scope.group = $rootScope.party;
$scope.group.loadingParty = false; $scope.group.loadingParty = false;
checkForNotifications(); checkForNotifications();
if ($state.is('options.social.party')) {
if ('Notification' in window && window.Notification.permission === 'default') {
window.Notification.requestPermission();
}
Chat.markChatSeen($scope.group._id);
}
} }
function handlePartyError (response) { function handlePartyError (response) {
@@ -52,10 +58,6 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
} }
} }
if ($scope.group && $scope.group._id) {
Chat.markChatSeen($scope.group._id);
}
$scope.create = function(group) { $scope.create = function(group) {
group.loadingParty = true; group.loadingParty = true;

View File

@@ -93,9 +93,9 @@ angular.module("habitrpg").factory("Notification",
_notify(window.env.t('streakName') + ': ' + val, 'streak', 'glyphicon glyphicon-repeat'); _notify(window.env.t('streakName') + ': ' + val, 'streak', 'glyphicon glyphicon-repeat');
} }
function text(val){ function text(val, onClick){
if (val) { if (val) {
_notify(val, 'info'); _notify(val, 'info', null, null, onClick);
} }
} }
@@ -114,7 +114,7 @@ angular.module("habitrpg").factory("Notification",
// Used to stack notifications, must be outside of _notify // Used to stack notifications, must be outside of _notify
var stack_topright = {"dir1": "down", "dir2": "left", "spacing1": 15, "spacing2": 15, "firstpos1": 60}; var stack_topright = {"dir1": "down", "dir2": "left", "spacing1": 15, "spacing2": 15, "firstpos1": 60};
function _notify(html, type, icon, canHide) { function _notify(html, type, icon, canHide, onClick) {
var notice = $.pnotify({ var notice = $.pnotify({
type: type || 'warning', //('info', 'text', 'warning', 'success', 'gp', 'xp', 'hp', 'lvl', 'death', 'mp', 'crit') type: type || 'warning', //('info', 'text', 'warning', 'success', 'gp', 'xp', 'hp', 'lvl', 'death', 'mp', 'crit')
text: html, text: html,
@@ -126,7 +126,13 @@ angular.module("habitrpg").factory("Notification",
width: "250px", width: "250px",
stack: stack_topright, stack: stack_topright,
icon: icon || false icon: icon || false
}).click(function() { notice.pnotify_remove() }); }).click(function() {
notice.pnotify_remove();
if (onClick) {
onClick();
}
});
} }
return { return {

View File

@@ -1,8 +1,8 @@
'use strict'; 'use strict';
angular.module('habitrpg') angular.module('habitrpg')
.factory('Pusher', ['$rootScope', 'STORAGE_SETTINGS_ID', 'Groups', 'Shared', '$state', 'Chat', .factory('Pusher', ['$rootScope', 'STORAGE_SETTINGS_ID', 'Groups', 'Shared', '$state', 'Chat', 'Notification',
function($rootScope, STORAGE_SETTINGS_ID, Groups, Shared, $state, Chat) { function($rootScope, STORAGE_SETTINGS_ID, Groups, Shared, $state, Chat, Notification) {
var settings = JSON.parse(localStorage.getItem(STORAGE_SETTINGS_ID)); var settings = JSON.parse(localStorage.getItem(STORAGE_SETTINGS_ID));
var IS_PUSHER_ENABLED = window.env['PUSHER:ENABLED'] === 'true'; var IS_PUSHER_ENABLED = window.env['PUSHER:ENABLED'] === 'true';
@@ -128,29 +128,50 @@ angular.module('habitrpg')
}); });
// When a new chat message is posted // When a new chat message is posted
partyChannel.bind('new-chat', function (data) { partyChannel.bind('new-chat', function (chatData) {
Groups.party().then(function () { // wait for the party to be fully loaded Groups.party().then(function () { // wait for the party to be fully loaded
$rootScope.loadingParty = false; // make sure the party is set as loaded $rootScope.loadingParty = false; // make sure the party is set as loaded
// Update the party data // Update the party data
Groups.data.party.chat.unshift(data); Groups.data.party.chat.unshift(chatData);
Groups.data.party.chat.splice(200); Groups.data.party.chat.splice(200);
// If a system message comes in, sync the party as quest status may have changed // If a system message comes in, sync the party as quest status may have changed
if (data.uuid === 'system') { if (chatData.uuid === 'system') {
Groups.party(true).then(function (syncedParty) { Groups.party(true).then(function (syncedParty) {
// Assign and not replace so that all the references get the modifications // Assign and not replace so that all the references get the modifications
_.assign($rootScope.party, syncedParty); _.assign($rootScope.party, syncedParty);
}); });
} }
if ($state.is('options.social.party')) { // if we're on the party page, mark the chat as read if ($state.is('options.social.party') && document.hasFocus()) { // if we're on the party page, mark the chat as read
Chat.markChatSeen($rootScope.party._id); Chat.markChatSeen($rootScope.party._id);
} else { // show a notification } else { // show a notification
$rootScope.User.user.newMessages[$rootScope.party._id] = { $rootScope.User.user.newMessages[$rootScope.party._id] = {
name: $rootScope.party.name, name: $rootScope.party.name,
value: true, value: true,
}; };
if ('Notification' in window && window.Notification.permission === 'granted') {
var notif = new window.Notification(env.t('newChatMessageTitle', {
groupName: $rootScope.party.name,
}), {
body: (chatData.user || chatData.uuid) + ': ' + chatData.text,
icon: '/favicon_192x192-00993687.png?v=4'
});
notif.addEventListener('click', function () {
$state.go('options.social.party');
notif.close();
});
} else {
Notification.text(env.t('newChatMessagePlainNotification', {
groupName: $rootScope.party.name,
authorName: chatData.user || chatData.uuid,
}), function() {
$state.go('options.social.party');
});
}
} }
}); });
}); });