|
|
@ -17,7 +17,7 @@ import { createPosterForVideo } from "../../helpers/files"; |
|
|
|
import { copy, getObjectKeysAndSort } from "../../helpers/object"; |
|
|
|
import { copy, getObjectKeysAndSort } from "../../helpers/object"; |
|
|
|
import { randomLong } from "../../helpers/random"; |
|
|
|
import { randomLong } from "../../helpers/random"; |
|
|
|
import { splitStringByLength, limitSymbols, escapeRegExp } from "../../helpers/string"; |
|
|
|
import { splitStringByLength, limitSymbols, escapeRegExp } from "../../helpers/string"; |
|
|
|
import { Chat, ChatFull, Dialog as MTDialog, DialogPeer, DocumentAttribute, InputMedia, InputMessage, InputPeerNotifySettings, InputSingleMedia, Message, MessageAction, MessageEntity, MessageFwdHeader, MessageMedia, MessageReplies, MessageReplyHeader, MessagesDialogs, MessagesFilter, MessagesMessages, MethodDeclMap, NotifyPeer, PeerNotifySettings, PhotoSize, SendMessageAction, Update, Photo, Updates, ReplyMarkup } from "../../layer"; |
|
|
|
import { Chat, ChatFull, Dialog as MTDialog, DialogPeer, DocumentAttribute, InputMedia, InputMessage, InputPeerNotifySettings, InputSingleMedia, Message, MessageAction, MessageEntity, MessageFwdHeader, MessageMedia, MessageReplies, MessageReplyHeader, MessagesDialogs, MessagesFilter, MessagesMessages, MethodDeclMap, NotifyPeer, PeerNotifySettings, PhotoSize, SendMessageAction, Update, Photo, Updates, ReplyMarkup, InputPeer } from "../../layer"; |
|
|
|
import { InvokeApiOptions } from "../../types"; |
|
|
|
import { InvokeApiOptions } from "../../types"; |
|
|
|
import I18n, { i18n, join, langPack, LangPackKey, _i18n } from "../langPack"; |
|
|
|
import I18n, { i18n, join, langPack, LangPackKey, _i18n } from "../langPack"; |
|
|
|
import { logger, LogTypes } from "../logger"; |
|
|
|
import { logger, LogTypes } from "../logger"; |
|
|
@ -1562,12 +1562,11 @@ export class AppMessagesManager { |
|
|
|
const {peerId, tempId, storage} = pendingData; |
|
|
|
const {peerId, tempId, storage} = pendingData; |
|
|
|
const historyStorage = this.getHistoryStorage(peerId); |
|
|
|
const historyStorage = this.getHistoryStorage(peerId); |
|
|
|
|
|
|
|
|
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
update: { |
|
|
|
messages: [tempId], |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
pts: undefined, |
|
|
|
messages: [tempId] |
|
|
|
pts_count: undefined |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
historyStorage.history.delete(tempId); |
|
|
|
historyStorage.history.delete(tempId); |
|
|
@ -1983,11 +1982,11 @@ export class AppMessagesManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private doFlushHistory(inputPeer: any, justClear?: boolean, revoke?: boolean): Promise<true> { |
|
|
|
private doFlushHistory(peer: InputPeer, just_clear?: boolean, revoke?: boolean): Promise<true> { |
|
|
|
return apiManager.invokeApiSingle('messages.deleteHistory', { |
|
|
|
return apiManager.invokeApiSingle('messages.deleteHistory', { |
|
|
|
just_clear: justClear, |
|
|
|
just_clear, |
|
|
|
revoke: revoke, |
|
|
|
revoke, |
|
|
|
peer: inputPeer, |
|
|
|
peer, |
|
|
|
max_id: 0 |
|
|
|
max_id: 0 |
|
|
|
}).then((affectedHistory) => { |
|
|
|
}).then((affectedHistory) => { |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
@ -2003,7 +2002,7 @@ export class AppMessagesManager { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.doFlushHistory(inputPeer, justClear); |
|
|
|
return this.doFlushHistory(peer, just_clear); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2019,13 +2018,10 @@ export class AppMessagesManager { |
|
|
|
channel: appChatsManager.getChannelInput(channelId), |
|
|
|
channel: appChatsManager.getChannelInput(channelId), |
|
|
|
max_id: maxId |
|
|
|
max_id: maxId |
|
|
|
}).then(() => { |
|
|
|
}).then(() => { |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateChannelAvailableMessages', |
|
|
|
update: { |
|
|
|
channel_id: channelId, |
|
|
|
_: 'updateChannelAvailableMessages', |
|
|
|
available_min_id: maxId |
|
|
|
channel_id: channelId, |
|
|
|
|
|
|
|
available_min_id: maxId |
|
|
|
|
|
|
|
} as Update.updateChannelAvailableMessages |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -2277,7 +2273,7 @@ export class AppMessagesManager { |
|
|
|
if(message.replies.read_max_id) message.replies.read_max_id = this.generateMessageId(message.replies.read_max_id); |
|
|
|
if(message.replies.read_max_id) message.replies.read_max_id = this.generateMessageId(message.replies.read_max_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const overwriting = !!message.peerId; |
|
|
|
const overwriting = !!peerId; |
|
|
|
if(!overwriting) { |
|
|
|
if(!overwriting) { |
|
|
|
message.date -= serverTimeManager.serverTimeOffset; |
|
|
|
message.date -= serverTimeManager.serverTimeOffset; |
|
|
|
} |
|
|
|
} |
|
|
@ -2286,7 +2282,7 @@ export class AppMessagesManager { |
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
|
|
|
|
|
|
|
|
message.peerId = peerId; |
|
|
|
message.peerId = peerId; |
|
|
|
if(message.peerId === myId/* && !message.from_id && !message.fwd_from */) { |
|
|
|
if(peerId === myId/* && !message.from_id && !message.fwd_from */) { |
|
|
|
message.fromId = message.fwd_from ? (message.fwd_from.from_id ? appPeersManager.getPeerId(message.fwd_from.from_id) : 0) : myId; |
|
|
|
message.fromId = message.fwd_from ? (message.fwd_from.from_id ? appPeersManager.getPeerId(message.fwd_from.from_id) : 0) : myId; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//message.fromId = message.pFlags.post || (!message.pFlags.out && !message.from_id) ? peerId : appPeersManager.getPeerId(message.from_id);
|
|
|
|
//message.fromId = message.pFlags.post || (!message.pFlags.out && !message.from_id) ? peerId : appPeersManager.getPeerId(message.from_id);
|
|
|
@ -2396,7 +2392,7 @@ export class AppMessagesManager { |
|
|
|
let type: string; |
|
|
|
let type: string; |
|
|
|
if(action.duration === undefined) { |
|
|
|
if(action.duration === undefined) { |
|
|
|
type = 'started'; |
|
|
|
type = 'started'; |
|
|
|
if(message.peerId !== message.fromId) { |
|
|
|
if(peerId !== message.fromId) { |
|
|
|
type += '_by' + suffix; |
|
|
|
type += '_by' + suffix; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -3553,15 +3549,12 @@ export class AppMessagesManager { |
|
|
|
channel: appChatsManager.getChannelInput(channelId), |
|
|
|
channel: appChatsManager.getChannelInput(channelId), |
|
|
|
id: localMessageIds |
|
|
|
id: localMessageIds |
|
|
|
}).then((affectedMessages) => { |
|
|
|
}).then((affectedMessages) => { |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateDeleteChannelMessages', |
|
|
|
update: { |
|
|
|
channel_id: channelId, |
|
|
|
_: 'updateDeleteChannelMessages', |
|
|
|
messages: mids, |
|
|
|
channel_id: channelId, |
|
|
|
pts: affectedMessages.pts, |
|
|
|
messages: mids, |
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
pts: affectedMessages.pts, |
|
|
|
|
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -3569,14 +3562,11 @@ export class AppMessagesManager { |
|
|
|
revoke, |
|
|
|
revoke, |
|
|
|
id: localMessageIds |
|
|
|
id: localMessageIds |
|
|
|
}).then((affectedMessages) => { |
|
|
|
}).then((affectedMessages) => { |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
update: { |
|
|
|
messages: mids, |
|
|
|
_: 'updateDeleteMessages', |
|
|
|
pts: affectedMessages.pts, |
|
|
|
messages: mids, |
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
pts: affectedMessages.pts, |
|
|
|
|
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -3610,14 +3600,11 @@ export class AppMessagesManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateReadChannelDiscussionInbox', |
|
|
|
update: { |
|
|
|
channel_id: -peerId, |
|
|
|
_: 'updateReadChannelDiscussionInbox', |
|
|
|
top_msg_id: threadId, |
|
|
|
channel_id: -peerId, |
|
|
|
read_max_id: maxId |
|
|
|
top_msg_id: threadId, |
|
|
|
|
|
|
|
read_max_id: maxId |
|
|
|
|
|
|
|
} as Update.updateReadChannelDiscussionInbox |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} else if(appPeersManager.isChannel(peerId)) { |
|
|
|
} else if(appPeersManager.isChannel(peerId)) { |
|
|
|
if(!historyStorage.readPromise) { |
|
|
|
if(!historyStorage.readPromise) { |
|
|
@ -3627,13 +3614,12 @@ export class AppMessagesManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateReadChannelInbox', |
|
|
|
update: { |
|
|
|
max_id: maxId, |
|
|
|
_: 'updateReadChannelInbox', |
|
|
|
channel_id: -peerId, |
|
|
|
max_id: maxId, |
|
|
|
still_unread_count: undefined, |
|
|
|
channel_id: -peerId |
|
|
|
pts: undefined |
|
|
|
} as Update.updateReadChannelInbox |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if(!historyStorage.readPromise) { |
|
|
|
if(!historyStorage.readPromise) { |
|
|
@ -3652,13 +3638,13 @@ export class AppMessagesManager { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateReadHistoryInbox', |
|
|
|
update: { |
|
|
|
max_id: maxId, |
|
|
|
_: 'updateReadHistoryInbox', |
|
|
|
peer: appPeersManager.getOutputPeer(peerId), |
|
|
|
max_id: maxId, |
|
|
|
still_unread_count: undefined, |
|
|
|
peer: appPeersManager.getOutputPeer(peerId) |
|
|
|
pts: undefined, |
|
|
|
} as Update.updateReadHistoryInbox |
|
|
|
pts_count: undefined |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3698,27 +3684,21 @@ export class AppMessagesManager { |
|
|
|
channel: appChatsManager.getChannelInput(channelId), |
|
|
|
channel: appChatsManager.getChannelInput(channelId), |
|
|
|
id: msgIds |
|
|
|
id: msgIds |
|
|
|
}).then(() => { |
|
|
|
}).then(() => { |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateChannelReadMessagesContents', |
|
|
|
update: { |
|
|
|
channel_id: channelId, |
|
|
|
_: 'updateChannelReadMessagesContents', |
|
|
|
messages: msgIds |
|
|
|
channel_id: channelId, |
|
|
|
|
|
|
|
messages: msgIds |
|
|
|
|
|
|
|
} as Update.updateChannelReadMessagesContents |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
apiManager.invokeApi('messages.readMessageContents', { |
|
|
|
apiManager.invokeApi('messages.readMessageContents', { |
|
|
|
id: msgIds |
|
|
|
id: msgIds |
|
|
|
}).then((affectedMessages) => { |
|
|
|
}).then((affectedMessages) => { |
|
|
|
apiUpdatesManager.processUpdateMessage({ |
|
|
|
apiUpdatesManager.processLocalUpdate({ |
|
|
|
_: 'updateShort', |
|
|
|
_: 'updateReadMessagesContents', |
|
|
|
update: { |
|
|
|
messages: msgIds, |
|
|
|
_: 'updateReadMessagesContents', |
|
|
|
pts: affectedMessages.pts, |
|
|
|
messages: msgIds, |
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
pts: affectedMessages.pts, |
|
|
|
|
|
|
|
pts_count: affectedMessages.pts_count |
|
|
|
|
|
|
|
} as Update.updateReadMessagesContents |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -3887,8 +3867,39 @@ export class AppMessagesManager { |
|
|
|
rootScope.dispatchEvent('history_reply_markup', {peerId}); |
|
|
|
rootScope.dispatchEvent('history_reply_markup', {peerId}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.fromId > 0 && !message.pFlags.out && message.from_id) { |
|
|
|
const fromId = message.fromId; |
|
|
|
appUsersManager.forceUserOnline(message.fromId, message.date); |
|
|
|
if(fromId > 0 && !message.pFlags.out && message.from_id) { |
|
|
|
|
|
|
|
appUsersManager.forceUserOnline(fromId, message.date); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const action: SendMessageAction = { |
|
|
|
|
|
|
|
_: 'sendMessageCancelAction' |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let update: Update.updateUserTyping | Update.updateChatUserTyping | Update.updateChannelUserTyping; |
|
|
|
|
|
|
|
if(peerId > 0) { |
|
|
|
|
|
|
|
update = { |
|
|
|
|
|
|
|
_: 'updateUserTyping', |
|
|
|
|
|
|
|
action, |
|
|
|
|
|
|
|
user_id: fromId |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} else if(appPeersManager.isChannel(peerId)) { |
|
|
|
|
|
|
|
update = { |
|
|
|
|
|
|
|
_: 'updateChannelUserTyping', |
|
|
|
|
|
|
|
action, |
|
|
|
|
|
|
|
channel_id: -peerId, |
|
|
|
|
|
|
|
from_id: appPeersManager.getOutputPeer(fromId), |
|
|
|
|
|
|
|
top_msg_id: threadId ? this.getServerMessageId(threadId) : undefined |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
update = { |
|
|
|
|
|
|
|
_: 'updateChatUserTyping', |
|
|
|
|
|
|
|
action, |
|
|
|
|
|
|
|
chat_id: -peerId, |
|
|
|
|
|
|
|
from_id: appPeersManager.getOutputPeer(fromId) |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apiUpdatesManager.processLocalUpdate(update); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!pendingMessage) { |
|
|
|
if(!pendingMessage) { |
|
|
@ -3908,7 +3919,7 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(inboxUnread/* && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) */) { |
|
|
|
if(inboxUnread/* && ($rootScope.selectedPeerID != peerID || $rootScope.idle.isIDLE) */) { |
|
|
|
const notifyPeer = message.peerId; |
|
|
|
const notifyPeer = peerId; |
|
|
|
let notifyPeerToHandle = this.notificationsToHandle[notifyPeer]; |
|
|
|
let notifyPeerToHandle = this.notificationsToHandle[notifyPeer]; |
|
|
|
if(notifyPeerToHandle === undefined) { |
|
|
|
if(notifyPeerToHandle === undefined) { |
|
|
|
notifyPeerToHandle = this.notificationsToHandle[notifyPeer] = { |
|
|
|
notifyPeerToHandle = this.notificationsToHandle[notifyPeer] = { |
|
|
@ -3917,8 +3928,8 @@ export class AppMessagesManager { |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(notifyPeerToHandle.fromId !== message.fromId) { |
|
|
|
if(notifyPeerToHandle.fromId !== fromId) { |
|
|
|
notifyPeerToHandle.fromId = message.fromId; |
|
|
|
notifyPeerToHandle.fromId = fromId; |
|
|
|
notifyPeerToHandle.fwdCount = 0; |
|
|
|
notifyPeerToHandle.fwdCount = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|