|
|
@ -168,7 +168,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) { |
|
|
@ -259,7 +259,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); |
|
|
@ -364,6 +364,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', |
|
|
@ -499,7 +500,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; |
|
|
|
} |
|
|
|
} |
|
|
@ -641,7 +642,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 +658,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 +672,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) { |
|
|
@ -786,8 +787,13 @@ angular.module('myApp.services') |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var flags = 0; |
|
|
|
|
|
|
|
if (AppPeersManager.isChannel(peerID)) { |
|
|
|
|
|
|
|
flags |= 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return MtpApiManager.invokeApi('messages.search', { |
|
|
|
return MtpApiManager.invokeApi('messages.search', { |
|
|
|
flags: 0, |
|
|
|
flags: flags, |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
q: query || '', |
|
|
|
q: query || '', |
|
|
|
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, |
|
|
|
filter: inputFilter || {_: 'inputMessagesFilterEmpty'}, |
|
|
@ -842,7 +848,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,28 +894,6 @@ angular.module('myApp.services') |
|
|
|
return $q.all(promises); |
|
|
|
return $q.all(promises); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function processAffectedHistory (inputPeer, affectedHistory, method) { |
|
|
|
|
|
|
|
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) { |
|
|
|
function readHistory (inputPeer) { |
|
|
|
// console.trace('start read');
|
|
|
|
// console.trace('start read');
|
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer), |
|
|
@ -929,7 +913,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; |
|
|
|
} |
|
|
|
} |
|
|
@ -952,10 +936,7 @@ angular.module('myApp.services') |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
apiPromise = MtpApiManager.invokeApi('messages.readHistory', { |
|
|
|
apiPromise = MtpApiManager.invokeApi('messages.readHistory', { |
|
|
|
peer: inputPeer, |
|
|
|
peer: inputPeer, |
|
|
|
offset: 0, |
|
|
|
|
|
|
|
max_id: 0 |
|
|
|
max_id: 0 |
|
|
|
}).then(function (affectedHistory) { |
|
|
|
|
|
|
|
return processAffectedHistory(inputPeer, affectedHistory, 'messages.readHistory'); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -978,13 +959,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 +993,29 @@ 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 (inputPeer) { |
|
|
|
|
|
|
|
var peerID = AppPeersManager.getPeerID(inputPeer); |
|
|
|
|
|
|
|
return doFlushHistory(inputPeer).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,11 +1027,18 @@ 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'; |
|
|
@ -1048,11 +1048,11 @@ angular.module('myApp.services') |
|
|
|
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) { |
|
|
@ -1112,13 +1112,6 @@ angular.module('myApp.services') |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (apiMessage.reply_markup) { |
|
|
|
|
|
|
|
apiMessage.reply_markup.pFlags = { |
|
|
|
|
|
|
|
resize: (apiMessage.reply_markup.flags & 1) > 0, |
|
|
|
|
|
|
|
one_time: (apiMessage.reply_markup.flags & 2) > 0, |
|
|
|
|
|
|
|
selective: (apiMessage.reply_markup.flags & 4) > 0 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (apiMessage.message && apiMessage.message.length) { |
|
|
|
if (apiMessage.message && apiMessage.message.length) { |
|
|
|
var myEntities = RichTextProcessor.parseEntities(apiMessage.message); |
|
|
|
var myEntities = RichTextProcessor.parseEntities(apiMessage.message); |
|
|
@ -1139,6 +1132,7 @@ angular.module('myApp.services') |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
inputPeer = AppPeersManager.getInputPeerByID(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, |
|
|
|
asChannel = isChannel ? true : false, |
|
|
@ -1154,8 +1148,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 +1168,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, |
|
|
@ -1276,6 +1273,7 @@ angular.module('myApp.services') |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
historyStorage = historiesStorage[peerID], |
|
|
|
inputPeer = AppPeersManager.getInputPeerByID(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, |
|
|
|
asChannel = isChannel ? true : false, |
|
|
@ -1305,8 +1303,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 +1331,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, |
|
|
@ -1494,10 +1495,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 +1519,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, |
|
|
@ -1621,36 +1626,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 +1783,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 +1802,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 +2322,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 +2385,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 +2457,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 +2483,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 +2561,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 +2603,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 +2625,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 +2647,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 +2656,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}); |
|
|
|
} |
|
|
|
} |
|
|
|