|
|
@ -19,7 +19,7 @@ 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, InputPeer, InputPhoto, InputDocument, InputGeoPoint, WebPage, GeoPoint, ReportReason, MessagesGetDialogs, InputChannel, InputDialogPeer } 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, InputPhoto, InputDocument, InputGeoPoint, WebPage, GeoPoint, ReportReason, MessagesGetDialogs, InputChannel, InputDialogPeer } from "../../layer"; |
|
|
|
import { InvokeApiOptions } from "../../types"; |
|
|
|
import { InvokeApiOptions } from "../../types"; |
|
|
|
import I18n, { i18n, join, langPack, LangPackKey, _i18n } from "../langPack"; |
|
|
|
import I18n, { FormatterArguments, i18n, join, langPack, LangPackKey, _i18n } from "../langPack"; |
|
|
|
import { logger, LogTypes } from "../logger"; |
|
|
|
import { logger, LogTypes } from "../logger"; |
|
|
|
import type { ApiFileManager } from '../mtproto/apiFileManager'; |
|
|
|
import type { ApiFileManager } from '../mtproto/apiFileManager'; |
|
|
|
//import apiManager from '../mtproto/apiManager';
|
|
|
|
//import apiManager from '../mtproto/apiManager';
|
|
|
@ -41,7 +41,7 @@ import appPollsManager from "./appPollsManager"; |
|
|
|
import appStateManager from "./appStateManager"; |
|
|
|
import appStateManager from "./appStateManager"; |
|
|
|
import appUsersManager from "./appUsersManager"; |
|
|
|
import appUsersManager from "./appUsersManager"; |
|
|
|
import appWebPagesManager from "./appWebPagesManager"; |
|
|
|
import appWebPagesManager from "./appWebPagesManager"; |
|
|
|
import appDraftsManager from "./appDraftsManager"; |
|
|
|
import appDraftsManager, { MyDraftMessage } from "./appDraftsManager"; |
|
|
|
import { getFileNameByLocation } from "../../helpers/fileName"; |
|
|
|
import { getFileNameByLocation } from "../../helpers/fileName"; |
|
|
|
import appProfileManager from "./appProfileManager"; |
|
|
|
import appProfileManager from "./appProfileManager"; |
|
|
|
import DEBUG, { MOUNT_CLASS_TO } from "../../config/debug"; |
|
|
|
import DEBUG, { MOUNT_CLASS_TO } from "../../config/debug"; |
|
|
@ -2332,330 +2332,342 @@ export class AppMessagesManager { |
|
|
|
return appMessagesIdsManager.generateMessageId(dialog?.top_message || 0, true); |
|
|
|
return appMessagesIdsManager.generateMessageId(dialog?.top_message || 0, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public saveMessages(messages: any[], options: Partial<{ |
|
|
|
public saveMessage(message: any, options: Partial<{ |
|
|
|
storage: MessagesStorage, |
|
|
|
storage: MessagesStorage, |
|
|
|
isScheduled: true, |
|
|
|
isScheduled: true, |
|
|
|
isOutgoing: true, |
|
|
|
isOutgoing: true, |
|
|
|
//isNew: boolean, // * new - from update
|
|
|
|
//isNew: boolean, // * new - from update
|
|
|
|
}> = {}) { |
|
|
|
}> = {}) { |
|
|
|
//let groups: Set<string>;
|
|
|
|
if(message.pFlags === undefined) { |
|
|
|
messages.forEach((message) => { |
|
|
|
message.pFlags = {}; |
|
|
|
if(message.pFlags === undefined) { |
|
|
|
} |
|
|
|
message.pFlags = {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(message._ === 'messageEmpty') { |
|
|
|
if(message._ === 'messageEmpty') { |
|
|
|
message.deleted = true; |
|
|
|
message.deleted = true; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// * exclude from state
|
|
|
|
// * exclude from state
|
|
|
|
// defineNotNumerableProperties(message, ['rReply', 'mid', 'savedFrom', 'fwdFromId', 'fromId', 'peerId', 'reply_to_mid', 'viaBotId']);
|
|
|
|
// defineNotNumerableProperties(message, ['rReply', 'mid', 'savedFrom', 'fwdFromId', 'fromId', 'peerId', 'reply_to_mid', 'viaBotId']);
|
|
|
|
|
|
|
|
|
|
|
|
const peerId = this.getMessagePeer(message); |
|
|
|
const peerId = this.getMessagePeer(message); |
|
|
|
const storage = options.storage || this.getMessagesStorage(peerId); |
|
|
|
const storage = options.storage || this.getMessagesStorage(peerId); |
|
|
|
const isChannel = message.peer_id._ === 'peerChannel'; |
|
|
|
const isChannel = message.peer_id._ === 'peerChannel'; |
|
|
|
const isBroadcast = isChannel && appChatsManager.isBroadcast(peerId.toChatId()); |
|
|
|
const isBroadcast = isChannel && appChatsManager.isBroadcast(peerId.toChatId()); |
|
|
|
|
|
|
|
|
|
|
|
if(options.isScheduled) { |
|
|
|
if(options.isScheduled) { |
|
|
|
message.pFlags.is_scheduled = true; |
|
|
|
message.pFlags.is_scheduled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(options.isOutgoing) { |
|
|
|
if(options.isOutgoing) { |
|
|
|
message.pFlags.is_outgoing = true; |
|
|
|
message.pFlags.is_outgoing = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const mid = appMessagesIdsManager.generateMessageId(message.id); |
|
|
|
const mid = appMessagesIdsManager.generateMessageId(message.id); |
|
|
|
message.mid = mid; |
|
|
|
message.mid = mid; |
|
|
|
|
|
|
|
|
|
|
|
if(message.grouped_id) { |
|
|
|
if(message.grouped_id) { |
|
|
|
const storage = this.groupedMessagesStorage[message.grouped_id] ?? (this.groupedMessagesStorage[message.grouped_id] = new Map()); |
|
|
|
const storage = this.groupedMessagesStorage[message.grouped_id] ?? (this.groupedMessagesStorage[message.grouped_id] = new Map()); |
|
|
|
storage.set(mid, message); |
|
|
|
storage.set(mid, message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const dialog = this.getDialogOnly(peerId); |
|
|
|
const dialog = this.getDialogOnly(peerId); |
|
|
|
if(dialog && mid) { |
|
|
|
if(dialog && mid) { |
|
|
|
if(mid > dialog[message.pFlags.out |
|
|
|
if(mid > dialog[message.pFlags.out |
|
|
|
? 'read_outbox_max_id' |
|
|
|
? 'read_outbox_max_id' |
|
|
|
: 'read_inbox_max_id']) { |
|
|
|
: 'read_inbox_max_id']) { |
|
|
|
message.pFlags.unread = true; |
|
|
|
message.pFlags.unread = true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// this.log(dT(), 'msg unread', mid, apiMessage.pFlags.out, dialog && dialog[apiMessage.pFlags.out ? 'read_outbox_max_id' : 'read_inbox_max_id'])
|
|
|
|
} |
|
|
|
|
|
|
|
// this.log(dT(), 'msg unread', mid, apiMessage.pFlags.out, dialog && dialog[apiMessage.pFlags.out ? 'read_outbox_max_id' : 'read_inbox_max_id'])
|
|
|
|
|
|
|
|
|
|
|
|
if(message.reply_to) { |
|
|
|
if(message.reply_to) { |
|
|
|
if(message.reply_to.reply_to_msg_id) { |
|
|
|
if(message.reply_to.reply_to_msg_id) { |
|
|
|
message.reply_to.reply_to_msg_id = message.reply_to_mid = appMessagesIdsManager.generateMessageId(message.reply_to.reply_to_msg_id); |
|
|
|
message.reply_to.reply_to_msg_id = message.reply_to_mid = appMessagesIdsManager.generateMessageId(message.reply_to.reply_to_msg_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.reply_to.reply_to_top_id) message.reply_to.reply_to_top_id = appMessagesIdsManager.generateMessageId(message.reply_to.reply_to_top_id); |
|
|
|
if(message.reply_to.reply_to_top_id) message.reply_to.reply_to_top_id = appMessagesIdsManager.generateMessageId(message.reply_to.reply_to_top_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.replies) { |
|
|
|
if(message.replies) { |
|
|
|
if(message.replies.max_id) message.replies.max_id = appMessagesIdsManager.generateMessageId(message.replies.max_id); |
|
|
|
if(message.replies.max_id) message.replies.max_id = appMessagesIdsManager.generateMessageId(message.replies.max_id); |
|
|
|
if(message.replies.read_max_id) message.replies.read_max_id = appMessagesIdsManager.generateMessageId(message.replies.read_max_id); |
|
|
|
if(message.replies.read_max_id) message.replies.read_max_id = appMessagesIdsManager.generateMessageId(message.replies.read_max_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const overwriting = !!peerId; |
|
|
|
const overwriting = !!peerId; |
|
|
|
if(!overwriting) { |
|
|
|
if(!overwriting) { |
|
|
|
message.date -= serverTimeManager.serverTimeOffset; |
|
|
|
message.date -= serverTimeManager.serverTimeOffset; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//storage.generateIndex(message);
|
|
|
|
//storage.generateIndex(message);
|
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
|
|
|
|
|
|
|
|
message.peerId = peerId; |
|
|
|
message.peerId = peerId; |
|
|
|
if(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);
|
|
|
|
message.fromId = message.pFlags.post || !message.from_id ? peerId : appPeersManager.getPeerId(message.from_id); |
|
|
|
message.fromId = message.pFlags.post || !message.from_id ? peerId : appPeersManager.getPeerId(message.from_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const fwdHeader = message.fwd_from as MessageFwdHeader; |
|
|
|
const fwdHeader = message.fwd_from as MessageFwdHeader; |
|
|
|
if(fwdHeader) { |
|
|
|
if(fwdHeader) { |
|
|
|
//if(peerId === myID) {
|
|
|
|
//if(peerId === myID) {
|
|
|
|
if(fwdHeader.saved_from_msg_id) fwdHeader.saved_from_msg_id = appMessagesIdsManager.generateMessageId(fwdHeader.saved_from_msg_id); |
|
|
|
if(fwdHeader.saved_from_msg_id) fwdHeader.saved_from_msg_id = appMessagesIdsManager.generateMessageId(fwdHeader.saved_from_msg_id); |
|
|
|
if(fwdHeader.channel_post) fwdHeader.channel_post = appMessagesIdsManager.generateMessageId(fwdHeader.channel_post); |
|
|
|
if(fwdHeader.channel_post) fwdHeader.channel_post = appMessagesIdsManager.generateMessageId(fwdHeader.channel_post); |
|
|
|
|
|
|
|
|
|
|
|
const peer = fwdHeader.saved_from_peer || fwdHeader.from_id; |
|
|
|
const peer = fwdHeader.saved_from_peer || fwdHeader.from_id; |
|
|
|
const msgId = fwdHeader.saved_from_msg_id || fwdHeader.channel_post; |
|
|
|
const msgId = fwdHeader.saved_from_msg_id || fwdHeader.channel_post; |
|
|
|
if(peer && msgId) { |
|
|
|
if(peer && msgId) { |
|
|
|
const savedFromPeerId = appPeersManager.getPeerId(peer); |
|
|
|
const savedFromPeerId = appPeersManager.getPeerId(peer); |
|
|
|
const savedFromMid = appMessagesIdsManager.generateMessageId(msgId); |
|
|
|
const savedFromMid = appMessagesIdsManager.generateMessageId(msgId); |
|
|
|
message.savedFrom = savedFromPeerId + '_' + savedFromMid; |
|
|
|
message.savedFrom = savedFromPeerId + '_' + savedFromMid; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* if(peerId.isAnyChat() || peerId === myID) { |
|
|
|
/* if(peerId.isAnyChat() || peerId === myID) { |
|
|
|
message.fromId = appPeersManager.getPeerID(!message.from_id || deepEqual(message.from_id, fwdHeader.from_id) ? fwdHeader.from_id : message.from_id); |
|
|
|
message.fromId = appPeersManager.getPeerID(!message.from_id || deepEqual(message.from_id, fwdHeader.from_id) ? fwdHeader.from_id : message.from_id); |
|
|
|
} */ |
|
|
|
|
|
|
|
/* } else { |
|
|
|
|
|
|
|
apiMessage.fwdPostID = fwdHeader.channel_post; |
|
|
|
|
|
|
|
} */ |
|
|
|
} */ |
|
|
|
|
|
|
|
/* } else { |
|
|
|
|
|
|
|
apiMessage.fwdPostID = fwdHeader.channel_post; |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
message.fwdFromId = appPeersManager.getPeerId(fwdHeader.from_id); |
|
|
|
message.fwdFromId = appPeersManager.getPeerId(fwdHeader.from_id); |
|
|
|
|
|
|
|
|
|
|
|
if(!overwriting) { |
|
|
|
if(!overwriting) { |
|
|
|
fwdHeader.date -= serverTimeManager.serverTimeOffset; |
|
|
|
fwdHeader.date -= serverTimeManager.serverTimeOffset; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.via_bot_id > 0) { |
|
|
|
if(message.via_bot_id > 0) { |
|
|
|
message.viaBotId = message.via_bot_id; |
|
|
|
message.viaBotId = message.via_bot_id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const mediaContext: ReferenceContext = { |
|
|
|
const mediaContext: ReferenceContext = { |
|
|
|
type: 'message', |
|
|
|
type: 'message', |
|
|
|
peerId, |
|
|
|
peerId, |
|
|
|
messageId: mid |
|
|
|
messageId: mid |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if(message.media) { |
|
|
|
if(message.media) { |
|
|
|
switch(message.media._) { |
|
|
|
switch(message.media._) { |
|
|
|
case 'messageMediaEmpty': |
|
|
|
case 'messageMediaEmpty': { |
|
|
|
delete message.media; |
|
|
|
delete message.media; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'messageMediaPhoto': |
|
|
|
} |
|
|
|
if(message.media.ttl_seconds) { |
|
|
|
|
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
message.media.photo = appPhotosManager.savePhoto(message.media.photo, mediaContext); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!message.media.photo) { // * found this bug on test DC
|
|
|
|
case 'messageMediaPhoto': { |
|
|
|
delete message.media; |
|
|
|
if(message.media.ttl_seconds) { |
|
|
|
} |
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
|
|
|
} else { |
|
|
|
break; |
|
|
|
message.media.photo = appPhotosManager.savePhoto(message.media.photo, mediaContext); |
|
|
|
case 'messageMediaPoll': |
|
|
|
} |
|
|
|
const result = appPollsManager.savePoll(message.media.poll, message.media.results, message); |
|
|
|
|
|
|
|
message.media.poll = result.poll; |
|
|
|
|
|
|
|
message.media.results = result.results; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'messageMediaDocument': |
|
|
|
|
|
|
|
if(message.media.ttl_seconds) { |
|
|
|
|
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
message.media.document = appDocsManager.saveDoc(message.media.document, mediaContext); // 11.04.2020 warning
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
if(!message.media.photo) { // * found this bug on test DC
|
|
|
|
case 'messageMediaWebPage': |
|
|
|
delete message.media; |
|
|
|
const messageKey = appWebPagesManager.getMessageKeyForPendingWebPage(peerId, mid, options.isScheduled); |
|
|
|
} |
|
|
|
message.media.webpage = appWebPagesManager.saveWebPage(message.media.webpage, messageKey, mediaContext); |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
/*case 'messageMediaGame': |
|
|
|
} |
|
|
|
AppGamesManager.saveGame(apiMessage.media.game, apiMessage.mid, mediaContext); |
|
|
|
|
|
|
|
apiMessage.media.handleMessage = true; |
|
|
|
case 'messageMediaPoll': { |
|
|
|
break; */ |
|
|
|
const result = appPollsManager.savePoll(message.media.poll, message.media.results, message); |
|
|
|
case 'messageMediaInvoice': |
|
|
|
message.media.poll = result.poll; |
|
|
|
|
|
|
|
message.media.results = result.results; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaDocument': { |
|
|
|
|
|
|
|
if(message.media.ttl_seconds) { |
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
break; |
|
|
|
} else { |
|
|
|
|
|
|
|
message.media.document = appDocsManager.saveDoc(message.media.document, mediaContext); // 11.04.2020 warning
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaWebPage': { |
|
|
|
|
|
|
|
const messageKey = appWebPagesManager.getMessageKeyForPendingWebPage(peerId, mid, options.isScheduled); |
|
|
|
|
|
|
|
message.media.webpage = appWebPagesManager.saveWebPage(message.media.webpage, messageKey, mediaContext); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*case 'messageMediaGame': |
|
|
|
|
|
|
|
AppGamesManager.saveGame(apiMessage.media.game, apiMessage.mid, mediaContext); |
|
|
|
|
|
|
|
apiMessage.media.handleMessage = true; |
|
|
|
|
|
|
|
break; */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'messageMediaInvoice': { |
|
|
|
|
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.action) { |
|
|
|
if(message.action) { |
|
|
|
const action = message.action as MessageAction; |
|
|
|
const action = message.action as MessageAction; |
|
|
|
let migrateFrom: PeerId; |
|
|
|
let migrateFrom: PeerId; |
|
|
|
let migrateTo: PeerId; |
|
|
|
let migrateTo: PeerId; |
|
|
|
const suffix = message.fromId === appUsersManager.getSelf().id ? 'You' : ''; |
|
|
|
const suffix = message.fromId === appUsersManager.getSelf().id ? 'You' : ''; |
|
|
|
|
|
|
|
|
|
|
|
if((action as MessageAction.messageActionChatEditPhoto).photo) { |
|
|
|
if((action as MessageAction.messageActionChatEditPhoto).photo) { |
|
|
|
(action as MessageAction.messageActionChatEditPhoto).photo = appPhotosManager.savePhoto((action as MessageAction.messageActionChatEditPhoto).photo, mediaContext); |
|
|
|
(action as MessageAction.messageActionChatEditPhoto).photo = appPhotosManager.savePhoto((action as MessageAction.messageActionChatEditPhoto).photo, mediaContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if((action as any).document) { |
|
|
|
if((action as any).document) { |
|
|
|
(action as any).document = appDocsManager.saveDoc((action as any).photo, mediaContext); |
|
|
|
(action as any).document = appDocsManager.saveDoc((action as any).photo, mediaContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch(action._) { |
|
|
|
switch(action._) { |
|
|
|
//case 'messageActionChannelEditPhoto':
|
|
|
|
//case 'messageActionChannelEditPhoto':
|
|
|
|
case 'messageActionChatEditPhoto': |
|
|
|
case 'messageActionChatEditPhoto': |
|
|
|
// action.photo = appPhotosManager.savePhoto(action.photo, mediaContext);
|
|
|
|
// action.photo = appPhotosManager.savePhoto(action.photo, mediaContext);
|
|
|
|
if((action.photo as Photo.photo)?.video_sizes) { |
|
|
|
if((action.photo as Photo.photo)?.video_sizes) { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
action._ = isBroadcast ? 'messageActionChannelEditVideo' : 'messageActionChatEditVideo'; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if(isBroadcast) { // ! messageActionChannelEditPhoto не существует в принципе, это используется для перевода.
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action._ = isBroadcast ? 'messageActionChannelEditVideo' : 'messageActionChatEditVideo'; |
|
|
|
action._ = 'messageActionChannelEditPhoto'; |
|
|
|
} else { |
|
|
|
|
|
|
|
if(isBroadcast) { // ! messageActionChannelEditPhoto не существует в принципе, это используется для перевода.
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
action._ = 'messageActionChannelEditPhoto'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case 'messageActionGroupCall': { |
|
|
|
|
|
|
|
//assumeType<MessageAction.messageActionGroupCall>(action);
|
|
|
|
case 'messageActionGroupCall': { |
|
|
|
|
|
|
|
//assumeType<MessageAction.messageActionGroupCall>(action);
|
|
|
|
let type: string; |
|
|
|
|
|
|
|
if(action.duration === undefined) { |
|
|
|
let type: string; |
|
|
|
type = 'started'; |
|
|
|
if(action.duration === undefined) { |
|
|
|
if(peerId !== message.fromId) { |
|
|
|
type = 'started'; |
|
|
|
type += '_by' + suffix; |
|
|
|
if(peerId !== message.fromId) { |
|
|
|
} |
|
|
|
type += '_by' + suffix; |
|
|
|
} else { |
|
|
|
|
|
|
|
type = 'ended_by' + suffix; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
type = 'ended_by' + suffix; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action.type = type; |
|
|
|
action.type = type; |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatEditTitle': |
|
|
|
case 'messageActionChatEditTitle': |
|
|
|
/* if(options.isNew) { |
|
|
|
/* if(options.isNew) { |
|
|
|
const chat = appChatsManager.getChat(peerId.toChatId()); |
|
|
|
const chat = appChatsManager.getChat(peerId.toChatId()); |
|
|
|
chat.title = action.title; |
|
|
|
chat.title = action.title; |
|
|
|
appChatsManager.saveApiChat(chat, true); |
|
|
|
appChatsManager.saveApiChat(chat, true); |
|
|
|
} */ |
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
if(isBroadcast) { |
|
|
|
if(isBroadcast) { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action._ = 'messageActionChannelEditTitle'; |
|
|
|
action._ = 'messageActionChannelEditTitle'; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatDeletePhoto': |
|
|
|
case 'messageActionChatDeletePhoto': |
|
|
|
if(isBroadcast) { |
|
|
|
if(isBroadcast) { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action._ = 'messageActionChannelDeletePhoto'; |
|
|
|
action._ = 'messageActionChannelDeletePhoto'; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatAddUser': |
|
|
|
case 'messageActionChatAddUser': |
|
|
|
if(action.users.length === 1) { |
|
|
|
if(action.users.length === 1) { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action.user_id = action.users[0]; |
|
|
|
action.user_id = action.users[0]; |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
if(message.fromId === action.user_id) { |
|
|
|
if(message.fromId === action.user_id) { |
|
|
|
if(isChannel) { |
|
|
|
if(isChannel) { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action._ = 'messageActionChatJoined' + suffix; |
|
|
|
action._ = 'messageActionChatJoined' + suffix; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action._ = 'messageActionChatReturn' + suffix; |
|
|
|
action._ = 'messageActionChatReturn' + suffix; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else if(action.users.length > 1) { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
action._ = 'messageActionChatAddUsers'; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} else if(action.users.length > 1) { |
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
action._ = 'messageActionChatAddUsers'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatDeleteUser': |
|
|
|
case 'messageActionChatDeleteUser': |
|
|
|
if(message.fromId === action.user_id) { |
|
|
|
if(message.fromId === action.user_id) { |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action._ = 'messageActionChatLeave' + suffix; |
|
|
|
action._ = 'messageActionChatLeave' + suffix; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChannelMigrateFrom': |
|
|
|
case 'messageActionChannelMigrateFrom': |
|
|
|
migrateFrom = action.chat_id.toPeerId(true); |
|
|
|
migrateFrom = action.chat_id.toPeerId(true); |
|
|
|
migrateTo = peerId; |
|
|
|
migrateTo = peerId; |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionChatMigrateTo': |
|
|
|
case 'messageActionChatMigrateTo': |
|
|
|
migrateFrom = peerId; |
|
|
|
migrateFrom = peerId; |
|
|
|
migrateTo = action.channel_id.toPeerId(true); |
|
|
|
migrateTo = action.channel_id.toPeerId(true); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionHistoryClear': |
|
|
|
case 'messageActionHistoryClear': |
|
|
|
//apiMessage.deleted = true;
|
|
|
|
//apiMessage.deleted = true;
|
|
|
|
message.clear_history = true; |
|
|
|
message.clear_history = true; |
|
|
|
delete message.pFlags.out; |
|
|
|
delete message.pFlags.out; |
|
|
|
delete message.pFlags.unread; |
|
|
|
delete message.pFlags.unread; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionPhoneCall': |
|
|
|
case 'messageActionPhoneCall': |
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
action.type = |
|
|
|
action.type = |
|
|
|
(message.pFlags.out ? 'out_' : 'in_') + |
|
|
|
(message.pFlags.out ? 'out_' : 'in_') + |
|
|
|
( |
|
|
|
( |
|
|
|
action.reason._ === 'phoneCallDiscardReasonMissed' || |
|
|
|
action.reason._ === 'phoneCallDiscardReasonMissed' || |
|
|
|
action.reason._ === 'phoneCallDiscardReasonBusy' |
|
|
|
action.reason._ === 'phoneCallDiscardReasonBusy' |
|
|
|
? 'missed' |
|
|
|
? 'missed' |
|
|
|
: 'ok' |
|
|
|
: 'ok' |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(migrateFrom && |
|
|
|
if(migrateFrom && |
|
|
|
migrateTo && |
|
|
|
migrateTo && |
|
|
|
!this.migratedFromTo[migrateFrom] && |
|
|
|
!this.migratedFromTo[migrateFrom] && |
|
|
|
!this.migratedToFrom[migrateTo]) { |
|
|
|
!this.migratedToFrom[migrateTo]) { |
|
|
|
this.migrateChecks(migrateFrom, migrateTo); |
|
|
|
this.migrateChecks(migrateFrom, migrateTo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if(message.grouped_id) { |
|
|
|
|
|
|
|
if(!groups) { |
|
|
|
|
|
|
|
groups = new Set(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* if(message.grouped_id) { |
|
|
|
groups.add(message.grouped_id); |
|
|
|
if(!groups) { |
|
|
|
} else { |
|
|
|
groups = new Set(); |
|
|
|
message.rReply = this.getRichReplyText(message); |
|
|
|
} |
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
groups.add(message.grouped_id); |
|
|
|
if(message.message && message.message.length && !message.totalEntities) { |
|
|
|
} else { |
|
|
|
this.wrapMessageEntities(message); |
|
|
|
message.rReply = this.getRichReplyText(message); |
|
|
|
} |
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(message.message && message.message.length && !message.totalEntities) { |
|
|
|
storage.set(mid, message); |
|
|
|
this.wrapMessageEntities(message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
storage.set(mid, message); |
|
|
|
public saveMessages(messages: any[], options: Partial<{ |
|
|
|
|
|
|
|
storage: MessagesStorage, |
|
|
|
|
|
|
|
isScheduled: true, |
|
|
|
|
|
|
|
isOutgoing: true, |
|
|
|
|
|
|
|
//isNew: boolean, // * new - from update
|
|
|
|
|
|
|
|
}> = {}) { |
|
|
|
|
|
|
|
if((messages as any).saved) return; |
|
|
|
|
|
|
|
(messages as any).saved = true; |
|
|
|
|
|
|
|
messages.forEach((message) => { |
|
|
|
|
|
|
|
this.saveMessage(message, options); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/* if(groups) { |
|
|
|
|
|
|
|
for(const groupId of groups) { |
|
|
|
|
|
|
|
const mids = this.groupedMessagesStorage[groupId]; |
|
|
|
|
|
|
|
for(const mid in mids) { |
|
|
|
|
|
|
|
const message = this.groupedMessagesStorage[groupId][mid]; |
|
|
|
|
|
|
|
message.rReply = this.getRichReplyText(message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private wrapMessageEntities(message: any) { |
|
|
|
private wrapMessageEntities(message: Message.message) { |
|
|
|
const apiEntities = message.entities ? message.entities.slice() : []; |
|
|
|
const apiEntities = message.entities ? message.entities.slice() : []; |
|
|
|
message.message = RichTextProcessor.fixEmoji(message.message, apiEntities); |
|
|
|
message.message = RichTextProcessor.fixEmoji(message.message, apiEntities); |
|
|
|
|
|
|
|
|
|
|
@ -2663,9 +2675,9 @@ export class AppMessagesManager { |
|
|
|
message.totalEntities = RichTextProcessor.mergeEntities(apiEntities, myEntities); // ! only in this order, otherwise bold and emoji formatting won't work
|
|
|
|
message.totalEntities = RichTextProcessor.mergeEntities(apiEntities, myEntities); // ! only in this order, otherwise bold and emoji formatting won't work
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public wrapMessageForReply(message: any, text: string, usingMids: number[], plain: true, highlightWord?: string, withoutMediaType?: boolean): string; |
|
|
|
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text: string, usingMids: number[], plain: true, highlightWord?: string, withoutMediaType?: boolean): string; |
|
|
|
public wrapMessageForReply(message: any, text?: string, usingMids?: number[], plain?: false, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment; |
|
|
|
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text?: string, usingMids?: number[], plain?: false, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment; |
|
|
|
public wrapMessageForReply(message: any, text: string = message.message, usingMids?: number[], plain?: boolean, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment | string { |
|
|
|
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text: string = (message as Message.message).message, usingMids?: number[], plain?: boolean, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment | string { |
|
|
|
const parts: (HTMLElement | string)[] = []; |
|
|
|
const parts: (HTMLElement | string)[] = []; |
|
|
|
|
|
|
|
|
|
|
|
const addPart = (langKey: LangPackKey, part?: string | HTMLElement, text?: string) => { |
|
|
|
const addPart = (langKey: LangPackKey, part?: string | HTMLElement, text?: string) => { |
|
|
@ -2687,7 +2699,7 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if(message.media) { |
|
|
|
if('media' in message) { |
|
|
|
let usingFullAlbum = true; |
|
|
|
let usingFullAlbum = true; |
|
|
|
if(message.grouped_id) { |
|
|
|
if(message.grouped_id) { |
|
|
|
if(usingMids) { |
|
|
|
if(usingMids) { |
|
|
@ -2784,7 +2796,7 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(message.action) { |
|
|
|
if('action' in message) { |
|
|
|
const actionWrapped = this.wrapMessageActionTextNew(message, plain); |
|
|
|
const actionWrapped = this.wrapMessageActionTextNew(message, plain); |
|
|
|
if(actionWrapped) { |
|
|
|
if(actionWrapped) { |
|
|
|
addPart(undefined, actionWrapped); |
|
|
|
addPart(undefined, actionWrapped); |
|
|
@ -2865,20 +2877,21 @@ export class AppMessagesManager { |
|
|
|
return el; |
|
|
|
return el; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public wrapMessageActionTextNew(message: any, plain: true): string; |
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain: true): string; |
|
|
|
public wrapMessageActionTextNew(message: any, plain?: false): HTMLElement; |
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain?: false): HTMLElement; |
|
|
|
public wrapMessageActionTextNew(message: any, plain: boolean): HTMLElement | string; |
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain: boolean): HTMLElement | string; |
|
|
|
public wrapMessageActionTextNew(message: any, plain?: boolean): HTMLElement | string { |
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain?: boolean): HTMLElement | string { |
|
|
|
const element: HTMLElement = plain ? undefined : document.createElement('span'); |
|
|
|
const element: HTMLElement = plain ? undefined : document.createElement('span'); |
|
|
|
const action = message.action as MessageAction; |
|
|
|
const action = 'action' in message && message.action; |
|
|
|
|
|
|
|
|
|
|
|
// this.log('message action:', action);
|
|
|
|
// this.log('message action:', action);
|
|
|
|
|
|
|
|
|
|
|
|
if((action as MessageAction.messageActionCustomAction).message) { |
|
|
|
if((action as MessageAction.messageActionCustomAction).message) { |
|
|
|
|
|
|
|
const unsafeMessage = (action as MessageAction.messageActionCustomAction).message; |
|
|
|
if(plain) { |
|
|
|
if(plain) { |
|
|
|
return RichTextProcessor.wrapPlainText(message.message); |
|
|
|
return RichTextProcessor.wrapPlainText(unsafeMessage); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
element.innerHTML = RichTextProcessor.wrapRichText((action as MessageAction.messageActionCustomAction).message, {noLinebreaks: true}); |
|
|
|
element.innerHTML = RichTextProcessor.wrapRichText(unsafeMessage, {noLinebreaks: true}); |
|
|
|
return element; |
|
|
|
return element; |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -2912,7 +2925,7 @@ export class AppMessagesManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case 'messageActionInviteToGroupCall': { |
|
|
|
case 'messageActionInviteToGroupCall': { |
|
|
|
const peerIds = [message.fromId, action.users[0]]; |
|
|
|
const peerIds = [message.fromId, action.users[0].toPeerId()]; |
|
|
|
let a = 'ActionGroupCall'; |
|
|
|
let a = 'ActionGroupCall'; |
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
if(peerIds[0] === myId) a += 'You'; |
|
|
|
if(peerIds[0] === myId) a += 'You'; |
|
|
@ -2942,7 +2955,7 @@ export class AppMessagesManager { |
|
|
|
args.push(getNameDivHTML(message.fromId, plain)); |
|
|
|
args.push(getNameDivHTML(message.fromId, plain)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let k: LangPackKey, _args: any[] = []; |
|
|
|
let k: LangPackKey, _args: FormatterArguments = []; |
|
|
|
if(daysToStart < 1 && date.getDate() === today.getDate()) { |
|
|
|
if(daysToStart < 1 && date.getDate() === today.getDate()) { |
|
|
|
k = 'TodayAtFormattedWithToday'; |
|
|
|
k = 'TodayAtFormattedWithToday'; |
|
|
|
} else if(daysToStart < 2 && date.getDate() === tomorrowDate.getDate()) { |
|
|
|
} else if(daysToStart < 2 && date.getDate() === tomorrowDate.getDate()) { |
|
|
|