|
|
@ -163,13 +163,21 @@ angular.module('myApp.services', []) |
|
|
|
var timestampNow = tsNow(true) + serverTimeOffset; |
|
|
|
var timestampNow = tsNow(true) + serverTimeOffset; |
|
|
|
angular.forEach(users, function (user) { |
|
|
|
angular.forEach(users, function (user) { |
|
|
|
if (user.status && user.status._ == 'userStatusOnline' && |
|
|
|
if (user.status && user.status._ == 'userStatusOnline' && |
|
|
|
user.status.expires > timestampNow) { |
|
|
|
user.status.expires < timestampNow) { |
|
|
|
user.status = {_: 'userStatusOffline', was_online: user.status.expires}; |
|
|
|
user.status = {_: 'userStatusOffline', was_online: user.status.expires}; |
|
|
|
$rootScope.$broadcast('user_update', user.id); |
|
|
|
$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) { |
|
|
|
function wrapForFull (id) { |
|
|
|
var user = getUser(id); |
|
|
|
var user = getUser(id); |
|
|
|
|
|
|
|
|
|
|
@ -308,6 +316,7 @@ angular.module('myApp.services', []) |
|
|
|
case 'updateUserPhoto': |
|
|
|
case 'updateUserPhoto': |
|
|
|
var userID = update.user_id; |
|
|
|
var userID = update.user_id; |
|
|
|
if (users[userID]) { |
|
|
|
if (users[userID]) { |
|
|
|
|
|
|
|
forceUserOnline(userID); |
|
|
|
safeReplaceObject(users[userID].photo, update.photo); |
|
|
|
safeReplaceObject(users[userID].photo, update.photo); |
|
|
|
|
|
|
|
|
|
|
|
if (cachedPhotoLocations[userID] !== undefined) { |
|
|
|
if (cachedPhotoLocations[userID] !== undefined) { |
|
|
@ -333,6 +342,7 @@ angular.module('myApp.services', []) |
|
|
|
saveApiUser: saveApiUser, |
|
|
|
saveApiUser: saveApiUser, |
|
|
|
getUser: getUser, |
|
|
|
getUser: getUser, |
|
|
|
getUserInput: getUserInput, |
|
|
|
getUserInput: getUserInput, |
|
|
|
|
|
|
|
forceUserOnline: forceUserOnline, |
|
|
|
getUserPhoto: getUserPhoto, |
|
|
|
getUserPhoto: getUserPhoto, |
|
|
|
getUserString: getUserString, |
|
|
|
getUserString: getUserString, |
|
|
|
getUserSearchText: getUserSearchText, |
|
|
|
getUserSearchText: getUserSearchText, |
|
|
@ -744,6 +754,8 @@ angular.module('myApp.services', []) |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dateOrTimeFilter = $filter('dateOrTime'); |
|
|
|
|
|
|
|
|
|
|
|
midnightOffseted.setHours(0); |
|
|
|
midnightOffseted.setHours(0); |
|
|
|
midnightOffseted.setMinutes(0); |
|
|
|
midnightOffseted.setMinutes(0); |
|
|
|
midnightOffseted.setSeconds(0); |
|
|
|
midnightOffseted.setSeconds(0); |
|
|
@ -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), |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
offset = 0, |
|
|
|
offset = 0, |
|
|
@ -894,6 +906,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: []}; |
|
|
|
} |
|
|
|
} |
|
|
@ -910,7 +924,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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -934,9 +948,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)), |
|
|
@ -946,12 +959,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; |
|
|
@ -1187,6 +1199,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; |
|
|
@ -1296,6 +1309,7 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
@ -1420,6 +1434,7 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
@ -1561,6 +1576,7 @@ angular.module('myApp.services', []) |
|
|
|
delete historyMessage.error; |
|
|
|
delete historyMessage.error; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$rootScope.$broadcast('messages_pending'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
message.send = function () { |
|
|
|
message.send = function () { |
|
|
@ -1699,6 +1715,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]; |
|
|
@ -1722,7 +1740,9 @@ angular.module('myApp.services', []) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function wrapForDialog (msgID, unreadCount) { |
|
|
|
function wrapForDialog (msgID, unreadCount) { |
|
|
|
if (messagesForDialogs[msgID] !== undefined) { |
|
|
|
var useCache = unreadCount != -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (useCache && messagesForDialogs[msgID] !== undefined) { |
|
|
|
return messagesForDialogs[msgID]; |
|
|
|
return messagesForDialogs[msgID]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1751,10 +1771,13 @@ angular.module('myApp.services', []) |
|
|
|
message.richMessage = RichTextProcessor.wrapRichText(message.message.substr(0, 64), {noLinks: true, noLinebreaks: true}); |
|
|
|
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) { |
|
|
|
function wrapForHistory (msgID) { |
|
|
@ -1816,12 +1839,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); |
|
|
@ -1833,10 +1857,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) { |
|
|
|
|
|
|
|
if (curMessage.needDate) { |
|
|
|
delete curMessage.needDate; |
|
|
|
delete curMessage.needDate; |
|
|
|
|
|
|
|
wasUpdated = true; |
|
|
|
|
|
|
|
} |
|
|
|
} else if (!i || prevMessage) { |
|
|
|
} else if (!i || prevMessage) { |
|
|
|
|
|
|
|
if (!curMessage.needDate) { |
|
|
|
curMessage.needDate = true; |
|
|
|
curMessage.needDate = true; |
|
|
|
|
|
|
|
wasUpdated = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (prevMessage && |
|
|
|
if (prevMessage && |
|
|
@ -1867,9 +1900,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) { |
|
|
@ -1992,6 +2033,10 @@ angular.module('myApp.services', []) |
|
|
|
peerID = getMessagePeer(message), |
|
|
|
peerID = getMessagePeer(message), |
|
|
|
historyStorage = historiesStorage[peerID]; |
|
|
|
historyStorage = historiesStorage[peerID]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!message.out) { |
|
|
|
|
|
|
|
AppUsersManager.forceUserOnline(message.from_id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (historyStorage !== undefined) { |
|
|
|
if (historyStorage !== undefined) { |
|
|
|
var topMsgID = historiesStorage[peerID].history[0]; |
|
|
|
var topMsgID = historiesStorage[peerID].history[0]; |
|
|
|
if (historiesStorage[peerID].history.indexOf(message.id) != -1) { |
|
|
|
if (historiesStorage[peerID].history.indexOf(message.id) != -1) { |
|
|
@ -2066,7 +2111,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]; |
|
|
@ -2075,6 +2121,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; |
|
|
@ -2088,12 +2137,18 @@ angular.module('myApp.services', []) |
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (peerID > 0) { |
|
|
|
|
|
|
|
AppUsersManager.forceUserOnline(peerID); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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': |
|
|
@ -2511,7 +2566,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); |
|
|
@ -3543,7 +3597,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) { |
|
|
|