|
|
@ -455,45 +455,28 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
peerId = appPeersManager.getPeerMigratedTo(peerId) || peerId; |
|
|
|
peerId = appPeersManager.getPeerMigratedTo(peerId) || peerId; |
|
|
|
|
|
|
|
|
|
|
|
var entities = options.entities || []; |
|
|
|
let entities = options.entities || []; |
|
|
|
if(!options.viaBotId) { |
|
|
|
if(!options.viaBotId) { |
|
|
|
text = RichTextProcessor.parseMarkdown(text, entities); |
|
|
|
text = RichTextProcessor.parseMarkdown(text, entities); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var sendEntites = this.getInputEntities(entities); |
|
|
|
let sendEntites = this.getInputEntities(entities); |
|
|
|
if(!sendEntites.length) { |
|
|
|
if(!sendEntites.length) { |
|
|
|
sendEntites = undefined; |
|
|
|
sendEntites = undefined; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var messageId = this.generateTempMessageId(peerId); |
|
|
|
const messageId = this.generateTempMessageId(peerId); |
|
|
|
var randomIdS = randomLong(); |
|
|
|
const randomIdS = randomLong(); |
|
|
|
var pFlags: any = {}; |
|
|
|
const replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined; |
|
|
|
var replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined; |
|
|
|
const isChannel = appPeersManager.isChannel(peerId); |
|
|
|
var isChannel = appPeersManager.isChannel(peerId); |
|
|
|
const isBroadcast = appPeersManager.isBroadcast(peerId); |
|
|
|
var isMegagroup = isChannel && appPeersManager.isMegagroup(peerId); |
|
|
|
|
|
|
|
var asChannel = isChannel && !isMegagroup ? true : false; |
|
|
|
|
|
|
|
var message: any; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fromId = appUsersManager.getSelf().id; |
|
|
|
|
|
|
|
if(peerId != fromId) { |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!isChannel && !appUsersManager.isBot(peerId)) { |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(asChannel) { |
|
|
|
|
|
|
|
fromId = 0; |
|
|
|
|
|
|
|
pFlags.post = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
message = { |
|
|
|
const message: any = { |
|
|
|
_: 'message', |
|
|
|
_: 'message', |
|
|
|
id: messageId, |
|
|
|
id: messageId, |
|
|
|
from_id: appPeersManager.getOutputPeer(fromId), |
|
|
|
from_id: this.generateFromId(peerId), |
|
|
|
peer_id: appPeersManager.getOutputPeer(peerId), |
|
|
|
peer_id: appPeersManager.getOutputPeer(peerId), |
|
|
|
pFlags, |
|
|
|
pFlags: this.generateFlags(peerId), |
|
|
|
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), |
|
|
|
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), |
|
|
|
message: text, |
|
|
|
message: text, |
|
|
|
random_id: randomIdS, |
|
|
|
random_id: randomIdS, |
|
|
@ -501,7 +484,7 @@ export class AppMessagesManager { |
|
|
|
via_bot_id: options.viaBotId, |
|
|
|
via_bot_id: options.viaBotId, |
|
|
|
reply_markup: options.reply_markup, |
|
|
|
reply_markup: options.reply_markup, |
|
|
|
entities: entities, |
|
|
|
entities: entities, |
|
|
|
views: asChannel && 1, |
|
|
|
views: isBroadcast && 1, |
|
|
|
pending: true |
|
|
|
pending: true |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -512,7 +495,7 @@ export class AppMessagesManager { |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var toggleError = (on: any) => { |
|
|
|
const toggleError = (on: any) => { |
|
|
|
if(on) { |
|
|
|
if(on) { |
|
|
|
message.error = true; |
|
|
|
message.error = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -523,12 +506,12 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
message.send = () => { |
|
|
|
message.send = () => { |
|
|
|
toggleError(false); |
|
|
|
toggleError(false); |
|
|
|
var sentRequestOptions: any = {}; |
|
|
|
const sentRequestOptions: any = {}; |
|
|
|
if(this.pendingAfterMsgs[peerId]) { |
|
|
|
if(this.pendingAfterMsgs[peerId]) { |
|
|
|
sentRequestOptions.afterMessageId = this.pendingAfterMsgs[peerId].messageId; |
|
|
|
sentRequestOptions.afterMessageId = this.pendingAfterMsgs[peerId].messageId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var apiPromise: any; |
|
|
|
let apiPromise: any; |
|
|
|
if(options.viaBotId) { |
|
|
|
if(options.viaBotId) { |
|
|
|
apiPromise = apiManager.invokeApiAfter('messages.sendInlineBotResult', { |
|
|
|
apiPromise = apiManager.invokeApiAfter('messages.sendInlineBotResult', { |
|
|
|
peer: appPeersManager.getInputPeerById(peerId), |
|
|
|
peer: appPeersManager.getInputPeerById(peerId), |
|
|
@ -631,7 +614,7 @@ export class AppMessagesManager { |
|
|
|
//this.checkSendOptions(options);
|
|
|
|
//this.checkSendOptions(options);
|
|
|
|
const messageId = this.generateTempMessageId(peerId); |
|
|
|
const messageId = this.generateTempMessageId(peerId); |
|
|
|
const randomIdS = randomLong(); |
|
|
|
const randomIdS = randomLong(); |
|
|
|
const pFlags: any = {}; |
|
|
|
const pFlags = this.generateFlags(peerId); |
|
|
|
const replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined; |
|
|
|
const replyToMsgId = options.replyToMsgId ? this.getLocalMessageId(options.replyToMsgId) : undefined; |
|
|
|
const isChannel = appPeersManager.isChannel(peerId); |
|
|
|
const isChannel = appPeersManager.isChannel(peerId); |
|
|
|
const isMegagroup = isChannel && appPeersManager.isMegagroup(peerId); |
|
|
|
const isMegagroup = isChannel && appPeersManager.isMegagroup(peerId); |
|
|
@ -777,20 +760,6 @@ export class AppMessagesManager { |
|
|
|
|
|
|
|
|
|
|
|
this.log('AMM: sendFile', attachType, apiFileName, file.type, options); |
|
|
|
this.log('AMM: sendFile', attachType, apiFileName, file.type, options); |
|
|
|
|
|
|
|
|
|
|
|
let fromId = appUsersManager.getSelf().id; |
|
|
|
|
|
|
|
if(peerId != fromId) { |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!isChannel && !appUsersManager.isBot(peerId)) { |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(asChannel) { |
|
|
|
|
|
|
|
fromId = 0; |
|
|
|
|
|
|
|
pFlags.post = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const preloader = new ProgressivePreloader(null, true, false, 'prepend'); |
|
|
|
const preloader = new ProgressivePreloader(null, true, false, 'prepend'); |
|
|
|
|
|
|
|
|
|
|
|
const media = { |
|
|
|
const media = { |
|
|
@ -810,7 +779,7 @@ export class AppMessagesManager { |
|
|
|
const message: any = { |
|
|
|
const message: any = { |
|
|
|
_: 'message', |
|
|
|
_: 'message', |
|
|
|
id: messageId, |
|
|
|
id: messageId, |
|
|
|
from_id: appPeersManager.getOutputPeer(fromId), |
|
|
|
from_id: this.generateFromId(peerId), |
|
|
|
peer_id: appPeersManager.getOutputPeer(peerId), |
|
|
|
peer_id: appPeersManager.getOutputPeer(peerId), |
|
|
|
pFlags, |
|
|
|
pFlags, |
|
|
|
date, |
|
|
|
date, |
|
|
@ -1198,25 +1167,12 @@ export class AppMessagesManager { |
|
|
|
break; */ |
|
|
|
break; */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let pFlags: any = {}; |
|
|
|
|
|
|
|
if(peerId != fromId) { |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
|
|
|
|
if(!appUsersManager.isBot(peerId)) { |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(asChannel) { |
|
|
|
|
|
|
|
fromId = 0; |
|
|
|
|
|
|
|
pFlags.post = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const message: any = { |
|
|
|
const message: any = { |
|
|
|
_: 'message', |
|
|
|
_: 'message', |
|
|
|
id: messageId, |
|
|
|
id: messageId, |
|
|
|
from_id: appPeersManager.getOutputPeer(fromId), |
|
|
|
from_id: this.generateFromId(peerId), |
|
|
|
peer_id: appPeersManager.getOutputPeer(peerId), |
|
|
|
peer_id: appPeersManager.getOutputPeer(peerId), |
|
|
|
pFlags, |
|
|
|
pFlags: this.generateFlags(peerId), |
|
|
|
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), |
|
|
|
date: options.scheduleDate || (tsNow(true) + serverTimeManager.serverTimeOffset), |
|
|
|
message: '', |
|
|
|
message: '', |
|
|
|
media, |
|
|
|
media, |
|
|
@ -1352,6 +1308,35 @@ export class AppMessagesManager { |
|
|
|
return header; |
|
|
|
return header; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Generate correct from_id according to anonymous or broadcast |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public generateFromId(peerId: number) { |
|
|
|
|
|
|
|
if(peerId < 0 && (appPeersManager.isBroadcast(peerId) || appPeersManager.getPeer(peerId).admin_rights?.pFlags?.anonymous)) { |
|
|
|
|
|
|
|
return undefined; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return appPeersManager.getOutputPeer(peerId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public generateFlags(peerId: number) { |
|
|
|
|
|
|
|
const pFlags: any = {}; |
|
|
|
|
|
|
|
const fromId = appUsersManager.getSelf().id; |
|
|
|
|
|
|
|
if(peerId !== fromId) { |
|
|
|
|
|
|
|
pFlags.out = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!appPeersManager.isChannel(peerId) && !appUsersManager.isBot(peerId)) { |
|
|
|
|
|
|
|
pFlags.unread = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(appPeersManager.isBroadcast(peerId)) { |
|
|
|
|
|
|
|
pFlags.post = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pFlags; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private setDialogIndexByMessage(dialog: MTDialog.dialog, message: MyMessage) { |
|
|
|
private setDialogIndexByMessage(dialog: MTDialog.dialog, message: MyMessage) { |
|
|
|
if(!dialog.pFlags.pinned || !dialog.index) { |
|
|
|
if(!dialog.pFlags.pinned || !dialog.index) { |
|
|
|
dialog.index = this.dialogsStorage.generateDialogIndex(message.date); |
|
|
|
dialog.index = this.dialogsStorage.generateDialogIndex(message.date); |
|
|
|