|
|
|
@ -163,13 +163,21 @@ angular.module('myApp.services', [])
@@ -163,13 +163,21 @@ angular.module('myApp.services', [])
|
|
|
|
|
var timestampNow = tsNow(true) + serverTimeOffset; |
|
|
|
|
angular.forEach(users, function (user) { |
|
|
|
|
if (user.status && user.status._ == 'userStatusOnline' && |
|
|
|
|
user.status.expires > timestampNow) { |
|
|
|
|
user.status.expires < timestampNow) { |
|
|
|
|
user.status = {_: 'userStatusOffline', was_online: user.status.expires}; |
|
|
|
|
$rootScope.$broadcast('user_update', user.id); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function forceUserOnline (id) { |
|
|
|
|
var user = getUser(id); |
|
|
|
|
if (user && (!user.status || user.status._ != 'userStatusOnline')) { |
|
|
|
|
user.status = {_: 'userStatusOnline', expires: tsNow(true) + serverTimeOffset + 60}; |
|
|
|
|
$rootScope.$broadcast('user_update', id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function wrapForFull (id) { |
|
|
|
|
var user = getUser(id); |
|
|
|
|
|
|
|
|
@ -308,6 +316,7 @@ angular.module('myApp.services', [])
@@ -308,6 +316,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
case 'updateUserPhoto': |
|
|
|
|
var userID = update.user_id; |
|
|
|
|
if (users[userID]) { |
|
|
|
|
forceUserOnline(userID); |
|
|
|
|
safeReplaceObject(users[userID].photo, update.photo); |
|
|
|
|
|
|
|
|
|
if (cachedPhotoLocations[userID] !== undefined) { |
|
|
|
@ -333,6 +342,7 @@ angular.module('myApp.services', [])
@@ -333,6 +342,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
saveApiUser: saveApiUser, |
|
|
|
|
getUser: getUser, |
|
|
|
|
getUserInput: getUserInput, |
|
|
|
|
forceUserOnline: forceUserOnline, |
|
|
|
|
getUserPhoto: getUserPhoto, |
|
|
|
|
getUserString: getUserString, |
|
|
|
|
getUserSearchText: getUserSearchText, |
|
|
|
@ -744,6 +754,8 @@ angular.module('myApp.services', [])
@@ -744,6 +754,8 @@ angular.module('myApp.services', [])
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var dateOrTimeFilter = $filter('dateOrTime'); |
|
|
|
|
|
|
|
|
|
midnightOffseted.setHours(0); |
|
|
|
|
midnightOffseted.setMinutes(0); |
|
|
|
|
midnightOffseted.setSeconds(0); |
|
|
|
@ -885,7 +897,7 @@ angular.module('myApp.services', [])
@@ -885,7 +897,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function getHistory (inputPeer, maxID, limit, backLimit) { |
|
|
|
|
function getHistory (inputPeer, maxID, limit, backLimit, prerendered) { |
|
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
|
offset = 0, |
|
|
|
@ -894,6 +906,8 @@ angular.module('myApp.services', [])
@@ -894,6 +906,8 @@ angular.module('myApp.services', [])
|
|
|
|
|
unreadSkip = false, |
|
|
|
|
resultPending = []; |
|
|
|
|
|
|
|
|
|
prerendered = prerendered ? Math.min(50, prerendered) : 0; |
|
|
|
|
|
|
|
|
|
if (historyStorage === undefined) { |
|
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
|
|
} |
|
|
|
@ -910,7 +924,7 @@ angular.module('myApp.services', [])
@@ -910,7 +924,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
unreadOffset = 6; |
|
|
|
|
offset = unreadCount - unreadOffset; |
|
|
|
|
} else { |
|
|
|
|
limit = Math.max(10, unreadCount + 2); |
|
|
|
|
limit = Math.max(10, prerendered, unreadCount + 2); |
|
|
|
|
unreadOffset = unreadCount; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -934,9 +948,8 @@ angular.module('myApp.services', [])
@@ -934,9 +948,8 @@ angular.module('myApp.services', [])
|
|
|
|
|
offset = Math.max(0, offset - backLimit); |
|
|
|
|
limit += backLimit; |
|
|
|
|
} else { |
|
|
|
|
limit = limit || (offset ? 20 : 5); |
|
|
|
|
limit = limit || (offset ? 20 : (prerendered || 5)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $q.when({ |
|
|
|
|
count: historyStorage.count, |
|
|
|
|
history: resultPending.concat(historyStorage.history.slice(offset, offset + limit)), |
|
|
|
@ -946,12 +959,11 @@ angular.module('myApp.services', [])
@@ -946,12 +959,11 @@ angular.module('myApp.services', [])
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!backLimit && !limit) { |
|
|
|
|
limit = 20; |
|
|
|
|
limit = prerendered || 20; |
|
|
|
|
} |
|
|
|
|
if (offsetNotFound) { |
|
|
|
|
offset = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (backLimit || unreadSkip || maxID && historyStorage.history.indexOf(maxID) == -1) { |
|
|
|
|
if (backLimit) { |
|
|
|
|
offset = -backLimit; |
|
|
|
@ -1187,6 +1199,7 @@ angular.module('myApp.services', [])
@@ -1187,6 +1199,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
// console.log('done read history', peerID);
|
|
|
|
|
foundDialog[0].unread_count = 0; |
|
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: 0}); |
|
|
|
|
$rootScope.$broadcast('messages_read'); |
|
|
|
|
} |
|
|
|
|
})['finally'](function () { |
|
|
|
|
delete historyStorage.readPromise; |
|
|
|
@ -1296,6 +1309,7 @@ angular.module('myApp.services', [])
@@ -1296,6 +1309,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
delete historyMessage.error; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
@ -1420,6 +1434,7 @@ angular.module('myApp.services', [])
@@ -1420,6 +1434,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
delete historyMessage.error; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
@ -1561,6 +1576,7 @@ angular.module('myApp.services', [])
@@ -1561,6 +1576,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
delete historyMessage.error; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
@ -1699,6 +1715,8 @@ angular.module('myApp.services', [])
@@ -1699,6 +1715,8 @@ angular.module('myApp.services', [])
|
|
|
|
|
delete historyMessage.error; |
|
|
|
|
delete historyMessage.random_id; |
|
|
|
|
delete historyMessage.send; |
|
|
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delete messagesForHistory[tempID]; |
|
|
|
@ -1722,7 +1740,9 @@ angular.module('myApp.services', [])
@@ -1722,7 +1740,9 @@ angular.module('myApp.services', [])
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function wrapForDialog (msgID, unreadCount) { |
|
|
|
|
if (messagesForDialogs[msgID] !== undefined) { |
|
|
|
|
var useCache = unreadCount != -1; |
|
|
|
|
|
|
|
|
|
if (useCache && messagesForDialogs[msgID] !== undefined) { |
|
|
|
|
return messagesForDialogs[msgID]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1751,10 +1771,13 @@ angular.module('myApp.services', [])
@@ -1751,10 +1771,13 @@ angular.module('myApp.services', [])
|
|
|
|
|
message.richMessage = RichTextProcessor.wrapRichText(message.message.substr(0, 64), {noLinks: true, noLinebreaks: true}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
message.dateText = $filter('dateOrTime')(message.date); |
|
|
|
|
message.dateText = dateOrTimeFilter(message.date); |
|
|
|
|
|
|
|
|
|
if (useCache) { |
|
|
|
|
messagesForDialogs[msgID] = message; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return messagesForDialogs[msgID] = message; |
|
|
|
|
return message; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function wrapForHistory (msgID) { |
|
|
|
@ -1816,12 +1839,13 @@ angular.module('myApp.services', [])
@@ -1816,12 +1839,13 @@ angular.module('myApp.services', [])
|
|
|
|
|
|
|
|
|
|
function regroupWrappedHistory (history, limit) { |
|
|
|
|
if (!history || !history.length) { |
|
|
|
|
return; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
var start = 0, |
|
|
|
|
len = history.length, |
|
|
|
|
end = len, |
|
|
|
|
i, curDay, prevDay, curMessage, prevMessage; |
|
|
|
|
i, curDay, prevDay, curMessage, prevMessage, curGrouped, prevGrouped, |
|
|
|
|
wasUpdated = false; |
|
|
|
|
|
|
|
|
|
if (limit > 0) { |
|
|
|
|
end = Math.min(limit, len); |
|
|
|
@ -1833,10 +1857,19 @@ angular.module('myApp.services', [])
@@ -1833,10 +1857,19 @@ angular.module('myApp.services', [])
|
|
|
|
|
curMessage = history[i]; |
|
|
|
|
curDay = Math.floor((curMessage.date + midnightOffset) / 86400); |
|
|
|
|
|
|
|
|
|
prevGrouped = prevMessage && prevMessage.grouped; |
|
|
|
|
curGrouped = curMessage.grouped; |
|
|
|
|
|
|
|
|
|
if (curDay === prevDay) { |
|
|
|
|
if (curMessage.needDate) { |
|
|
|
|
delete curMessage.needDate; |
|
|
|
|
wasUpdated = true; |
|
|
|
|
} |
|
|
|
|
} else if (!i || prevMessage) { |
|
|
|
|
if (!curMessage.needDate) { |
|
|
|
|
curMessage.needDate = true; |
|
|
|
|
wasUpdated = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (prevMessage && |
|
|
|
@ -1867,9 +1900,17 @@ angular.module('myApp.services', [])
@@ -1867,9 +1900,17 @@ angular.module('myApp.services', [])
|
|
|
|
|
prevMessage.grouped += ' im_grouped_fwd_end'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!wasUpdated && prevGrouped != (prevMessage && prevMessage.grouped)) { |
|
|
|
|
wasUpdated = true; |
|
|
|
|
} |
|
|
|
|
prevMessage = curMessage; |
|
|
|
|
prevDay = curDay; |
|
|
|
|
} |
|
|
|
|
if (!wasUpdated && curGrouped != (prevMessage && prevMessage.grouped)) { |
|
|
|
|
wasUpdated = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return wasUpdated; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getDialogByPeerID (peerID) { |
|
|
|
@ -1992,6 +2033,10 @@ angular.module('myApp.services', [])
@@ -1992,6 +2033,10 @@ angular.module('myApp.services', [])
|
|
|
|
|
peerID = getMessagePeer(message), |
|
|
|
|
historyStorage = historiesStorage[peerID]; |
|
|
|
|
|
|
|
|
|
if (!message.out) { |
|
|
|
|
AppUsersManager.forceUserOnline(message.from_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (historyStorage !== undefined) { |
|
|
|
|
var topMsgID = historiesStorage[peerID].history[0]; |
|
|
|
|
if (historiesStorage[peerID].history.indexOf(message.id) != -1) { |
|
|
|
@ -2066,7 +2111,8 @@ angular.module('myApp.services', [])
@@ -2066,7 +2111,8 @@ angular.module('myApp.services', [])
|
|
|
|
|
|
|
|
|
|
case 'updateReadMessages': |
|
|
|
|
var dialogsUpdated = {}, |
|
|
|
|
messageID, message, i, peerID, foundDialog, dialog; |
|
|
|
|
messageID, message, i, peerID, foundDialog, dialog, |
|
|
|
|
foundAffected = false; |
|
|
|
|
for (i = 0; i < update.messages.length; i++) { |
|
|
|
|
messageID = update.messages[i]; |
|
|
|
|
message = messagesStorage[messageID]; |
|
|
|
@ -2075,6 +2121,9 @@ angular.module('myApp.services', [])
@@ -2075,6 +2121,9 @@ angular.module('myApp.services', [])
|
|
|
|
|
message.unread = false; |
|
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
|
messagesForHistory[messageID].unread = false; |
|
|
|
|
if (!foundAffected) { |
|
|
|
|
foundAffected = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
|
messagesForDialogs[messageID].unread = false; |
|
|
|
@ -2088,12 +2137,18 @@ angular.module('myApp.services', [])
@@ -2088,12 +2137,18 @@ angular.module('myApp.services', [])
|
|
|
|
|
|
|
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
|
} |
|
|
|
|
else if (peerID > 0) { |
|
|
|
|
AppUsersManager.forceUserOnline(peerID); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
angular.forEach(dialogsUpdated, function(count, peerID) { |
|
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: count}); |
|
|
|
|
}); |
|
|
|
|
if (foundAffected) { |
|
|
|
|
$rootScope.$broadcast('messages_read'); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'updateDeleteMessages': |
|
|
|
@ -2511,7 +2566,6 @@ angular.module('myApp.services', [])
@@ -2511,7 +2566,6 @@ angular.module('myApp.services', [])
|
|
|
|
|
full.width = fullWidth; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// console.log(222, video.w, video.h, full.width, full.height);
|
|
|
|
|
|
|
|
|
|
video.full = full; |
|
|
|
|
video.fullThumb = angular.copy(video.thumb); |
|
|
|
@ -3543,7 +3597,7 @@ angular.module('myApp.services', [])
@@ -3543,7 +3597,7 @@ angular.module('myApp.services', [])
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function notify (data) { |
|
|
|
|
console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport); |
|
|
|
|
// console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport);
|
|
|
|
|
|
|
|
|
|
// FFOS Notification blob src bug workaround
|
|
|
|
|
if (Config.Navigator.ffos) { |
|
|
|
|