Improved new msgs grouping
This commit is contained in:
parent
c12bc72d8d
commit
5854d0eafb
@ -2284,6 +2284,52 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
function handleNewMessages () {
|
function handleNewMessages () {
|
||||||
$timeout.cancel(newMessagesHandlePromise);
|
$timeout.cancel(newMessagesHandlePromise);
|
||||||
newMessagesHandlePromise = false;
|
newMessagesHandlePromise = false;
|
||||||
|
|
||||||
|
angular.forEach(newMessagesToHandle, function (msgs, peerID) {
|
||||||
|
var historyStorage = historiesStorage[peerID];
|
||||||
|
var topMsgID = false;
|
||||||
|
|
||||||
|
if (historyStorage !== undefined) {
|
||||||
|
topMsgID = historiesStorage[peerID].history[0];
|
||||||
|
} else {
|
||||||
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []};
|
||||||
|
}
|
||||||
|
|
||||||
|
var i, messageID;
|
||||||
|
var needToSort = false;
|
||||||
|
var len = msgs.length;
|
||||||
|
var history = historyStorage.history;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
messageID = msgs[i];
|
||||||
|
if (history.indexOf(messageID) != -1) {
|
||||||
|
msgs.splice(i, 1);
|
||||||
|
len--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (topMsgID > 0 &&
|
||||||
|
messageID > 0 &&
|
||||||
|
messageID < topMsgID) {
|
||||||
|
needToSort = true;
|
||||||
|
}
|
||||||
|
history.unshift(messageID);
|
||||||
|
topMsgID = messageID;
|
||||||
|
}
|
||||||
|
if (!len) {
|
||||||
|
delete newMessagesToHandle[peerID];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needToSort) {
|
||||||
|
history.sort(function (a, b) {
|
||||||
|
return b - a;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (historyStorage.count !== null) {
|
||||||
|
historyStorage.count += len;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$broadcast('history_multiappend', newMessagesToHandle);
|
$rootScope.$broadcast('history_multiappend', newMessagesToHandle);
|
||||||
newMessagesToHandle = {};
|
newMessagesToHandle = {};
|
||||||
}
|
}
|
||||||
@ -2306,23 +2352,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
|
|
||||||
case 'updateNewMessage':
|
case 'updateNewMessage':
|
||||||
var message = update.message,
|
var message = update.message,
|
||||||
peerID = getMessagePeer(message),
|
peerID = getMessagePeer(message);
|
||||||
historyStorage = historiesStorage[peerID];
|
|
||||||
|
|
||||||
if (historyStorage !== undefined) {
|
|
||||||
if (historiesStorage[peerID].history.indexOf(message.id) != -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var topMsgID = historiesStorage[peerID].history[0];
|
|
||||||
historyStorage.history.unshift(message.id);
|
|
||||||
if (message.id > 0 && message.id < topMsgID) {
|
|
||||||
historyStorage.history.sort(function (a, b) {
|
|
||||||
return b - a;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
historyStorage = historiesStorage[peerID] = {count: null, history: [message.id], pending: []};
|
|
||||||
}
|
|
||||||
|
|
||||||
saveMessages([message]);
|
saveMessages([message]);
|
||||||
|
|
||||||
@ -2330,10 +2360,6 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
AppUsersManager.forceUserOnline(message.from_id);
|
AppUsersManager.forceUserOnline(message.from_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (historyStorage.count !== null) {
|
|
||||||
historyStorage.count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
var randomID = pendingByMessageID[message.id],
|
var randomID = pendingByMessageID[message.id],
|
||||||
pendingMessage;
|
pendingMessage;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user