|
|
@ -901,7 +901,7 @@ angular.module('myApp.services', []) |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function getHistory (inputPeer, maxID, limit, backLimit) { |
|
|
|
function getHistory (inputPeer, maxID, limit, backLimit, prerendered) { |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
offset = 0, |
|
|
|
offset = 0, |
|
|
@ -910,6 +910,8 @@ angular.module('myApp.services', []) |
|
|
|
unreadSkip = false, |
|
|
|
unreadSkip = false, |
|
|
|
resultPending = []; |
|
|
|
resultPending = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prerendered = prerendered ? Math.min(50, prerendered) : 0; |
|
|
|
|
|
|
|
|
|
|
|
if (historyStorage === undefined) { |
|
|
|
if (historyStorage === undefined) { |
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
|
} |
|
|
|
} |
|
|
@ -926,7 +928,7 @@ angular.module('myApp.services', []) |
|
|
|
unreadOffset = 6; |
|
|
|
unreadOffset = 6; |
|
|
|
offset = unreadCount - unreadOffset; |
|
|
|
offset = unreadCount - unreadOffset; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
limit = Math.max(10, unreadCount + 2); |
|
|
|
limit = Math.max(10, prerendered, unreadCount + 2); |
|
|
|
unreadOffset = unreadCount; |
|
|
|
unreadOffset = unreadCount; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -950,9 +952,8 @@ angular.module('myApp.services', []) |
|
|
|
offset = Math.max(0, offset - backLimit); |
|
|
|
offset = Math.max(0, offset - backLimit); |
|
|
|
limit += backLimit; |
|
|
|
limit += backLimit; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
limit = limit || (offset ? 20 : 5); |
|
|
|
limit = limit || (offset ? 20 : (prerendered || 5)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $q.when({ |
|
|
|
return $q.when({ |
|
|
|
count: historyStorage.count, |
|
|
|
count: historyStorage.count, |
|
|
|
history: resultPending.concat(historyStorage.history.slice(offset, offset + limit)), |
|
|
|
history: resultPending.concat(historyStorage.history.slice(offset, offset + limit)), |
|
|
@ -962,12 +963,11 @@ angular.module('myApp.services', []) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!backLimit && !limit) { |
|
|
|
if (!backLimit && !limit) { |
|
|
|
limit = 20; |
|
|
|
limit = prerendered || 20; |
|
|
|
} |
|
|
|
} |
|
|
|
if (offsetNotFound) { |
|
|
|
if (offsetNotFound) { |
|
|
|
offset = 0; |
|
|
|
offset = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (backLimit || unreadSkip || maxID && historyStorage.history.indexOf(maxID) == -1) { |
|
|
|
if (backLimit || unreadSkip || maxID && historyStorage.history.indexOf(maxID) == -1) { |
|
|
|
if (backLimit) { |
|
|
|
if (backLimit) { |
|
|
|
offset = -backLimit; |
|
|
|
offset = -backLimit; |
|
|
@ -1203,6 +1203,7 @@ angular.module('myApp.services', []) |
|
|
|
// console.log('done read history', peerID);
|
|
|
|
// console.log('done read history', peerID);
|
|
|
|
foundDialog[0].unread_count = 0; |
|
|
|
foundDialog[0].unread_count = 0; |
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: 0}); |
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: 0}); |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_read'); |
|
|
|
} |
|
|
|
} |
|
|
|
})['finally'](function () { |
|
|
|
})['finally'](function () { |
|
|
|
delete historyStorage.readPromise; |
|
|
|
delete historyStorage.readPromise; |
|
|
@ -1312,6 +1313,7 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
@ -1436,6 +1438,7 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
@ -1577,6 +1580,7 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
@ -1715,6 +1719,8 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.random_id; |
|
|
|
delete historyMessage.random_id; |
|
|
|
delete historyMessage.send; |
|
|
|
delete historyMessage.send; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete messagesForHistory[tempID]; |
|
|
|
delete messagesForHistory[tempID]; |
|
|
@ -1832,12 +1838,13 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
function regroupWrappedHistory (history, limit) { |
|
|
|
function regroupWrappedHistory (history, limit) { |
|
|
|
if (!history || !history.length) { |
|
|
|
if (!history || !history.length) { |
|
|
|
return; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
var start = 0, |
|
|
|
var start = 0, |
|
|
|
len = history.length, |
|
|
|
len = history.length, |
|
|
|
end = len, |
|
|
|
end = len, |
|
|
|
i, curDay, prevDay, curMessage, prevMessage; |
|
|
|
i, curDay, prevDay, curMessage, prevMessage, curGrouped, prevGrouped, |
|
|
|
|
|
|
|
wasUpdated = false; |
|
|
|
|
|
|
|
|
|
|
|
if (limit > 0) { |
|
|
|
if (limit > 0) { |
|
|
|
end = Math.min(limit, len); |
|
|
|
end = Math.min(limit, len); |
|
|
@ -1849,10 +1856,19 @@ angular.module('myApp.services', []) |
|
|
|
curMessage = history[i]; |
|
|
|
curMessage = history[i]; |
|
|
|
curDay = Math.floor((curMessage.date + midnightOffset) / 86400); |
|
|
|
curDay = Math.floor((curMessage.date + midnightOffset) / 86400); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prevGrouped = prevMessage && prevMessage.grouped; |
|
|
|
|
|
|
|
curGrouped = curMessage.grouped; |
|
|
|
|
|
|
|
|
|
|
|
if (curDay === prevDay) { |
|
|
|
if (curDay === prevDay) { |
|
|
|
delete curMessage.needDate; |
|
|
|
if (curMessage.needDate) { |
|
|
|
|
|
|
|
delete curMessage.needDate; |
|
|
|
|
|
|
|
wasUpdated = true; |
|
|
|
|
|
|
|
} |
|
|
|
} else if (!i || prevMessage) { |
|
|
|
} else if (!i || prevMessage) { |
|
|
|
curMessage.needDate = true; |
|
|
|
if (!curMessage.needDate) { |
|
|
|
|
|
|
|
curMessage.needDate = true; |
|
|
|
|
|
|
|
wasUpdated = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (prevMessage && |
|
|
|
if (prevMessage && |
|
|
@ -1883,9 +1899,17 @@ angular.module('myApp.services', []) |
|
|
|
prevMessage.grouped += ' im_grouped_fwd_end'; |
|
|
|
prevMessage.grouped += ' im_grouped_fwd_end'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!wasUpdated && prevGrouped != (prevMessage && prevMessage.grouped)) { |
|
|
|
|
|
|
|
wasUpdated = true; |
|
|
|
|
|
|
|
} |
|
|
|
prevMessage = curMessage; |
|
|
|
prevMessage = curMessage; |
|
|
|
prevDay = curDay; |
|
|
|
prevDay = curDay; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!wasUpdated && curGrouped != (prevMessage && prevMessage.grouped)) { |
|
|
|
|
|
|
|
wasUpdated = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return wasUpdated; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getDialogByPeerID (peerID) { |
|
|
|
function getDialogByPeerID (peerID) { |
|
|
@ -2085,7 +2109,8 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
case 'updateReadMessages': |
|
|
|
case 'updateReadMessages': |
|
|
|
var dialogsUpdated = {}, |
|
|
|
var dialogsUpdated = {}, |
|
|
|
messageID, message, i, peerID, foundDialog, dialog; |
|
|
|
messageID, message, i, peerID, foundDialog, dialog, |
|
|
|
|
|
|
|
foundAffected = false; |
|
|
|
for (i = 0; i < update.messages.length; i++) { |
|
|
|
for (i = 0; i < update.messages.length; i++) { |
|
|
|
messageID = update.messages[i]; |
|
|
|
messageID = update.messages[i]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
@ -2094,6 +2119,9 @@ angular.module('myApp.services', []) |
|
|
|
message.unread = false; |
|
|
|
message.unread = false; |
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
messagesForHistory[messageID].unread = false; |
|
|
|
messagesForHistory[messageID].unread = false; |
|
|
|
|
|
|
|
if (!foundAffected) { |
|
|
|
|
|
|
|
foundAffected = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
messagesForDialogs[messageID].unread = false; |
|
|
|
messagesForDialogs[messageID].unread = false; |
|
|
@ -2116,6 +2144,9 @@ angular.module('myApp.services', []) |
|
|
|
angular.forEach(dialogsUpdated, function(count, peerID) { |
|
|
|
angular.forEach(dialogsUpdated, function(count, peerID) { |
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: count}); |
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: count}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
if (foundAffected) { |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_read'); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'updateDeleteMessages': |
|
|
|
case 'updateDeleteMessages': |
|
|
@ -2533,7 +2564,6 @@ angular.module('myApp.services', []) |
|
|
|
full.width = fullWidth; |
|
|
|
full.width = fullWidth; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log(222, video.w, video.h, full.width, full.height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
video.full = full; |
|
|
|
video.full = full; |
|
|
|
video.fullThumb = angular.copy(video.thumb); |
|
|
|
video.fullThumb = angular.copy(video.thumb); |
|
|
@ -3565,7 +3595,7 @@ angular.module('myApp.services', []) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function notify (data) { |
|
|
|
function notify (data) { |
|
|
|
console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport); |
|
|
|
// console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport);
|
|
|
|
|
|
|
|
|
|
|
|
// FFOS Notification blob src bug workaround
|
|
|
|
// FFOS Notification blob src bug workaround
|
|
|
|
if (Config.Navigator.ffos) { |
|
|
|
if (Config.Navigator.ffos) { |
|
|
|