From e025491a10fa40e5b5380c139de3b26abf00a6ca Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 17 Jun 2016 14:17:42 +0300 Subject: [PATCH] Fixed unread flag --- app/js/messages_manager.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 973e5aee..e7ea66ae 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -1155,7 +1155,8 @@ angular.module('myApp.services') }); } - function saveMessages (apiMessages, edited) { + function saveMessages (apiMessages, options) { + options = options || {}; angular.forEach(apiMessages, function (apiMessage) { if (apiMessage.pFlags === undefined) { apiMessage.pFlags = {}; @@ -1178,12 +1179,16 @@ angular.module('myApp.services') var mid = getFullMessageID(apiMessage.id, channelID); apiMessage.mid = mid; - if (channelID && !isBroadcast) { - var dialog = getDialogByPeerID(toPeerID)[0]; - var dialogKey = apiMessage.pFlags.outline + var dialog = getDialogByPeerID(toPeerID)[0]; + if (dialog) { + var dialogKey = apiMessage.pFlags.out ? 'read_outbox_max_id' : 'read_inbox_max_id'; - apiMessage.pFlags.unread = dialog ? mid > dialog[dialogKey] : true; + + apiMessage.pFlags.unread = mid > dialog[dialogKey]; + } + else if (options.isNew) { + apiMessage.pFlags.unread = true; } if (apiMessage.reply_to_msg_id) { @@ -1294,7 +1299,7 @@ angular.module('myApp.services') apiMessage.totalEntities = RichTextProcessor.mergeEntities(myEntities, apiEntities, !apiMessage.pending); } - if (!edited) { + if (!options.isEdited) { messagesStorage[mid] = apiMessage; } }); @@ -2707,7 +2712,7 @@ angular.module('myApp.services') } } - saveMessages([message]); + saveMessages([message], {isNew: true}); if (historyStorage !== undefined) { var history = historyStorage.history; @@ -2828,7 +2833,7 @@ angular.module('myApp.services') } // console.trace(dT(), 'edit message', message); - saveMessages([message], true); + saveMessages([message], {isEdited: true}); safeReplaceObject(messagesStorage[mid], message); var wasForHistory = messagesForHistory[mid];