Browse Source

Supported new read updates

master
Igor Zhukov 10 years ago
parent
commit
7211e6ee1e
  1. 53
      app/js/services.js

53
app/js/services.js

@ -2368,13 +2368,35 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
incrementMaxSeenID(message.id); incrementMaxSeenID(message.id);
break; break;
case 'updateReadMessages': case 'updateReadHistoryInbox':
var dialogsUpdated = {}, case 'updateReadHistoryOutbox':
messageID, message, i, peerID, foundDialog, dialog, var maxID = update.max_id;
foundAffected = false; var isOut = update._ == 'updateReadHistoryOutbox';
for (i = 0; i < update.messages.length; i++) { var peerID = AppPeersManager.getPeerID(update.peer);
messageID = update.messages[i]; var foundDialog = getDialogByPeerID(peerID);
var history = (historiesStorage[peerID] || {}).history || [];
var newUnreadCount = false;
var length = history.length;
var foundAffected = false;
var messageID, message, i;
if (peerID > 0 && isOut) {
AppUsersManager.forceUserOnline(peerID);
}
for (i = 0; i < length; i++) {
messageID = history[i];
if (messageID > maxID) {
continue;
}
message = messagesStorage[messageID]; message = messagesStorage[messageID];
if (message.out != isOut) {
continue;
}
if (!message.unread) {
break;
}
// console.log('read', messageID, message.unread, message); // console.log('read', messageID, message.unread, message);
if (message && message.unread) { if (message && message.unread) {
message.unread = false; message.unread = false;
@ -2387,36 +2409,27 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
if (messagesForDialogs[messageID]) { if (messagesForDialogs[messageID]) {
messagesForDialogs[messageID].unread = false; messagesForDialogs[messageID].unread = false;
} }
peerID = getMessagePeer(message);
if (!message.out) { if (!message.out) {
foundDialog = getDialogByPeerID(peerID);
if (foundDialog) { if (foundDialog) {
dialogsUpdated[peerID] = --foundDialog[0].unread_count; newUnreadCount = --foundDialog[0].unread_count;
} }
NotificationsManager.cancel('msg' + messageID); NotificationsManager.cancel('msg' + messageID);
} }
else if (peerID > 0) {
AppUsersManager.forceUserOnline(peerID);
}
} }
} }
angular.forEach(dialogsUpdated, function(count, peerID) { if (newUnreadCount !== false) {
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: count}); $rootScope.$broadcast('dialog_unread', {peerID: peerID, count: newUnreadCount});
}); }
if (foundAffected) { if (foundAffected) {
$rootScope.$broadcast('messages_read'); $rootScope.$broadcast('messages_read');
} }
break; break;
// case 'updateReadHistoryInbox':
// case 'updateReadHistoryOutbox':
case 'updateDeleteMessages': case 'updateDeleteMessages':
var dialogsUpdated = {}, var dialogsUpdated = {},
historiesUpdated = {}, historiesUpdated = {},
messageID, message, i, peerID, foundDialog, dialog, history; messageID, message, i, peerID, foundDialog, history;
for (i = 0; i < update.messages.length; i++) { for (i = 0; i < update.messages.length; i++) {
messageID = update.messages[i]; messageID = update.messages[i];

Loading…
Cancel
Save