Browse Source

Added notifications about unseen msgs on startup

Closes #655
master
Igor Zhukov 10 years ago
parent
commit
b0d1b3dce5
  1. 37
      app/js/services.js

37
app/js/services.js

@ -712,6 +712,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
midnightOffseted = new Date(), midnightOffseted = new Date(),
midnightOffset; midnightOffset;
var maxSeenID = false;
if (Config.Modes.packed) {
Storage.get('max_seen_msg').then(function (maxID) {
maxSeenID = maxID || 0;
});
}
Storage.get('server_time_offset').then(function (to) { Storage.get('server_time_offset').then(function (to) {
if (to) { if (to) {
serverTimeOffset = to; serverTimeOffset = to;
@ -791,6 +799,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
curDialogStorage.count = dialogsResult.count || dialogsResult.dialogs.length; curDialogStorage.count = dialogsResult.count || dialogsResult.dialogs.length;
if (!maxID && curDialogStorage.dialogs.length) {
incrementMaxSeenID(curDialogStorage.dialogs[0].top_message);
}
curDialogStorage.dialogs.splice(offset, curDialogStorage.dialogs.length - offset); curDialogStorage.dialogs.splice(offset, curDialogStorage.dialogs.length - offset);
angular.forEach(dialogsResult.dialogs, function (dialog) { angular.forEach(dialogsResult.dialogs, function (dialog) {
var peerID = AppPeersManager.getPeerID(dialog.peer), var peerID = AppPeersManager.getPeerID(dialog.peer),
@ -809,6 +821,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
} }
NotificationsManager.savePeerSettings(peerID, dialog.notify_settings); NotificationsManager.savePeerSettings(peerID, dialog.notify_settings);
if (
dialog.unread_count > 0 &&
maxSeenID &&
dialog.top_message > maxSeenID
) {
var message = getMessage(dialog.top_message);
if (message.unread && !message.out) {
NotificationsManager.getPeerMuted(peerID).then(function (muted) {
if (!muted) {
notifyAboutMessage(message);
}
});
}
}
}); });
return { return {
@ -1917,6 +1944,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return []; return [];
} }
function incrementMaxSeenID (maxID) {
if (maxSeenID !== false && maxID && maxID > maxSeenID) {
Storage.set({
max_seen_msg: maxID
});
}
}
function notifyAboutMessage (message) { function notifyAboutMessage (message) {
var peerID = getMessagePeer(message); var peerID = getMessagePeer(message);
var fromUser = AppUsersManager.getUser(message.from_id); var fromUser = AppUsersManager.getUser(message.from_id);
@ -2114,6 +2149,8 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
}) })
}, timeout); }, timeout);
} }
incrementMaxSeenID(message.id);
break; break;
case 'updateReadMessages': case 'updateReadMessages':

Loading…
Cancel
Save