|
|
@ -65,13 +65,14 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
NotificationsManager.start(); |
|
|
|
NotificationsManager.start(); |
|
|
|
|
|
|
|
|
|
|
|
var allChannelsLoaded = false; |
|
|
|
|
|
|
|
var channelsLoadPromise = false; |
|
|
|
|
|
|
|
var allDialogsLoaded = false |
|
|
|
var allDialogsLoaded = false |
|
|
|
var loadedDialogsCount = 0; |
|
|
|
var loadedDialogsCount = 0; |
|
|
|
var dialogsNum = 0; |
|
|
|
var dialogsNum = 0; |
|
|
|
var minDialogsIndex = Math.pow(2, 50); |
|
|
|
var minDialogsIndex = Math.pow(2, 50); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var migratedFromTo = {}; |
|
|
|
|
|
|
|
var migratedToFrom = {}; |
|
|
|
|
|
|
|
|
|
|
|
function getConversations (query, offsetIndex, limit) { |
|
|
|
function getConversations (query, offsetIndex, limit) { |
|
|
|
var curDialogStorage = dialogsStorage; |
|
|
|
var curDialogStorage = dialogsStorage; |
|
|
|
var isSearch = angular.isString(query) && query.length; |
|
|
|
var isSearch = angular.isString(query) && query.length; |
|
|
@ -108,7 +109,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
isSearch || |
|
|
|
isSearch || |
|
|
|
(allChannelsLoaded && allDialogsLoaded) || |
|
|
|
allDialogsLoaded || |
|
|
|
( |
|
|
|
( |
|
|
|
curDialogStorage.dialogs.length >= offset + limit && |
|
|
|
curDialogStorage.dialogs.length >= offset + limit && |
|
|
|
curDialogStorage.dialogs[offset + limit - 1].index >= minDialogsIndex |
|
|
|
curDialogStorage.dialogs[offset + limit - 1].index >= minDialogsIndex |
|
|
@ -119,7 +120,7 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $q.all([getAllChannels(), getTopMessages(loadedDialogsCount, limit)]).then(function () { |
|
|
|
return getTopMessages(limit).then(function () { |
|
|
|
offset = 0; |
|
|
|
offset = 0; |
|
|
|
if (offsetIndex > 0) { |
|
|
|
if (offsetIndex > 0) { |
|
|
|
for (offset = 0; offset < curDialogStorage.dialogs.length; offset++) { |
|
|
|
for (offset = 0; offset < curDialogStorage.dialogs.length; offset++) { |
|
|
@ -149,9 +150,14 @@ angular.module('myApp.services') |
|
|
|
var peerText = AppPeersManager.getPeerSearchText(peerID); |
|
|
|
var peerText = AppPeersManager.getPeerSearchText(peerID); |
|
|
|
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex); |
|
|
|
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var isMegagroup = AppChatsManager.isMegagroup(channelID); |
|
|
|
|
|
|
|
if (isMegagroup) { |
|
|
|
|
|
|
|
var mid = getFullMessageID(dialog.top_message, channelID); |
|
|
|
|
|
|
|
} else { |
|
|
|
var mid = getFullMessageID(dialog.top_important_message, channelID); |
|
|
|
var mid = getFullMessageID(dialog.top_important_message, channelID); |
|
|
|
dialog.top_message = mid; |
|
|
|
|
|
|
|
dialog.unread_count = dialog.unread_important_count; |
|
|
|
dialog.unread_count = dialog.unread_important_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dialog.top_message = mid; |
|
|
|
dialog.read_inbox_max_id = getFullMessageID(dialog.read_inbox_max_id, channelID); |
|
|
|
dialog.read_inbox_max_id = getFullMessageID(dialog.read_inbox_max_id, channelID); |
|
|
|
|
|
|
|
|
|
|
|
var message = getMessage(dialog.top_message); |
|
|
|
var message = getMessage(dialog.top_message); |
|
|
@ -168,7 +174,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
// Because we saved message without dialog present
|
|
|
|
// Because we saved message without dialog present
|
|
|
|
if (message.mid && message.mid > dialog.read_inbox_max_id) { |
|
|
|
if (message.mid && message.mid > dialog.read_inbox_max_id) { |
|
|
|
message.unread = true; |
|
|
|
message.pFlags.unread = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (historiesStorage[peerID] === undefined) { |
|
|
|
if (historiesStorage[peerID] === undefined) { |
|
|
@ -180,46 +186,34 @@ angular.module('myApp.services') |
|
|
|
ApiUpdatesManager.addChannelState(channelID, dialog.pts); |
|
|
|
ApiUpdatesManager.addChannelState(channelID, dialog.pts); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getAllChannels () { |
|
|
|
function getTopMessages (limit) { |
|
|
|
if (channelsLoadPromise) { |
|
|
|
var first = true; |
|
|
|
return channelsLoadPromise; |
|
|
|
var dialogs = dialogsStorage.dialogs; |
|
|
|
|
|
|
|
var len = dialogs && dialogs.length; |
|
|
|
|
|
|
|
var offsetDate = 0; |
|
|
|
|
|
|
|
var offsetID = 0; |
|
|
|
|
|
|
|
var offsetPeerID = 0; |
|
|
|
|
|
|
|
if (len) { |
|
|
|
|
|
|
|
var dialog = dialogs[len - 1]; |
|
|
|
|
|
|
|
var index = dialog.index; |
|
|
|
|
|
|
|
if (index) { |
|
|
|
|
|
|
|
offsetDate = Math.ceil(index / 0x10000); |
|
|
|
|
|
|
|
offsetID = dialog.top_message; |
|
|
|
|
|
|
|
offsetPeerID = dialog.peerID; |
|
|
|
} |
|
|
|
} |
|
|
|
return channelsLoadPromise = MtpApiManager.invokeApi('channels.getDialogs', { |
|
|
|
|
|
|
|
offset: 0, |
|
|
|
|
|
|
|
limit: 100 |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
timeout: 300 |
|
|
|
|
|
|
|
}).then(function (dialogsResult) { |
|
|
|
|
|
|
|
AppUsersManager.saveApiUsers(dialogsResult.users); |
|
|
|
|
|
|
|
AppChatsManager.saveApiChats(dialogsResult.chats); |
|
|
|
|
|
|
|
saveMessages(dialogsResult.messages); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
angular.forEach(dialogsResult.dialogs, function (dialog) { |
|
|
|
|
|
|
|
var peerID = AppPeersManager.getPeerID(dialog.peer); |
|
|
|
|
|
|
|
var channelID = -peerID; |
|
|
|
|
|
|
|
saveChannelDialog(channelID, dialog); |
|
|
|
|
|
|
|
ApiUpdatesManager.addChannelState(channelID, dialog.pts); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
allChannelsLoaded = true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getTopMessages (offset, limit) { |
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.getDialogs', { |
|
|
|
return MtpApiManager.invokeApi('messages.getDialogs', { |
|
|
|
offset: offset, |
|
|
|
offset_date: offsetDate, |
|
|
|
|
|
|
|
offset_id: getMessageLocalID(offsetID), |
|
|
|
|
|
|
|
offset_peer: AppPeersManager.getInputPeerByID(offsetPeerID), |
|
|
|
limit: limit |
|
|
|
limit: limit |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
timeout: 300 |
|
|
|
timeout: 300 |
|
|
|
}).then(function (dialogsResult) { |
|
|
|
}).then(function (dialogsResult) { |
|
|
|
if (!offset) { |
|
|
|
if (!offsetDate) { |
|
|
|
TelegramMeWebService.setAuthorized(true); |
|
|
|
TelegramMeWebService.setAuthorized(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Server-side bug
|
|
|
|
|
|
|
|
if (dialogsResult.count && offset >= dialogsResult.count) { |
|
|
|
|
|
|
|
dialogsResult.dialogs = []; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AppUsersManager.saveApiUsers(dialogsResult.users); |
|
|
|
AppUsersManager.saveApiUsers(dialogsResult.users); |
|
|
|
AppChatsManager.saveApiChats(dialogsResult.chats); |
|
|
|
AppChatsManager.saveApiChats(dialogsResult.chats); |
|
|
|
saveMessages(dialogsResult.messages); |
|
|
|
saveMessages(dialogsResult.messages); |
|
|
@ -227,12 +221,24 @@ angular.module('myApp.services') |
|
|
|
if (!dialogsResult.dialogs.length) { |
|
|
|
if (!dialogsResult.dialogs.length) { |
|
|
|
allDialogsLoaded = true; |
|
|
|
allDialogsLoaded = true; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!offset) { |
|
|
|
|
|
|
|
incrementMaxSeenID(dialogsResult.dialogs[0].top_message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var maxSeenIdIncremented = offsetDate ? true : false; |
|
|
|
angular.forEach(dialogsResult.dialogs, function (dialog) { |
|
|
|
angular.forEach(dialogsResult.dialogs, function (dialog) { |
|
|
|
var peerID = AppPeersManager.getPeerID(dialog.peer); |
|
|
|
var peerID = AppPeersManager.getPeerID(dialog.peer); |
|
|
|
|
|
|
|
if (dialog._ == 'dialogChannel') { |
|
|
|
|
|
|
|
var channelID = -peerID; |
|
|
|
|
|
|
|
saveChannelDialog(channelID, dialog); |
|
|
|
|
|
|
|
ApiUpdatesManager.addChannelState(channelID, dialog.pts); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (peerID < 0) { |
|
|
|
|
|
|
|
var chat = AppChatsManager.getChat(-peerID); |
|
|
|
|
|
|
|
if (chat && chat.migrated_to && chat.pFlags.deactivated) { |
|
|
|
|
|
|
|
var migratedToPeer = AppPeersManager.getPeerID(chat.migrated_to); |
|
|
|
|
|
|
|
migratedFromTo[peerID] = migratedToPeer; |
|
|
|
|
|
|
|
migratedToFrom[migratedToPeer] = peerID; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
var peerText = AppPeersManager.getPeerSearchText(peerID); |
|
|
|
var peerText = AppPeersManager.getPeerSearchText(peerID); |
|
|
|
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex); |
|
|
|
SearchIndexManager.indexObject(peerID, peerText, dialogsIndex); |
|
|
|
|
|
|
|
|
|
|
@ -243,6 +249,11 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
pushDialogToStorage(dialog); |
|
|
|
pushDialogToStorage(dialog); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!maxSeenIdIncremented) { |
|
|
|
|
|
|
|
incrementMaxSeenID(dialog.top_message); |
|
|
|
|
|
|
|
maxSeenIdIncremented = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (historiesStorage[peerID] === undefined) { |
|
|
|
if (historiesStorage[peerID] === undefined) { |
|
|
|
var historyStorage = {count: null, history: [dialog.top_message], pending: []}; |
|
|
|
var historyStorage = {count: null, history: [dialog.top_message], pending: []}; |
|
|
|
historiesStorage[peerID] = historyStorage; |
|
|
|
historiesStorage[peerID] = historyStorage; |
|
|
@ -259,7 +270,7 @@ angular.module('myApp.services') |
|
|
|
dialog.top_message > maxSeenID |
|
|
|
dialog.top_message > maxSeenID |
|
|
|
) { |
|
|
|
) { |
|
|
|
var notifyPeer = message.flags & 16 ? message.from_id : peerID; |
|
|
|
var notifyPeer = message.flags & 16 ? message.from_id : peerID; |
|
|
|
if (message.unread && !message.out) { |
|
|
|
if (message.pFlags.unread && !message.pFlags.out) { |
|
|
|
NotificationsManager.getPeerMuted(notifyPeer).then(function (muted) { |
|
|
|
NotificationsManager.getPeerMuted(notifyPeer).then(function (muted) { |
|
|
|
if (!muted) { |
|
|
|
if (!muted) { |
|
|
|
notifyAboutMessage(message); |
|
|
|
notifyAboutMessage(message); |
|
|
@ -267,6 +278,7 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -311,11 +323,12 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function requestHistory (inputPeer, maxID, limit, offset) { |
|
|
|
function requestHistory (peerID, maxID, limit, offset) { |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer); |
|
|
|
|
|
|
|
var isChannel = AppPeersManager.isChannel(peerID); |
|
|
|
var isChannel = AppPeersManager.isChannel(peerID); |
|
|
|
|
|
|
|
var isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID); |
|
|
|
|
|
|
|
|
|
|
|
var promise; |
|
|
|
var promise; |
|
|
|
if (isChannel) { |
|
|
|
if (isChannel && !isMegagroup) { |
|
|
|
promise = MtpApiManager.invokeApi('channels.getImportantHistory', { |
|
|
|
promise = MtpApiManager.invokeApi('channels.getImportantHistory', { |
|
|
|
channel: AppChatsManager.getChannelInput(-peerID), |
|
|
|
channel: AppChatsManager.getChannelInput(-peerID), |
|
|
|
offset_id: maxID ? getMessageLocalID(maxID) : 0, |
|
|
|
offset_id: maxID ? getMessageLocalID(maxID) : 0, |
|
|
@ -327,7 +340,7 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
promise = MtpApiManager.invokeApi('messages.getHistory', { |
|
|
|
promise = MtpApiManager.invokeApi('messages.getHistory', { |
|
|
|
peer: inputPeer, |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
offset_id: maxID ? getMessageLocalID(maxID) : 0, |
|
|
|
offset_id: maxID ? getMessageLocalID(maxID) : 0, |
|
|
|
add_offset: offset || 0, |
|
|
|
add_offset: offset || 0, |
|
|
|
limit: limit || 0 |
|
|
|
limit: limit || 0 |
|
|
@ -364,6 +377,7 @@ angular.module('myApp.services') |
|
|
|
from_id: peerID, |
|
|
|
from_id: peerID, |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
flags: 0, |
|
|
|
flags: 0, |
|
|
|
|
|
|
|
pFlags: {}, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
action: { |
|
|
|
action: { |
|
|
|
_: 'messageActionBotIntro', |
|
|
|
_: 'messageActionBotIntro', |
|
|
@ -457,9 +471,13 @@ angular.module('myApp.services') |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function fillHistoryStorage (inputPeer, maxID, fullLimit, historyStorage) { |
|
|
|
function fillHistoryStorage (peerID, maxID, fullLimit, historyStorage) { |
|
|
|
// console.log('fill history storage', inputPeer, maxID, fullLimit, angular.copy(historyStorage));
|
|
|
|
// console.log('fill history storage', peerID, maxID, fullLimit, angular.copy(historyStorage));
|
|
|
|
return requestHistory (inputPeer, maxID, fullLimit).then(function (historyResult) { |
|
|
|
var migratedNextPeer = migratedFromTo[peerID]; |
|
|
|
|
|
|
|
var migratedPrevPeer = migratedToFrom[peerID]; |
|
|
|
|
|
|
|
var isMigrated = migratedNextPeer !== undefined || migratedPrevPeer !== undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return requestHistory (peerID, maxID, fullLimit).then(function (historyResult) { |
|
|
|
historyStorage.count = historyResult.count || historyResult.messages.length; |
|
|
|
historyStorage.count = historyResult.count || historyResult.messages.length; |
|
|
|
|
|
|
|
|
|
|
|
var offset = 0; |
|
|
|
var offset = 0; |
|
|
@ -474,21 +492,41 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var wasTotalCount = historyStorage.history.length; |
|
|
|
|
|
|
|
|
|
|
|
historyStorage.history.splice(offset, historyStorage.history.length - offset); |
|
|
|
historyStorage.history.splice(offset, historyStorage.history.length - offset); |
|
|
|
angular.forEach(historyResult.messages, function (message) { |
|
|
|
angular.forEach(historyResult.messages, function (message) { |
|
|
|
if (mergeReplyKeyboard(historyStorage, message)) { |
|
|
|
if (mergeReplyKeyboard(historyStorage, message)) { |
|
|
|
$rootScope.$broadcast('history_reply_markup', {peerID: AppPeersManager.getPeerID(inputPeer)}); |
|
|
|
$rootScope.$broadcast('history_reply_markup', {peerID: peerID}); |
|
|
|
} |
|
|
|
} |
|
|
|
historyStorage.history.push(message.mid); |
|
|
|
historyStorage.history.push(message.mid); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
fullLimit -= historyResult.messages.length; |
|
|
|
var totalCount = historyStorage.history.length; |
|
|
|
|
|
|
|
fullLimit -= (totalCount - wasTotalCount); |
|
|
|
|
|
|
|
|
|
|
|
if (fullLimit > 0 && historyStorage.history.length < historyStorage.count) { |
|
|
|
if (isMigrated) { |
|
|
|
maxID = historyStorage.history[historyStorage.history.length - 1]; |
|
|
|
historyStorage.count = Math.max(historyStorage.count, totalCount) + 1; |
|
|
|
return fillHistoryStorage(inputPeer, maxID, fullLimit, historyStorage); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fullLimit > 0) { |
|
|
|
|
|
|
|
maxID = historyStorage.history[totalCount - 1]; |
|
|
|
|
|
|
|
if (isMigrated) { |
|
|
|
|
|
|
|
if (!historyResult.messages.length) { |
|
|
|
|
|
|
|
if (migratedPrevPeer) { |
|
|
|
|
|
|
|
maxID = 0; |
|
|
|
|
|
|
|
peerID = migratedPrevPeer; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
historyStorage.count = totalCount; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return fillHistoryStorage(peerID, maxID, fullLimit, historyStorage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (totalCount < historyStorage.count) { |
|
|
|
|
|
|
|
return fillHistoryStorage(peerID, maxID, fullLimit, historyStorage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -499,7 +537,7 @@ angular.module('myApp.services') |
|
|
|
var i, message; |
|
|
|
var i, message; |
|
|
|
for (i = result.history.length - 1; i >= 0; i--) { |
|
|
|
for (i = result.history.length - 1; i >= 0; i--) { |
|
|
|
message = messagesStorage[result.history[i]]; |
|
|
|
message = messagesStorage[result.history[i]]; |
|
|
|
if (message && !message.out && message.unread) { |
|
|
|
if (message && !message.pFlags.out && message.pFlags.unread) { |
|
|
|
result.unreadOffset = i + 1; |
|
|
|
result.unreadOffset = i + 1; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -508,9 +546,11 @@ angular.module('myApp.services') |
|
|
|
return $q.when(result); |
|
|
|
return $q.when(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getHistory (inputPeer, maxID, limit, backLimit, prerendered) { |
|
|
|
function getHistory (peerID, maxID, limit, backLimit, prerendered) { |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
if (migratedFromTo[peerID]) { |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
peerID = migratedFromTo[peerID]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var historyStorage = historiesStorage[peerID], |
|
|
|
offset = 0, |
|
|
|
offset = 0, |
|
|
|
offsetNotFound = false, |
|
|
|
offsetNotFound = false, |
|
|
|
unreadOffset = false, |
|
|
|
unreadOffset = false, |
|
|
@ -522,6 +562,15 @@ angular.module('myApp.services') |
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var isMigrated = false; |
|
|
|
|
|
|
|
var reqPeerID = peerID; |
|
|
|
|
|
|
|
if (migratedToFrom[peerID]) { |
|
|
|
|
|
|
|
isMigrated = true; |
|
|
|
|
|
|
|
if (maxID && maxID < fullMsgIDModulus) { |
|
|
|
|
|
|
|
reqPeerID = migratedToFrom[peerID]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!limit && !maxID) { |
|
|
|
if (!limit && !maxID) { |
|
|
|
var foundDialog = getDialogByPeerID(peerID)[0]; |
|
|
|
var foundDialog = getDialogByPeerID(peerID)[0]; |
|
|
|
if (foundDialog && foundDialog.unread_count > 1) { |
|
|
|
if (foundDialog && foundDialog.unread_count > 1) { |
|
|
@ -590,8 +639,11 @@ angular.module('myApp.services') |
|
|
|
offset = -backLimit; |
|
|
|
offset = -backLimit; |
|
|
|
limit += backLimit; |
|
|
|
limit += backLimit; |
|
|
|
} |
|
|
|
} |
|
|
|
return requestHistory(inputPeer, maxID, limit, offset).then(function (historyResult) { |
|
|
|
return requestHistory(reqPeerID, maxID, limit, offset).then(function (historyResult) { |
|
|
|
historyStorage.count = historyResult.count || historyResult.messages.length; |
|
|
|
historyStorage.count = historyResult.count || historyResult.messages.length; |
|
|
|
|
|
|
|
if (isMigrated) { |
|
|
|
|
|
|
|
historyStorage.count++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var history = []; |
|
|
|
var history = []; |
|
|
|
angular.forEach(historyResult.messages, function (message) { |
|
|
|
angular.forEach(historyResult.messages, function (message) { |
|
|
@ -610,7 +662,7 @@ angular.module('myApp.services') |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return fillHistoryStorage(inputPeer, maxID, limit, historyStorage).then(function () { |
|
|
|
return fillHistoryStorage(peerID, maxID, limit, historyStorage).then(function () { |
|
|
|
offset = 0; |
|
|
|
offset = 0; |
|
|
|
if (maxID > 0) { |
|
|
|
if (maxID > 0) { |
|
|
|
for (offset = 0; offset < historyStorage.history.length; offset++) { |
|
|
|
for (offset = 0; offset < historyStorage.history.length; offset++) { |
|
|
@ -641,7 +693,7 @@ angular.module('myApp.services') |
|
|
|
function mergeReplyKeyboard (historyStorage, message) { |
|
|
|
function mergeReplyKeyboard (historyStorage, message) { |
|
|
|
// console.log('merge', message.mid, message.reply_markup, historyStorage.reply_markup);
|
|
|
|
// console.log('merge', message.mid, message.reply_markup, historyStorage.reply_markup);
|
|
|
|
if (!message.reply_markup && |
|
|
|
if (!message.reply_markup && |
|
|
|
!message.out && |
|
|
|
!message.pFlags.out && |
|
|
|
!message.action) { |
|
|
|
!message.action) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -657,7 +709,7 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
if (historyStorage.maxOutID && |
|
|
|
if (historyStorage.maxOutID && |
|
|
|
message.mid < historyStorage.maxOutID && |
|
|
|
message.mid < historyStorage.maxOutID && |
|
|
|
messageReplyMarkup.pFlags.one_time) { |
|
|
|
messageReplyMarkup.pFlags.single_use) { |
|
|
|
messageReplyMarkup.pFlags.hidden = true; |
|
|
|
messageReplyMarkup.pFlags.hidden = true; |
|
|
|
} |
|
|
|
} |
|
|
|
messageReplyMarkup = angular.extend({ |
|
|
|
messageReplyMarkup = angular.extend({ |
|
|
@ -671,9 +723,9 @@ angular.module('myApp.services') |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (message.out) { |
|
|
|
if (message.pFlags.out) { |
|
|
|
if (lastReplyMarkup) { |
|
|
|
if (lastReplyMarkup) { |
|
|
|
if (lastReplyMarkup.pFlags.one_time && |
|
|
|
if (lastReplyMarkup.pFlags.single_use && |
|
|
|
!lastReplyMarkup.pFlags.hidden && |
|
|
|
!lastReplyMarkup.pFlags.hidden && |
|
|
|
(message.mid > lastReplyMarkup.mid || message.mid < 0) && |
|
|
|
(message.mid > lastReplyMarkup.mid || message.mid < 0) && |
|
|
|
message.message) { |
|
|
|
message.message) { |
|
|
@ -707,10 +759,9 @@ angular.module('myApp.services') |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getSearch (inputPeer, query, inputFilter, maxID, limit) { |
|
|
|
function getSearch (peerID, query, inputFilter, maxID, limit) { |
|
|
|
var foundMsgs = [], |
|
|
|
var foundMsgs = [], |
|
|
|
useSearchCache = !query, |
|
|
|
useSearchCache = !query, |
|
|
|
peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
|
|
|
|
newSearchFilter = {peer: peerID, filter: inputFilter}, |
|
|
|
newSearchFilter = {peer: peerID, filter: inputFilter}, |
|
|
|
sameSearchCache = useSearchCache && angular.equals(lastSearchFilter, newSearchFilter); |
|
|
|
sameSearchCache = useSearchCache && angular.equals(lastSearchFilter, newSearchFilter); |
|
|
|
|
|
|
|
|
|
|
@ -719,7 +770,7 @@ angular.module('myApp.services') |
|
|
|
lastSearchResults = []; |
|
|
|
lastSearchResults = []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!maxID && !query) { |
|
|
|
if (peerID && !maxID && !query) { |
|
|
|
var historyStorage = historiesStorage[peerID]; |
|
|
|
var historyStorage = historiesStorage[peerID]; |
|
|
|
|
|
|
|
|
|
|
|
if (historyStorage !== undefined && historyStorage.history.length) { |
|
|
|
if (historyStorage !== undefined && historyStorage.history.length) { |
|
|
@ -786,9 +837,17 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.search', { |
|
|
|
var apiPromise; |
|
|
|
flags: 0, |
|
|
|
|
|
|
|
peer: inputPeer, |
|
|
|
if (peerID || !query) { |
|
|
|
|
|
|
|
var flags = 0; |
|
|
|
|
|
|
|
if (AppPeersManager.isChannel(peerID) && |
|
|
|
|
|
|
|
!AppPeersManager.isMegagroup(peerID)) { |
|
|
|
|
|
|
|
flags |= 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
apiPromise = MtpApiManager.invokeApi('messages.search', { |
|
|
|
|
|
|
|
flags: flags, |
|
|
|
|
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
q: query || '', |
|
|
|
q: query || '', |
|
|
|
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, |
|
|
|
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, |
|
|
|
min_date: 0, |
|
|
|
min_date: 0, |
|
|
@ -798,7 +857,30 @@ angular.module('myApp.services') |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
timeout: 300, |
|
|
|
timeout: 300, |
|
|
|
noErrorBox: true |
|
|
|
noErrorBox: true |
|
|
|
}).then(function (searchResult) { |
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var offsetDate = 0; |
|
|
|
|
|
|
|
var offsetPeerID = 0; |
|
|
|
|
|
|
|
var offsetID = 0; |
|
|
|
|
|
|
|
var offsetMessage = maxID && getMessage(maxID); |
|
|
|
|
|
|
|
if (offsetMessage && offsetMessage.date) { |
|
|
|
|
|
|
|
offsetDate = offsetMessage.date; |
|
|
|
|
|
|
|
offsetID = offsetMessage.id; |
|
|
|
|
|
|
|
offsetPeerID = getMessagePeer(offsetMessage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
apiPromise = MtpApiManager.invokeApi('messages.searchGlobal', { |
|
|
|
|
|
|
|
q: query, |
|
|
|
|
|
|
|
offset_date: offsetDate, |
|
|
|
|
|
|
|
offset_peer: AppPeersManager.getInputPeerByID(offsetPeerID), |
|
|
|
|
|
|
|
offset_id: getMessageLocalID(offsetID), |
|
|
|
|
|
|
|
limit: limit || 20 |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
timeout: 300, |
|
|
|
|
|
|
|
noErrorBox: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return apiPromise.then(function (searchResult) { |
|
|
|
AppUsersManager.saveApiUsers(searchResult.users); |
|
|
|
AppUsersManager.saveApiUsers(searchResult.users); |
|
|
|
AppChatsManager.saveApiChats(searchResult.chats); |
|
|
|
AppChatsManager.saveApiChats(searchResult.chats); |
|
|
|
saveMessages(searchResult.messages); |
|
|
|
saveMessages(searchResult.messages); |
|
|
@ -832,6 +914,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
function deleteMessages (messageIDs) { |
|
|
|
function deleteMessages (messageIDs) { |
|
|
|
var splitted = splitMessageIDsByChannels(messageIDs); |
|
|
|
var splitted = splitMessageIDsByChannels(messageIDs); |
|
|
|
|
|
|
|
debugger; |
|
|
|
var promises = []; |
|
|
|
var promises = []; |
|
|
|
angular.forEach(splitted.msgIDs, function (msgIDs, channelID) { |
|
|
|
angular.forEach(splitted.msgIDs, function (msgIDs, channelID) { |
|
|
|
var promise; |
|
|
|
var promise; |
|
|
@ -842,7 +925,7 @@ angular.module('myApp.services') |
|
|
|
if (channel.pFlags.editor) { |
|
|
|
if (channel.pFlags.editor) { |
|
|
|
angular.forEach(msgIDs, function (msgID, i) { |
|
|
|
angular.forEach(msgIDs, function (msgID, i) { |
|
|
|
var message = getMessage(splitted.mids[channelID][i]); |
|
|
|
var message = getMessage(splitted.mids[channelID][i]); |
|
|
|
if (message.out) { |
|
|
|
if (message.pFlags.out) { |
|
|
|
goodMsgIDs.push(msgID); |
|
|
|
goodMsgIDs.push(msgID); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -888,32 +971,9 @@ angular.module('myApp.services') |
|
|
|
return $q.all(promises); |
|
|
|
return $q.all(promises); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function processAffectedHistory (inputPeer, affectedHistory, method) { |
|
|
|
function readHistory (peerID) { |
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
|
|
|
|
_: 'updateShort', |
|
|
|
|
|
|
|
update: { |
|
|
|
|
|
|
|
_: 'updatePts', |
|
|
|
|
|
|
|
pts: affectedHistory.pts, |
|
|
|
|
|
|
|
pts_count: affectedHistory.pts_count |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!affectedHistory.offset) { |
|
|
|
|
|
|
|
return $q.when(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return MtpApiManager.invokeApi(method, { |
|
|
|
|
|
|
|
peer: inputPeer, |
|
|
|
|
|
|
|
offset: affectedHistory.offset, |
|
|
|
|
|
|
|
max_id: 0 |
|
|
|
|
|
|
|
}).then(function (affectedHistory) { |
|
|
|
|
|
|
|
return processAffectedHistory(inputPeer, affectedHistory, method); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function readHistory (inputPeer) { |
|
|
|
|
|
|
|
// console.trace('start read');
|
|
|
|
// console.trace('start read');
|
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
var isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
|
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
foundDialog = getDialogByPeerID(peerID)[0]; |
|
|
|
foundDialog = getDialogByPeerID(peerID)[0]; |
|
|
|
|
|
|
|
|
|
|
@ -929,7 +989,7 @@ angular.module('myApp.services') |
|
|
|
for (i = historyStorage.history.length; i >= 0; i--) { |
|
|
|
for (i = historyStorage.history.length; i >= 0; i--) { |
|
|
|
messageID = historyStorage.history[i]; |
|
|
|
messageID = historyStorage.history[i]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
if (message && !message.out && message.unread) { |
|
|
|
if (message && !message.pFlags.out && message.pFlags.unread) { |
|
|
|
foundUnread = true; |
|
|
|
foundUnread = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -951,11 +1011,8 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
apiPromise = MtpApiManager.invokeApi('messages.readHistory', { |
|
|
|
apiPromise = MtpApiManager.invokeApi('messages.readHistory', { |
|
|
|
peer: inputPeer, |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
offset: 0, |
|
|
|
|
|
|
|
max_id: 0 |
|
|
|
max_id: 0 |
|
|
|
}).then(function (affectedHistory) { |
|
|
|
|
|
|
|
return processAffectedHistory(inputPeer, affectedHistory, 'messages.readHistory'); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -978,13 +1035,13 @@ angular.module('myApp.services') |
|
|
|
for (i = 0; i < historyStorage.history.length; i++) { |
|
|
|
for (i = 0; i < historyStorage.history.length; i++) { |
|
|
|
messageID = historyStorage.history[i]; |
|
|
|
messageID = historyStorage.history[i]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
if (message && !message.out) { |
|
|
|
if (message && !message.pFlags.out) { |
|
|
|
message.unread = false; |
|
|
|
message.pFlags.unread = false; |
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
messagesForHistory[messageID].unread = false; |
|
|
|
messagesForHistory[messageID].pFlags.unread = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
messagesForDialogs[messageID].unread = false; |
|
|
|
messagesForDialogs[messageID].pFlags.unread = false; |
|
|
|
} |
|
|
|
} |
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
} |
|
|
|
} |
|
|
@ -1012,17 +1069,28 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function flushHistory (inputPeer) { |
|
|
|
function doFlushHistory (inputPeer) { |
|
|
|
// console.log('start flush');
|
|
|
|
|
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
|
|
|
|
historyStorage = historiesStorage[peerID]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.deleteHistory', { |
|
|
|
return MtpApiManager.invokeApi('messages.deleteHistory', { |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
offset: 0 |
|
|
|
max_id: 0 |
|
|
|
}).then(function (affectedHistory) { |
|
|
|
}).then(function (affectedHistory) { |
|
|
|
return processAffectedHistory(inputPeer, affectedHistory, 'messages.deleteHistory'); |
|
|
|
ApiUpdatesManager.processUpdateMessage({ |
|
|
|
}).then(function () { |
|
|
|
_: 'updateShort', |
|
|
|
|
|
|
|
update: { |
|
|
|
|
|
|
|
_: 'updatePts', |
|
|
|
|
|
|
|
pts: affectedHistory.pts, |
|
|
|
|
|
|
|
pts_count: affectedHistory.pts_count |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (!affectedHistory.offset) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return doFlushHistory(inputPeer); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function flushHistory (peerID) { |
|
|
|
|
|
|
|
return doFlushHistory(AppPeersManager.getInputPeerByID(peerID)).then(function () { |
|
|
|
var foundDialog = getDialogByPeerID(peerID); |
|
|
|
var foundDialog = getDialogByPeerID(peerID); |
|
|
|
if (foundDialog[0]) { |
|
|
|
if (foundDialog[0]) { |
|
|
|
dialogsStorage.dialogs.splice(foundDialog[1], 1); |
|
|
|
dialogsStorage.dialogs.splice(foundDialog[1], 1); |
|
|
@ -1034,25 +1102,33 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
function saveMessages (apiMessages) { |
|
|
|
function saveMessages (apiMessages) { |
|
|
|
angular.forEach(apiMessages, function (apiMessage) { |
|
|
|
angular.forEach(apiMessages, function (apiMessage) { |
|
|
|
|
|
|
|
if (apiMessage.pFlags === undefined) { |
|
|
|
|
|
|
|
apiMessage.pFlags = {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!apiMessage.pFlags.out) { |
|
|
|
|
|
|
|
apiMessage.pFlags.out = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!apiMessage.pFlags.unread) { |
|
|
|
|
|
|
|
apiMessage.pFlags.unread = false; |
|
|
|
|
|
|
|
} |
|
|
|
if (apiMessage._ == 'messageEmpty') { |
|
|
|
if (apiMessage._ == 'messageEmpty') { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
apiMessage.out = apiMessage.flags & 2 ? true : false; |
|
|
|
|
|
|
|
apiMessage.media_unread = apiMessage.flags & 32 ? true : false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var toPeerID = AppPeersManager.getPeerID(apiMessage.to_id); |
|
|
|
var toPeerID = AppPeersManager.getPeerID(apiMessage.to_id); |
|
|
|
var isChannel = apiMessage.to_id._ == 'peerChannel'; |
|
|
|
var isChannel = apiMessage.to_id._ == 'peerChannel'; |
|
|
|
var channelID = isChannel ? -toPeerID : 0; |
|
|
|
var channelID = isChannel ? -toPeerID : 0; |
|
|
|
|
|
|
|
var isBroadcast = isChannel && !AppChatsManager.isMegagroup(channelID); |
|
|
|
|
|
|
|
|
|
|
|
var mid = getFullMessageID(apiMessage.id, channelID); |
|
|
|
var mid = getFullMessageID(apiMessage.id, channelID); |
|
|
|
apiMessage.mid = mid; |
|
|
|
apiMessage.mid = mid; |
|
|
|
messagesStorage[mid] = apiMessage; |
|
|
|
messagesStorage[mid] = apiMessage; |
|
|
|
|
|
|
|
|
|
|
|
if (channelID && !apiMessage.out) { |
|
|
|
if (channelID && !apiMessage.pFlags.out) { |
|
|
|
var dialog = getDialogByPeerID(toPeerID)[0]; |
|
|
|
var dialog = getDialogByPeerID(toPeerID)[0]; |
|
|
|
apiMessage.unread = dialog ? mid > dialog.read_inbox_max_id : true; |
|
|
|
apiMessage.pFlags.unread = dialog ? mid > dialog.read_inbox_max_id : true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
apiMessage.unread = apiMessage.flags & 1 ? true : false; |
|
|
|
apiMessage.pFlags.unread = apiMessage.flags & 1 ? true : false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (apiMessage.reply_to_msg_id) { |
|
|
|
if (apiMessage.reply_to_msg_id) { |
|
|
@ -1097,27 +1173,44 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (apiMessage.action) { |
|
|
|
if (apiMessage.action) { |
|
|
|
if (apiMessage.action._ == 'messageActionChatEditPhoto') { |
|
|
|
switch (apiMessage.action._) { |
|
|
|
|
|
|
|
case 'messageActionChatEditPhoto': |
|
|
|
AppPhotosManager.savePhoto(apiMessage.action.photo, mediaContext); |
|
|
|
AppPhotosManager.savePhoto(apiMessage.action.photo, mediaContext); |
|
|
|
if (isChannel) { |
|
|
|
if (isBroadcast) { |
|
|
|
apiMessage.action._ = 'messageActionChannelEditPhoto'; |
|
|
|
apiMessage.action._ = 'messageActionChannelEditPhoto'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
else if (isChannel) { |
|
|
|
|
|
|
|
if (apiMessage.action._ == 'messageActionChatEditTitle') { |
|
|
|
case 'messageActionChatEditTitle': |
|
|
|
|
|
|
|
if (isBroadcast) { |
|
|
|
apiMessage.action._ = 'messageActionChannelEditTitle'; |
|
|
|
apiMessage.action._ = 'messageActionChannelEditTitle'; |
|
|
|
} |
|
|
|
} |
|
|
|
if (apiMessage.action._ == 'messageActionChatDeletePhoto') { |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatDeletePhoto': |
|
|
|
|
|
|
|
if (isBroadcast) { |
|
|
|
apiMessage.action._ = 'messageActionChannelDeletePhoto'; |
|
|
|
apiMessage.action._ = 'messageActionChannelDeletePhoto'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatAddUser': |
|
|
|
|
|
|
|
if (apiMessage.action.users.length == 1) { |
|
|
|
|
|
|
|
apiMessage.action.user_id = apiMessage.action.users[0]; |
|
|
|
|
|
|
|
if (apiMessage.fromID == apiMessage.action.user_id) { |
|
|
|
|
|
|
|
apiMessage.action._ = 'messageActionChatReturn'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (apiMessage.reply_markup) { |
|
|
|
else if (apiMessage.action.users.length > 1) { |
|
|
|
apiMessage.reply_markup.pFlags = { |
|
|
|
apiMessage.action._ = 'messageActionChatAddUsers'; |
|
|
|
resize: (apiMessage.reply_markup.flags & 1) > 0, |
|
|
|
} |
|
|
|
one_time: (apiMessage.reply_markup.flags & 2) > 0, |
|
|
|
break; |
|
|
|
selective: (apiMessage.reply_markup.flags & 4) > 0 |
|
|
|
|
|
|
|
}; |
|
|
|
case 'messageActionChatDeleteUser': |
|
|
|
|
|
|
|
if (apiMessage.fromID == apiMessage.action.user_id) { |
|
|
|
|
|
|
|
apiMessage.action._ = 'messageActionChatLeave'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (apiMessage.message && apiMessage.message.length) { |
|
|
|
if (apiMessage.message && apiMessage.message.length) { |
|
|
@ -1137,11 +1230,12 @@ angular.module('myApp.services') |
|
|
|
randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], |
|
|
|
randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], |
|
|
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), |
|
|
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
inputPeer = AppPeersManager.getInputPeerByID(peerID), |
|
|
|
|
|
|
|
flags = 0, |
|
|
|
flags = 0, |
|
|
|
|
|
|
|
pFlags = {}, |
|
|
|
replyToMsgID = options.replyToMsgID, |
|
|
|
replyToMsgID = options.replyToMsgID, |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
asChannel = isChannel ? true : false, |
|
|
|
isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID), |
|
|
|
|
|
|
|
asChannel = isChannel && !isMegagroup ? true : false, |
|
|
|
entities = [], |
|
|
|
entities = [], |
|
|
|
message; |
|
|
|
message; |
|
|
|
|
|
|
|
|
|
|
@ -1154,8 +1248,10 @@ angular.module('myApp.services') |
|
|
|
var fromID = AppUsersManager.getSelf().id; |
|
|
|
var fromID = AppUsersManager.getSelf().id; |
|
|
|
if (peerID != fromID) { |
|
|
|
if (peerID != fromID) { |
|
|
|
flags |= 2; |
|
|
|
flags |= 2; |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
if (!isChannel && !AppUsersManager.isBot(peerID)) { |
|
|
|
if (!isChannel && !AppUsersManager.isBot(peerID)) { |
|
|
|
flags |= 1; |
|
|
|
flags |= 1; |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (replyToMsgID) { |
|
|
|
if (replyToMsgID) { |
|
|
@ -1172,6 +1268,7 @@ angular.module('myApp.services') |
|
|
|
from_id: fromID, |
|
|
|
from_id: fromID, |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
|
|
|
|
pFlags: pFlags, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
message: text, |
|
|
|
message: text, |
|
|
|
random_id: randomIDS, |
|
|
|
random_id: randomIDS, |
|
|
@ -1216,7 +1313,7 @@ angular.module('myApp.services') |
|
|
|
// console.log(flags, entities);
|
|
|
|
// console.log(flags, entities);
|
|
|
|
MtpApiManager.invokeApi('messages.sendMessage', { |
|
|
|
MtpApiManager.invokeApi('messages.sendMessage', { |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
peer: inputPeer, |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
message: text, |
|
|
|
message: text, |
|
|
|
random_id: randomID, |
|
|
|
random_id: randomID, |
|
|
|
reply_to_msg_id: getMessageLocalID(replyToMsgID), |
|
|
|
reply_to_msg_id: getMessageLocalID(replyToMsgID), |
|
|
@ -1274,11 +1371,12 @@ angular.module('myApp.services') |
|
|
|
randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], |
|
|
|
randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], |
|
|
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), |
|
|
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
inputPeer = AppPeersManager.getInputPeerByID(peerID), |
|
|
|
|
|
|
|
flags = 0, |
|
|
|
flags = 0, |
|
|
|
|
|
|
|
pFlags = {}, |
|
|
|
replyToMsgID = options.replyToMsgID, |
|
|
|
replyToMsgID = options.replyToMsgID, |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
asChannel = isChannel ? true : false, |
|
|
|
isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID), |
|
|
|
|
|
|
|
asChannel = isChannel && !isMegagroup ? true : false, |
|
|
|
attachType, apiFileName, realFileName; |
|
|
|
attachType, apiFileName, realFileName; |
|
|
|
|
|
|
|
|
|
|
|
if (!options.isMedia) { |
|
|
|
if (!options.isMedia) { |
|
|
@ -1305,8 +1403,10 @@ angular.module('myApp.services') |
|
|
|
var fromID = AppUsersManager.getSelf().id; |
|
|
|
var fromID = AppUsersManager.getSelf().id; |
|
|
|
if (peerID != fromID) { |
|
|
|
if (peerID != fromID) { |
|
|
|
flags |= 2; |
|
|
|
flags |= 2; |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
if (!isChannel && !AppUsersManager.isBot(peerID)) { |
|
|
|
if (!isChannel && !AppUsersManager.isBot(peerID)) { |
|
|
|
flags |= 1; |
|
|
|
flags |= 1; |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (replyToMsgID) { |
|
|
|
if (replyToMsgID) { |
|
|
@ -1331,6 +1431,7 @@ angular.module('myApp.services') |
|
|
|
from_id: fromID, |
|
|
|
from_id: fromID, |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
|
|
|
|
pFlags: pFlags, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
message: '', |
|
|
|
message: '', |
|
|
|
media: media, |
|
|
|
media: media, |
|
|
@ -1400,7 +1501,7 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
MtpApiManager.invokeApi('messages.sendMedia', { |
|
|
|
MtpApiManager.invokeApi('messages.sendMedia', { |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
peer: inputPeer, |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
media: inputMedia, |
|
|
|
media: inputMedia, |
|
|
|
random_id: randomID, |
|
|
|
random_id: randomID, |
|
|
|
reply_to_msg_id: getMessageLocalID(replyToMsgID) |
|
|
|
reply_to_msg_id: getMessageLocalID(replyToMsgID) |
|
|
@ -1458,10 +1559,10 @@ angular.module('myApp.services') |
|
|
|
randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], |
|
|
|
randomID = [nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)], |
|
|
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), |
|
|
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(), |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
inputPeer = AppPeersManager.getInputPeerByID(peerID), |
|
|
|
|
|
|
|
replyToMsgID = options.replyToMsgID, |
|
|
|
replyToMsgID = options.replyToMsgID, |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
isChannel = AppPeersManager.isChannel(peerID), |
|
|
|
asChannel = isChannel ? true : false; |
|
|
|
isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID), |
|
|
|
|
|
|
|
asChannel = isChannel && !isMegagroup ? true : false; |
|
|
|
|
|
|
|
|
|
|
|
if (historyStorage === undefined) { |
|
|
|
if (historyStorage === undefined) { |
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []}; |
|
|
@ -1494,10 +1595,13 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var flags = 0; |
|
|
|
var flags = 0; |
|
|
|
|
|
|
|
var pFlags = {}; |
|
|
|
if (peerID != fromID) { |
|
|
|
if (peerID != fromID) { |
|
|
|
flags |= 2; |
|
|
|
flags |= 2; |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
if (!AppUsersManager.isBot(peerID)) { |
|
|
|
if (!AppUsersManager.isBot(peerID)) { |
|
|
|
flags |= 1; |
|
|
|
flags |= 1; |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (replyToMsgID) { |
|
|
|
if (replyToMsgID) { |
|
|
@ -1515,6 +1619,7 @@ angular.module('myApp.services') |
|
|
|
from_id: fromID, |
|
|
|
from_id: fromID, |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
to_id: AppPeersManager.getOutputPeer(peerID), |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
|
|
|
|
pFlags: pFlags, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
date: tsNow(true) + serverTimeOffset, |
|
|
|
message: '', |
|
|
|
message: '', |
|
|
|
media: media, |
|
|
|
media: media, |
|
|
@ -1556,7 +1661,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
MtpApiManager.invokeApi('messages.sendMedia', { |
|
|
|
MtpApiManager.invokeApi('messages.sendMedia', { |
|
|
|
flags: flags, |
|
|
|
flags: flags, |
|
|
|
peer: inputPeer, |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
media: inputMedia, |
|
|
|
media: inputMedia, |
|
|
|
random_id: randomID, |
|
|
|
random_id: randomID, |
|
|
|
reply_to_msg_id: getMessageLocalID(replyToMsgID) |
|
|
|
reply_to_msg_id: getMessageLocalID(replyToMsgID) |
|
|
@ -1590,7 +1695,8 @@ angular.module('myApp.services') |
|
|
|
var i, mid, msgID; |
|
|
|
var i, mid, msgID; |
|
|
|
var fromChannel = getMessageIDInfo(mids[0])[1]; |
|
|
|
var fromChannel = getMessageIDInfo(mids[0])[1]; |
|
|
|
var isChannel = AppPeersManager.isChannel(peerID); |
|
|
|
var isChannel = AppPeersManager.isChannel(peerID); |
|
|
|
var asChannel = isChannel ? true : false; |
|
|
|
var isMegagroup = isChannel && AppPeersManager.isMegagroup(peerID); |
|
|
|
|
|
|
|
var asChannel = isChannel && !isMegagroup ? true : false; |
|
|
|
|
|
|
|
|
|
|
|
if (asChannel) { |
|
|
|
if (asChannel) { |
|
|
|
flags |= 16; |
|
|
|
flags |= 16; |
|
|
@ -1621,36 +1727,37 @@ angular.module('myApp.services') |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function startBot (botID, chatID, startParam) { |
|
|
|
function startBot (botID, chatID, startParam) { |
|
|
|
|
|
|
|
var peerID = chatID ? -chatID : botID; |
|
|
|
if (startParam) { |
|
|
|
if (startParam) { |
|
|
|
var randomID = bigint(nextRandomInt(0xFFFFFFFF)).shiftLeft(32).add(bigint(nextRandomInt(0xFFFFFFFF))).toString(); |
|
|
|
var randomID = bigint(nextRandomInt(0xFFFFFFFF)).shiftLeft(32).add(bigint(nextRandomInt(0xFFFFFFFF))).toString(); |
|
|
|
|
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.startBot', { |
|
|
|
return MtpApiManager.invokeApi('messages.startBot', { |
|
|
|
bot: AppUsersManager.getUserInput(botID), |
|
|
|
bot: AppUsersManager.getUserInput(botID), |
|
|
|
chat_id: AppChatsManager.getChatInput(chatID), |
|
|
|
peer: AppPeersManager.getInputPeerByID(peerID), |
|
|
|
random_id: randomID, |
|
|
|
random_id: randomID, |
|
|
|
start_param: startParam |
|
|
|
start_param: startParam |
|
|
|
|
|
|
|
}).then(function (updates) { |
|
|
|
|
|
|
|
ApiUpdatesManager.processUpdateMessage(updates); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var peerID = chatID ? -chatID : botID; |
|
|
|
|
|
|
|
var inputPeer = AppPeersManager.getInputPeerByID(peerID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (chatID) { |
|
|
|
if (chatID) { |
|
|
|
return MtpApiManager.invokeApi('messages.addChatUser', { |
|
|
|
return MtpApiManager.invokeApi('messages.addChatUser', { |
|
|
|
chat_id: AppChatsManager.getChatInput(chatID), |
|
|
|
chat_id: AppChatsManager.getChatInput(chatID), |
|
|
|
user_id: AppUsersManager.getUserInput(botID) |
|
|
|
user_id: AppUsersManager.getUserInput(botID) |
|
|
|
}).then(function (updates) { |
|
|
|
}).then(function (updates) { |
|
|
|
ApiUpdatesManager.processUpdateMessage(updates); |
|
|
|
ApiUpdatesManager.processUpdateMessage(updates); |
|
|
|
|
|
|
|
sendText(peerID, '/start@' + bot.username); |
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
if (error && error.type == 'USER_ALREADY_PARTICIPANT') { |
|
|
|
if (error && error.type == 'USER_ALREADY_PARTICIPANT') { |
|
|
|
var bot = AppUsersManager.getUser(botID); |
|
|
|
var bot = AppUsersManager.getUser(botID); |
|
|
|
sendText(-chatID, '/start@' + bot.username); |
|
|
|
sendText(peerID, '/start@' + bot.username); |
|
|
|
error.handled = true; |
|
|
|
error.handled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return sendText(botID, '/start'); |
|
|
|
return sendText(peerID, '/start'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function cancelPendingMessage (randomID) { |
|
|
|
function cancelPendingMessage (randomID) { |
|
|
@ -1777,7 +1884,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
if (toID < 0) { |
|
|
|
if (toID < 0) { |
|
|
|
return toID; |
|
|
|
return toID; |
|
|
|
} else if (message.out || message.flags & 2) { |
|
|
|
} else if (message.pFlags && message.pFlags.out || message.flags & 2) { |
|
|
|
return toID; |
|
|
|
return toID; |
|
|
|
} |
|
|
|
} |
|
|
|
return message.from_id; |
|
|
|
return message.from_id; |
|
|
@ -1796,7 +1903,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
if (!message || !message.to_id) { |
|
|
|
if (!message || !message.to_id) { |
|
|
|
if (dialog && dialog.peerID) { |
|
|
|
if (dialog && dialog.peerID) { |
|
|
|
message = {_: 'message', to_id: AppPeersManager.getOutputPeer(dialog.peerID), deleted: true, date: tsNow(true)}; |
|
|
|
message = {_: 'message', to_id: AppPeersManager.getOutputPeer(dialog.peerID), deleted: true, date: tsNow(true), pFlags: {}}; |
|
|
|
message.deleted = true; |
|
|
|
message.deleted = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return message; |
|
|
|
return message; |
|
|
@ -2316,7 +2423,7 @@ angular.module('myApp.services') |
|
|
|
MtpApiFileManager.downloadSmallFile(notificationPhoto.location, notificationPhoto.size).then(function (blob) { |
|
|
|
MtpApiFileManager.downloadSmallFile(notificationPhoto.location, notificationPhoto.size).then(function (blob) { |
|
|
|
notification.image = FileManager.getUrl(blob, 'image/jpeg'); |
|
|
|
notification.image = FileManager.getUrl(blob, 'image/jpeg'); |
|
|
|
|
|
|
|
|
|
|
|
if (message.unread) { |
|
|
|
if (message.pFlags.unread) { |
|
|
|
NotificationsManager.notify(notification); |
|
|
|
NotificationsManager.notify(notification); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -2379,11 +2486,11 @@ angular.module('myApp.services') |
|
|
|
notifyPeerToHandle.isMutedPromise.then(function (muted) { |
|
|
|
notifyPeerToHandle.isMutedPromise.then(function (muted) { |
|
|
|
var topMessage = notifyPeerToHandle.top_message; |
|
|
|
var topMessage = notifyPeerToHandle.top_message; |
|
|
|
if (muted || |
|
|
|
if (muted || |
|
|
|
!topMessage.unread) { |
|
|
|
!topMessage.pFlags.unread) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
setTimeout(function () { |
|
|
|
setTimeout(function () { |
|
|
|
if (topMessage.unread) { |
|
|
|
if (topMessage.pFlags.unread) { |
|
|
|
notifyAboutMessage(topMessage, { |
|
|
|
notifyAboutMessage(topMessage, { |
|
|
|
fwd_count: notifyPeerToHandle.fwd_count |
|
|
|
fwd_count: notifyPeerToHandle.fwd_count |
|
|
|
}); |
|
|
|
}); |
|
|
@ -2451,7 +2558,7 @@ angular.module('myApp.services') |
|
|
|
$rootScope.$broadcast('history_reply_markup', {peerID: peerID}) |
|
|
|
$rootScope.$broadcast('history_reply_markup', {peerID: peerID}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!message.out && message.from_id) { |
|
|
|
if (!message.pFlags.out && message.from_id) { |
|
|
|
AppUsersManager.forceUserOnline(message.from_id); |
|
|
|
AppUsersManager.forceUserOnline(message.from_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2477,7 +2584,7 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
var foundDialog = getDialogByPeerID(peerID); |
|
|
|
var foundDialog = getDialogByPeerID(peerID); |
|
|
|
var dialog; |
|
|
|
var dialog; |
|
|
|
var inboxUnread = !message.out && message.unread; |
|
|
|
var inboxUnread = !message.pFlags.out && message.pFlags.unread; |
|
|
|
|
|
|
|
|
|
|
|
if (foundDialog.length) { |
|
|
|
if (foundDialog.length) { |
|
|
|
dialog = foundDialog[0]; |
|
|
|
dialog = foundDialog[0]; |
|
|
@ -2555,25 +2662,25 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
message = messagesStorage[messageID]; |
|
|
|
|
|
|
|
|
|
|
|
if (message.out != isOut) { |
|
|
|
if (message.pFlags.out != isOut) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!message.unread) { |
|
|
|
if (!message.pFlags.unread) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log('read', messageID, message.unread, message);
|
|
|
|
// console.log('read', messageID, message.pFlags.unread, message);
|
|
|
|
if (message && message.unread) { |
|
|
|
if (message && message.pFlags.unread) { |
|
|
|
message.unread = false; |
|
|
|
message.pFlags.unread = false; |
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
if (messagesForHistory[messageID]) { |
|
|
|
messagesForHistory[messageID].unread = false; |
|
|
|
messagesForHistory[messageID].pFlags.unread = false; |
|
|
|
if (!foundAffected) { |
|
|
|
if (!foundAffected) { |
|
|
|
foundAffected = true; |
|
|
|
foundAffected = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
if (messagesForDialogs[messageID]) { |
|
|
|
messagesForDialogs[messageID].unread = false; |
|
|
|
messagesForDialogs[messageID].pFlags.unread = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!message.out) { |
|
|
|
if (!message.pFlags.out) { |
|
|
|
if (foundDialog) { |
|
|
|
if (foundDialog) { |
|
|
|
newUnreadCount = --foundDialog[0].unread_count; |
|
|
|
newUnreadCount = --foundDialog[0].unread_count; |
|
|
|
} |
|
|
|
} |
|
|
@ -2597,10 +2704,10 @@ angular.module('myApp.services') |
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
for (i = 0; i < len; i++) { |
|
|
|
messageID = messages[i]; |
|
|
|
messageID = messages[i]; |
|
|
|
if (message = messagesStorage[messageID]) { |
|
|
|
if (message = messagesStorage[messageID]) { |
|
|
|
delete message.media_unread; |
|
|
|
delete message.pFlags.media_unread; |
|
|
|
} |
|
|
|
} |
|
|
|
if (historyMessage = messagesForHistory[messageID]) { |
|
|
|
if (historyMessage = messagesForHistory[messageID]) { |
|
|
|
delete historyMessage.media_unread; |
|
|
|
delete historyMessage.pFlags.media_unread; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -2619,8 +2726,8 @@ angular.module('myApp.services') |
|
|
|
peerID = getMessagePeer(message); |
|
|
|
peerID = getMessagePeer(message); |
|
|
|
history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}}); |
|
|
|
history = historiesUpdated[peerID] || (historiesUpdated[peerID] = {count: 0, unread: 0, msgs: {}}); |
|
|
|
|
|
|
|
|
|
|
|
if (!message.out && message.unread) { |
|
|
|
if (!message.pFlags.out && message.pFlags.unread) { |
|
|
|
history.unread++; |
|
|
|
history.pFlags.unread++; |
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
NotificationsManager.cancel('msg' + messageID); |
|
|
|
} |
|
|
|
} |
|
|
|
history.count++; |
|
|
|
history.count++; |
|
|
@ -2641,8 +2748,7 @@ angular.module('myApp.services') |
|
|
|
from_id: message.from_id, |
|
|
|
from_id: message.from_id, |
|
|
|
to_id: message.to_id, |
|
|
|
to_id: message.to_id, |
|
|
|
flags: message.flags, |
|
|
|
flags: message.flags, |
|
|
|
out: message.out, |
|
|
|
pFlags: message.pFlags, |
|
|
|
unread: message.unread, |
|
|
|
|
|
|
|
date: message.date |
|
|
|
date: message.date |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
@ -2651,8 +2757,8 @@ angular.module('myApp.services') |
|
|
|
angular.forEach(historiesUpdated, function (updatedData, peerID) { |
|
|
|
angular.forEach(historiesUpdated, function (updatedData, peerID) { |
|
|
|
var foundDialog = getDialogByPeerID(peerID); |
|
|
|
var foundDialog = getDialogByPeerID(peerID); |
|
|
|
if (foundDialog) { |
|
|
|
if (foundDialog) { |
|
|
|
if (updatedData.unread) { |
|
|
|
if (updatedData.pFlags.unread) { |
|
|
|
foundDialog[0].unread_count -= updatedData.unread; |
|
|
|
foundDialog[0].unread_count -= updatedData.pFlags.unread; |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: foundDialog[0].unread_count}); |
|
|
|
$rootScope.$broadcast('dialog_unread', {peerID: peerID, count: foundDialog[0].unread_count}); |
|
|
|
} |
|
|
|
} |
|
|
@ -2747,10 +2853,9 @@ angular.module('myApp.services') |
|
|
|
|
|
|
|
|
|
|
|
function reloadChannelDialog (channelID) { |
|
|
|
function reloadChannelDialog (channelID) { |
|
|
|
var peerID = -channelID; |
|
|
|
var peerID = -channelID; |
|
|
|
var inputPeer = AppPeersManager.getInputPeerByID(peerID); |
|
|
|
|
|
|
|
return $q.all([ |
|
|
|
return $q.all([ |
|
|
|
AppProfileManager.getChannelFull(channelID, true), |
|
|
|
AppProfileManager.getChannelFull(channelID, true), |
|
|
|
getHistory(inputPeer, 0) |
|
|
|
getHistory(peerID, 0) |
|
|
|
]).then(function (results) { |
|
|
|
]).then(function (results) { |
|
|
|
var channelResult = results[0]; |
|
|
|
var channelResult = results[0]; |
|
|
|
var historyResult = results[1]; |
|
|
|
var historyResult = results[1]; |
|
|
|