|
|
|
@ -19,7 +19,7 @@ import { randomLong } from "../../helpers/random";
@@ -19,7 +19,7 @@ import { randomLong } from "../../helpers/random";
|
|
|
|
|
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 { 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 type { ApiFileManager } from '../mtproto/apiFileManager'; |
|
|
|
|
//import apiManager from '../mtproto/apiManager';
|
|
|
|
@ -41,7 +41,7 @@ import appPollsManager from "./appPollsManager";
@@ -41,7 +41,7 @@ import appPollsManager from "./appPollsManager";
|
|
|
|
|
import appStateManager from "./appStateManager"; |
|
|
|
|
import appUsersManager from "./appUsersManager"; |
|
|
|
|
import appWebPagesManager from "./appWebPagesManager"; |
|
|
|
|
import appDraftsManager from "./appDraftsManager"; |
|
|
|
|
import appDraftsManager, { MyDraftMessage } from "./appDraftsManager"; |
|
|
|
|
import { getFileNameByLocation } from "../../helpers/fileName"; |
|
|
|
|
import appProfileManager from "./appProfileManager"; |
|
|
|
|
import DEBUG, { MOUNT_CLASS_TO } from "../../config/debug"; |
|
|
|
@ -2332,14 +2332,12 @@ export class AppMessagesManager {
@@ -2332,14 +2332,12 @@ export class AppMessagesManager {
|
|
|
|
|
return appMessagesIdsManager.generateMessageId(dialog?.top_message || 0, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public saveMessages(messages: any[], options: Partial<{ |
|
|
|
|
public saveMessage(message: any, options: Partial<{ |
|
|
|
|
storage: MessagesStorage, |
|
|
|
|
isScheduled: true, |
|
|
|
|
isOutgoing: true, |
|
|
|
|
//isNew: boolean, // * new - from update
|
|
|
|
|
}> = {}) { |
|
|
|
|
//let groups: Set<string>;
|
|
|
|
|
messages.forEach((message) => { |
|
|
|
|
if(message.pFlags === undefined) { |
|
|
|
|
message.pFlags = {}; |
|
|
|
|
} |
|
|
|
@ -2452,10 +2450,12 @@ export class AppMessagesManager {
@@ -2452,10 +2450,12 @@ export class AppMessagesManager {
|
|
|
|
|
|
|
|
|
|
if(message.media) { |
|
|
|
|
switch(message.media._) { |
|
|
|
|
case 'messageMediaEmpty': |
|
|
|
|
case 'messageMediaEmpty': { |
|
|
|
|
delete message.media; |
|
|
|
|
break; |
|
|
|
|
case 'messageMediaPhoto': |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'messageMediaPhoto': { |
|
|
|
|
if(message.media.ttl_seconds) { |
|
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
} else { |
|
|
|
@ -2467,12 +2467,16 @@ export class AppMessagesManager {
@@ -2467,12 +2467,16 @@ export class AppMessagesManager {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
case 'messageMediaPoll': |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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': |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'messageMediaDocument': { |
|
|
|
|
if(message.media.ttl_seconds) { |
|
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
} else { |
|
|
|
@ -2480,19 +2484,25 @@ export class AppMessagesManager {
@@ -2480,19 +2484,25 @@ export class AppMessagesManager {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
case 'messageMediaWebPage': |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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': |
|
|
|
|
|
|
|
|
|
case 'messageMediaInvoice': { |
|
|
|
|
message.media = {_: 'messageMediaUnsupportedWeb'}; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(message.action) { |
|
|
|
|
const action = message.action as MessageAction; |
|
|
|
@ -2642,20 +2652,22 @@ export class AppMessagesManager {
@@ -2642,20 +2652,22 @@ export class AppMessagesManager {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
storage.set(mid, message); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/* 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private wrapMessageEntities(message: any) { |
|
|
|
|
private wrapMessageEntities(message: Message.message) { |
|
|
|
|
const apiEntities = message.entities ? message.entities.slice() : []; |
|
|
|
|
message.message = RichTextProcessor.fixEmoji(message.message, apiEntities); |
|
|
|
|
|
|
|
|
@ -2663,9 +2675,9 @@ export class AppMessagesManager {
@@ -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
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public wrapMessageForReply(message: any, 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: any, text: string = message.message, usingMids?: number[], plain?: boolean, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment | string { |
|
|
|
|
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text: string, usingMids: number[], plain: true, highlightWord?: string, withoutMediaType?: boolean): string; |
|
|
|
|
public wrapMessageForReply(message: MyMessage | MyDraftMessage, text?: string, usingMids?: number[], plain?: false, highlightWord?: string, withoutMediaType?: boolean): DocumentFragment; |
|
|
|
|
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 addPart = (langKey: LangPackKey, part?: string | HTMLElement, text?: string) => { |
|
|
|
@ -2687,7 +2699,7 @@ export class AppMessagesManager {
@@ -2687,7 +2699,7 @@ export class AppMessagesManager {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if(message.media) { |
|
|
|
|
if('media' in message) { |
|
|
|
|
let usingFullAlbum = true; |
|
|
|
|
if(message.grouped_id) { |
|
|
|
|
if(usingMids) { |
|
|
|
@ -2784,7 +2796,7 @@ export class AppMessagesManager {
@@ -2784,7 +2796,7 @@ export class AppMessagesManager {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(message.action) { |
|
|
|
|
if('action' in message) { |
|
|
|
|
const actionWrapped = this.wrapMessageActionTextNew(message, plain); |
|
|
|
|
if(actionWrapped) { |
|
|
|
|
addPart(undefined, actionWrapped); |
|
|
|
@ -2865,20 +2877,21 @@ export class AppMessagesManager {
@@ -2865,20 +2877,21 @@ export class AppMessagesManager {
|
|
|
|
|
return el; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public wrapMessageActionTextNew(message: any, plain: true): string; |
|
|
|
|
public wrapMessageActionTextNew(message: any, plain?: false): HTMLElement; |
|
|
|
|
public wrapMessageActionTextNew(message: any, plain: boolean): HTMLElement | string; |
|
|
|
|
public wrapMessageActionTextNew(message: any, plain?: boolean): HTMLElement | string { |
|
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain: true): string; |
|
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain?: false): HTMLElement; |
|
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain: boolean): HTMLElement | string; |
|
|
|
|
public wrapMessageActionTextNew(message: MyMessage, plain?: boolean): HTMLElement | string { |
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if((action as MessageAction.messageActionCustomAction).message) { |
|
|
|
|
const unsafeMessage = (action as MessageAction.messageActionCustomAction).message; |
|
|
|
|
if(plain) { |
|
|
|
|
return RichTextProcessor.wrapPlainText(message.message); |
|
|
|
|
return RichTextProcessor.wrapPlainText(unsafeMessage); |
|
|
|
|
} else { |
|
|
|
|
element.innerHTML = RichTextProcessor.wrapRichText((action as MessageAction.messageActionCustomAction).message, {noLinebreaks: true}); |
|
|
|
|
element.innerHTML = RichTextProcessor.wrapRichText(unsafeMessage, {noLinebreaks: true}); |
|
|
|
|
return element; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -2912,7 +2925,7 @@ export class AppMessagesManager {
@@ -2912,7 +2925,7 @@ export class AppMessagesManager {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 'messageActionInviteToGroupCall': { |
|
|
|
|
const peerIds = [message.fromId, action.users[0]]; |
|
|
|
|
const peerIds = [message.fromId, action.users[0].toPeerId()]; |
|
|
|
|
let a = 'ActionGroupCall'; |
|
|
|
|
const myId = appUsersManager.getSelf().id; |
|
|
|
|
if(peerIds[0] === myId) a += 'You'; |
|
|
|
@ -2942,7 +2955,7 @@ export class AppMessagesManager {
@@ -2942,7 +2955,7 @@ export class AppMessagesManager {
|
|
|
|
|
args.push(getNameDivHTML(message.fromId, plain)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let k: LangPackKey, _args: any[] = []; |
|
|
|
|
let k: LangPackKey, _args: FormatterArguments = []; |
|
|
|
|
if(daysToStart < 1 && date.getDate() === today.getDate()) { |
|
|
|
|
k = 'TodayAtFormattedWithToday'; |
|
|
|
|
} else if(daysToStart < 2 && date.getDate() === tomorrowDate.getDate()) { |
|
|
|
|