Fixed messages updates handling
This commit is contained in:
parent
5854d0eafb
commit
bdb467bc62
@ -1048,7 +1048,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
history = $scope.peerHistories[pos];
|
history = $scope.peerHistories[pos];
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
history = {peerID: peerID, messages: []};
|
history = {peerID: peerID, messages: [], ids: []};
|
||||||
$scope.peerHistories.unshift(history);
|
$scope.peerHistories.unshift(history);
|
||||||
diff = $scope.peerHistories.length - maxLen;
|
diff = $scope.peerHistories.length - maxLen;
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
@ -1109,20 +1109,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
}
|
}
|
||||||
|
|
||||||
function messageFocusHistory () {
|
function messageFocusHistory () {
|
||||||
var i,
|
var history = historiesQueueFind();
|
||||||
found = false,
|
|
||||||
history = historiesQueueFind();
|
|
||||||
|
|
||||||
if (history) {
|
if (history &&
|
||||||
for (i = 0; i < history.messages.length; i++) {
|
history.ids.indexOf($scope.curDialog.messageID) != -1) {
|
||||||
if ($scope.curDialog.messageID == history.messages[i].id) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
|
||||||
$scope.historyUnread = {};
|
$scope.historyUnread = {};
|
||||||
$scope.$broadcast('messages_focus', $scope.curDialog.messageID);
|
$scope.$broadcast('messages_focus', $scope.curDialog.messageID);
|
||||||
$scope.$broadcast('ui_history_change_scroll');
|
$scope.$broadcast('ui_history_change_scroll');
|
||||||
@ -1155,6 +1145,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
id = historyResult.history[i];
|
id = historyResult.history[i];
|
||||||
if (id > minID) {
|
if (id > minID) {
|
||||||
peerHistory.messages.push(AppMessagesManager.wrapForHistory(id));
|
peerHistory.messages.push(AppMessagesManager.wrapForHistory(id));
|
||||||
|
peerHistory.ids.push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1203,6 +1194,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
|
|
||||||
angular.forEach(historyResult.history, function (id) {
|
angular.forEach(historyResult.history, function (id) {
|
||||||
peerHistory.messages.unshift(AppMessagesManager.wrapForHistory(id));
|
peerHistory.messages.unshift(AppMessagesManager.wrapForHistory(id));
|
||||||
|
peerHistory.ids.unshift(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
hasMore = historyResult.count === null ||
|
hasMore = historyResult.count === null ||
|
||||||
@ -1253,6 +1245,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
if (prerenderedLen && (maxID || backLimit)) {
|
if (prerenderedLen && (maxID || backLimit)) {
|
||||||
prerenderedLen = 0;
|
prerenderedLen = 0;
|
||||||
peerHistory.messages = [];
|
peerHistory.messages = [];
|
||||||
|
peerHistory.ids = [];
|
||||||
$scope.state.empty = true;
|
$scope.state.empty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1284,6 +1277,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
safeReplaceObject($scope.state, {loaded: true, empty: !fetchedLength});
|
safeReplaceObject($scope.state, {loaded: true, empty: !fetchedLength});
|
||||||
|
|
||||||
peerHistory.messages = [];
|
peerHistory.messages = [];
|
||||||
|
peerHistory.ids = [];
|
||||||
angular.forEach(historyResult.history, function (id) {
|
angular.forEach(historyResult.history, function (id) {
|
||||||
var message = AppMessagesManager.wrapForHistory(id);
|
var message = AppMessagesManager.wrapForHistory(id);
|
||||||
if ($scope.historyState.skipped) {
|
if ($scope.historyState.skipped) {
|
||||||
@ -1293,8 +1287,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
message.unreadAfter = true;
|
message.unreadAfter = true;
|
||||||
}
|
}
|
||||||
peerHistory.messages.push(message);
|
peerHistory.messages.push(message);
|
||||||
|
peerHistory.ids.push(id);
|
||||||
});
|
});
|
||||||
peerHistory.messages.reverse();
|
peerHistory.messages.reverse();
|
||||||
|
peerHistory.ids.reverse();
|
||||||
|
|
||||||
if (AppMessagesManager.regroupWrappedHistory(peerHistory.messages)) {
|
if (AppMessagesManager.regroupWrappedHistory(peerHistory.messages)) {
|
||||||
$scope.$broadcast('messages_regroup');
|
$scope.$broadcast('messages_regroup');
|
||||||
@ -1466,6 +1462,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
function toggleMedia (mediaType) {
|
function toggleMedia (mediaType) {
|
||||||
$scope.historyFilter.mediaType = mediaType || false;
|
$scope.historyFilter.mediaType = mediaType || false;
|
||||||
peerHistory.messages = [];
|
peerHistory.messages = [];
|
||||||
|
peerHistory.ids = [];
|
||||||
$scope.state.empty = true;
|
$scope.state.empty = true;
|
||||||
loadHistory();
|
loadHistory();
|
||||||
}
|
}
|
||||||
@ -1523,6 +1520,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
// console.trace();
|
// console.trace();
|
||||||
var historyMessage = AppMessagesManager.wrapForHistory(addedMessage.messageID);
|
var historyMessage = AppMessagesManager.wrapForHistory(addedMessage.messageID);
|
||||||
history.messages.push(historyMessage);
|
history.messages.push(historyMessage);
|
||||||
|
history.ids.push(addedMessage.messageID);
|
||||||
if (AppMessagesManager.regroupWrappedHistory(history.messages, -3)) {
|
if (AppMessagesManager.regroupWrappedHistory(history.messages, -3)) {
|
||||||
$scope.$broadcast('messages_regroup');
|
$scope.$broadcast('messages_regroup');
|
||||||
}
|
}
|
||||||
@ -1568,6 +1566,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var curPeer = peerID == $scope.curDialog.peerID;
|
var curPeer = peerID == $scope.curDialog.peerID;
|
||||||
|
var exlen = history.messages.length;
|
||||||
var len = msgs.length;
|
var len = msgs.length;
|
||||||
|
|
||||||
if (curPeer) {
|
if (curPeer) {
|
||||||
@ -1580,7 +1579,6 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
}
|
}
|
||||||
if (len > 10) {
|
if (len > 10) {
|
||||||
if (curPeer) {
|
if (curPeer) {
|
||||||
var exlen = history.messages.length;
|
|
||||||
if (exlen > 10) {
|
if (exlen > 10) {
|
||||||
minID = history.messages[exlen - 1].id;
|
minID = history.messages[exlen - 1].id;
|
||||||
$scope.historyState.skipped = hasLess = minID > 0;
|
$scope.historyState.skipped = hasLess = minID > 0;
|
||||||
@ -1602,11 +1600,12 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
var lastIsRead = !historyMessage || !historyMessage.unread;
|
var lastIsRead = !historyMessage || !historyMessage.unread;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
messageID = msgs[i];
|
messageID = msgs[i];
|
||||||
if (historyMessage.id == messageID) {
|
if (history.ids.indexOf(messageID) !== -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
historyMessage = AppMessagesManager.wrapForHistory(messageID);
|
historyMessage = AppMessagesManager.wrapForHistory(messageID);
|
||||||
history.messages.push(historyMessage);
|
history.messages.push(historyMessage);
|
||||||
|
history.ids.push(messageID);
|
||||||
if (!unreadAfterNew && isIDLE) {
|
if (!unreadAfterNew && isIDLE) {
|
||||||
if (historyMessage.unread &&
|
if (historyMessage.unread &&
|
||||||
!historyMessage.out &&
|
!historyMessage.out &&
|
||||||
@ -1630,7 +1629,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
$scope.historyState.typing.splice(0, $scope.historyState.typing.length);
|
$scope.historyState.typing.splice(0, $scope.historyState.typing.length);
|
||||||
}
|
}
|
||||||
$scope.$broadcast('ui_history_append_new', {
|
$scope.$broadcast('ui_history_append_new', {
|
||||||
idleScroll: unreadAfterIdle && !hasOut && unreadAfterNew
|
idleScroll: unreadAfterIdle && !hasOut && isIDLE
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isIDLE) {
|
if (isIDLE) {
|
||||||
@ -1680,6 +1679,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
var history = historiesQueueFind(dialog.peerID);
|
var history = historiesQueueFind(dialog.peerID);
|
||||||
if (history) {
|
if (history) {
|
||||||
history.messages = [];
|
history.messages = [];
|
||||||
|
history.ids = [];
|
||||||
if (dialog.peerID == $scope.curDialog.peerID) {
|
if (dialog.peerID == $scope.curDialog.peerID) {
|
||||||
$scope.state.empty = true;
|
$scope.state.empty = true;
|
||||||
}
|
}
|
||||||
|
@ -2284,52 +2284,6 @@ 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 = {};
|
||||||
}
|
}
|
||||||
@ -2352,7 +2306,31 @@ 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) {
|
||||||
|
var history = historyStorage.history;
|
||||||
|
if (history.indexOf(message.id) != -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var topMsgID = history[0];
|
||||||
|
history.unshift(message.id);
|
||||||
|
if (message.id > 0 && message.id < topMsgID) {
|
||||||
|
history.sort(function (a, b) {
|
||||||
|
return b - a;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (historyStorage.count !== null) {
|
||||||
|
historyStorage.count++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
historyStorage = historiesStorage[peerID] = {
|
||||||
|
count: null,
|
||||||
|
history: [message.id],
|
||||||
|
pending: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
saveMessages([message]);
|
saveMessages([message]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user