Fix afterMessageID
This commit is contained in:
parent
b260c4a5a7
commit
2a5f859ed7
@ -748,9 +748,9 @@ export class AppMessagesManager {
|
|||||||
text = splitted[0];
|
text = splitted[0];
|
||||||
|
|
||||||
for(let i = 1; i < splitted.length; ++i) {
|
for(let i = 1; i < splitted.length; ++i) {
|
||||||
//setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.sendText(peerID, splitted[i], options);
|
this.sendText(peerID, splitted[i], options);
|
||||||
//}, i);
|
}, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -837,7 +837,7 @@ export class AppMessagesManager {
|
|||||||
|
|
||||||
var apiPromise: any;
|
var apiPromise: any;
|
||||||
if(options.viaBotID) {
|
if(options.viaBotID) {
|
||||||
apiPromise = apiManager.invokeApi('messages.sendInlineBotResult', {
|
apiPromise = apiManager.invokeApiAfter('messages.sendInlineBotResult', {
|
||||||
peer: appPeersManager.getInputPeerByID(peerID),
|
peer: appPeersManager.getInputPeerByID(peerID),
|
||||||
random_id: randomID as any,
|
random_id: randomID as any,
|
||||||
reply_to_msg_id: replyToMsgID ? appMessagesIDsManager.getMessageLocalID(replyToMsgID) : undefined,
|
reply_to_msg_id: replyToMsgID ? appMessagesIDsManager.getMessageLocalID(replyToMsgID) : undefined,
|
||||||
@ -846,7 +846,7 @@ export class AppMessagesManager {
|
|||||||
clear_draft: options.clearDraft
|
clear_draft: options.clearDraft
|
||||||
}, sentRequestOptions);
|
}, sentRequestOptions);
|
||||||
} else {
|
} else {
|
||||||
apiPromise = apiManager.invokeApi('messages.sendMessage', {
|
apiPromise = apiManager.invokeApiAfter('messages.sendMessage', {
|
||||||
no_webpage: options.noWebPage,
|
no_webpage: options.noWebPage,
|
||||||
peer: appPeersManager.getInputPeerByID(peerID),
|
peer: appPeersManager.getInputPeerByID(peerID),
|
||||||
message: text,
|
message: text,
|
||||||
@ -1731,7 +1731,7 @@ export class AppMessagesManager {
|
|||||||
|
|
||||||
let apiPromise: Promise<any>;
|
let apiPromise: Promise<any>;
|
||||||
if(options.viaBotID) {
|
if(options.viaBotID) {
|
||||||
apiPromise = apiManager.invokeApi('messages.sendInlineBotResult', {
|
apiPromise = apiManager.invokeApiAfter('messages.sendInlineBotResult', {
|
||||||
peer: appPeersManager.getInputPeerByID(peerID),
|
peer: appPeersManager.getInputPeerByID(peerID),
|
||||||
random_id: randomID as any,
|
random_id: randomID as any,
|
||||||
reply_to_msg_id: replyToMsgID ? appMessagesIDsManager.getMessageLocalID(replyToMsgID) : undefined,
|
reply_to_msg_id: replyToMsgID ? appMessagesIDsManager.getMessageLocalID(replyToMsgID) : undefined,
|
||||||
@ -1740,7 +1740,7 @@ export class AppMessagesManager {
|
|||||||
clear_draft: options.clearDraft
|
clear_draft: options.clearDraft
|
||||||
}, sentRequestOptions);
|
}, sentRequestOptions);
|
||||||
} else {
|
} else {
|
||||||
apiPromise = apiManager.invokeApi('messages.sendMedia', {
|
apiPromise = apiManager.invokeApiAfter('messages.sendMedia', {
|
||||||
peer: appPeersManager.getInputPeerByID(peerID),
|
peer: appPeersManager.getInputPeerByID(peerID),
|
||||||
media: inputMedia,
|
media: inputMedia,
|
||||||
random_id: randomID as any,
|
random_id: randomID as any,
|
||||||
@ -2032,7 +2032,7 @@ export class AppMessagesManager {
|
|||||||
sentRequestOptions.afterMessageID = this.pendingAfterMsgs[peerID].messageID;
|
sentRequestOptions.afterMessageID = this.pendingAfterMsgs[peerID].messageID;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promise = apiManager.invokeApi('messages.forwardMessages', {
|
const promise = apiManager.invokeApiAfter('messages.forwardMessages', {
|
||||||
from_peer: appPeersManager.getInputPeerByID(-channelID),
|
from_peer: appPeersManager.getInputPeerByID(-channelID),
|
||||||
id: msgIDs,
|
id: msgIDs,
|
||||||
random_id: randomIDs as any,
|
random_id: randomIDs as any,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import AppStorage from '../storage';
|
import AppStorage from '../storage';
|
||||||
|
|
||||||
import MTPNetworker from './networker';
|
import MTPNetworker, { MTMessage } from './networker';
|
||||||
import { bytesFromHex, bytesToHex, isObject } from '../bin_utils';
|
import { bytesFromHex, bytesToHex, isObject } from '../bin_utils';
|
||||||
import networkerFactory from './networkerFactory';
|
import networkerFactory from './networkerFactory';
|
||||||
//import { telegramMeWebService } from './mtproto';
|
//import { telegramMeWebService } from './mtproto';
|
||||||
@ -46,6 +46,8 @@ export class ApiManager {
|
|||||||
public telegramMeNotified = false;
|
public telegramMeNotified = false;
|
||||||
|
|
||||||
private log: ReturnType<typeof logger> = logger('API');
|
private log: ReturnType<typeof logger> = logger('API');
|
||||||
|
|
||||||
|
private afterMessageTempIDs: {[tempID: string]: string} = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
//MtpSingleInstanceService.start();
|
//MtpSingleInstanceService.start();
|
||||||
@ -193,6 +195,13 @@ export class ApiManager {
|
|||||||
|
|
||||||
const deferred = deferredPromise<MethodDeclMap[T]['res']>();
|
const deferred = deferredPromise<MethodDeclMap[T]['res']>();
|
||||||
|
|
||||||
|
const afterMessageIDTemp = options.afterMessageID;
|
||||||
|
if(afterMessageIDTemp) {
|
||||||
|
deferred.finally(() => {
|
||||||
|
delete this.afterMessageTempIDs[afterMessageIDTemp];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(MOUNT_CLASS_TO) {
|
if(MOUNT_CLASS_TO) {
|
||||||
deferred.finally(() => {
|
deferred.finally(() => {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
@ -248,9 +257,15 @@ export class ApiManager {
|
|||||||
var cachedNetworker: MTPNetworker;
|
var cachedNetworker: MTPNetworker;
|
||||||
var stack = (new Error()).stack || 'empty stack';
|
var stack = (new Error()).stack || 'empty stack';
|
||||||
var performRequest = (networker: MTPNetworker) => {
|
var performRequest = (networker: MTPNetworker) => {
|
||||||
return (cachedNetworker = networker)
|
if(afterMessageIDTemp) {
|
||||||
.wrapApiCall(method, params, options)
|
options.afterMessageID = this.afterMessageTempIDs[afterMessageIDTemp];
|
||||||
.then(deferred.resolve, (error: ApiError) => {
|
}
|
||||||
|
const promise = (cachedNetworker = networker).wrapApiCall(method, params, options);
|
||||||
|
if(options.prepareTempMessageID) {
|
||||||
|
this.afterMessageTempIDs[options.prepareTempMessageID] = (options as MTMessage).messageID;
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then(deferred.resolve, (error: ApiError) => {
|
||||||
//if(!options.ignoreErrors) {
|
//if(!options.ignoreErrors) {
|
||||||
if(error.type != 'FILE_REFERENCE_EXPIRED') {
|
if(error.type != 'FILE_REFERENCE_EXPIRED') {
|
||||||
this.log.error('Error', error.code, error.type, this.baseDcID, dcID, method, params);
|
this.log.error('Error', error.code, error.type, this.baseDcID, dcID, method, params);
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
import {isObject} from '../utils';
|
import MTProtoWorker from 'worker-loader!./mtproto.worker';
|
||||||
import AppStorage from '../storage';
|
import type { MethodDeclMap } from '../../layer';
|
||||||
|
import type { InvokeApiOptions } from '../../types';
|
||||||
import CryptoWorkerMethods from '../crypto/crypto_methods';
|
import CryptoWorkerMethods from '../crypto/crypto_methods';
|
||||||
import { logger } from '../logger';
|
import { logger } from '../logger';
|
||||||
import webpWorkerController from '../webp/webpWorkerController';
|
|
||||||
import MTProtoWorker from 'worker-loader!./mtproto.worker';
|
|
||||||
import type { DownloadOptions } from './apiFileManager';
|
|
||||||
import type { ServiceWorkerTask, ServiceWorkerTaskResponse } from './mtproto.service';
|
|
||||||
import { MethodDeclMap } from '../../layer';
|
|
||||||
import { MOUNT_CLASS_TO } from './mtproto_config';
|
|
||||||
import $rootScope from '../rootScope';
|
import $rootScope from '../rootScope';
|
||||||
import referenceDatabase from './referenceDatabase';
|
import AppStorage from '../storage';
|
||||||
|
import { isObject } from '../utils';
|
||||||
|
import webpWorkerController from '../webp/webpWorkerController';
|
||||||
|
import type { DownloadOptions } from './apiFileManager';
|
||||||
import { ApiError } from './apiManager';
|
import { ApiError } from './apiManager';
|
||||||
import { InvokeApiOptions } from '../../types';
|
import type { ServiceWorkerTask, ServiceWorkerTaskResponse } from './mtproto.service';
|
||||||
|
import { MOUNT_CLASS_TO } from './mtproto_config';
|
||||||
|
import type { MTMessage } from './networker';
|
||||||
|
import referenceDatabase from './referenceDatabase';
|
||||||
|
|
||||||
type Task = {
|
type Task = {
|
||||||
taskID: number,
|
taskID: number,
|
||||||
@ -24,6 +25,7 @@ const USEWORKERASWORKER = true;
|
|||||||
class ApiManagerProxy extends CryptoWorkerMethods {
|
class ApiManagerProxy extends CryptoWorkerMethods {
|
||||||
public worker: Worker;
|
public worker: Worker;
|
||||||
public postMessage: (...args: any[]) => void;
|
public postMessage: (...args: any[]) => void;
|
||||||
|
private afterMessageIDTemp = 0;
|
||||||
|
|
||||||
private taskID = 0;
|
private taskID = 0;
|
||||||
private awaiting: {
|
private awaiting: {
|
||||||
@ -206,25 +208,22 @@ class ApiManagerProxy extends CryptoWorkerMethods {
|
|||||||
this.updatesProcessor = callback;
|
this.updatesProcessor = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public invokeApi<T extends keyof MethodDeclMap>(method: T, params: MethodDeclMap[T]['req'] = {}, options: {
|
public invokeApi<T extends keyof MethodDeclMap>(method: T, params: MethodDeclMap[T]['req'] = {}, options: InvokeApiOptions = {}): Promise<MethodDeclMap[T]['res']> {
|
||||||
dcID?: number,
|
|
||||||
timeout?: number,
|
|
||||||
noErrorBox?: boolean,
|
|
||||||
fileUpload?: boolean,
|
|
||||||
ignoreErrors?: boolean,
|
|
||||||
fileDownload?: boolean,
|
|
||||||
createNetworker?: boolean,
|
|
||||||
singleInRequest?: boolean,
|
|
||||||
startMaxLength?: number,
|
|
||||||
|
|
||||||
waitTime?: number,
|
|
||||||
stopTime?: number,
|
|
||||||
rawError?: any
|
|
||||||
} = {}): Promise<MethodDeclMap[T]['res']> {
|
|
||||||
//console.log('will invokeApi:', method, params, options);
|
//console.log('will invokeApi:', method, params, options);
|
||||||
return this.performTaskWorker('invokeApi', method, params, options);
|
return this.performTaskWorker('invokeApi', method, params, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public invokeApiAfter<T extends keyof MethodDeclMap>(method: T, params: MethodDeclMap[T]['req'] = {}, options: InvokeApiOptions = {}): Promise<MethodDeclMap[T]['res']> {
|
||||||
|
let o = options;
|
||||||
|
o.prepareTempMessageID = '' + ++this.afterMessageIDTemp;
|
||||||
|
|
||||||
|
o = {...options};
|
||||||
|
(options as MTMessage).messageID = o.prepareTempMessageID;
|
||||||
|
|
||||||
|
//console.log('will invokeApi:', method, params, options);
|
||||||
|
return this.performTaskWorker('invokeApi', method, params, o);
|
||||||
|
}
|
||||||
|
|
||||||
public setBaseDcID(dcID: number) {
|
public setBaseDcID(dcID: number) {
|
||||||
return this.performTaskWorker('setBaseDcID', dcID);
|
return this.performTaskWorker('setBaseDcID', dcID);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import {TLDeserialization, TLSerialization} from './tl_utils';
|
|||||||
import CryptoWorker from '../crypto/cryptoworker';
|
import CryptoWorker from '../crypto/cryptoworker';
|
||||||
import AppStorage from '../storage';
|
import AppStorage from '../storage';
|
||||||
import Schema from './schema';
|
import Schema from './schema';
|
||||||
|
|
||||||
import timeManager from './timeManager';
|
import timeManager from './timeManager';
|
||||||
import NetworkerFactory from './networkerFactory';
|
import NetworkerFactory from './networkerFactory';
|
||||||
import { logger, LogLevels } from '../logger';
|
import { logger, LogLevels } from '../logger';
|
||||||
@ -30,7 +29,7 @@ import Socket from './transports/websocket';
|
|||||||
|
|
||||||
//console.error('networker included!', new Error().stack);
|
//console.error('networker included!', new Error().stack);
|
||||||
|
|
||||||
type MessageOptions = InvokeApiOptions & Partial<{
|
export type MTMessageOptions = InvokeApiOptions & Partial<{
|
||||||
noResponse: true,
|
noResponse: true,
|
||||||
longPoll: true,
|
longPoll: true,
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ type MessageOptions = InvokeApiOptions & Partial<{
|
|||||||
messageID: string,
|
messageID: string,
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
type Message = InvokeApiOptions & MessageOptions & {
|
export type MTMessage = InvokeApiOptions & MTMessageOptions & {
|
||||||
msg_id: string,
|
msg_id: string,
|
||||||
seq_no: number,
|
seq_no: number,
|
||||||
body?: Uint8Array | number[],
|
body?: Uint8Array | number[],
|
||||||
@ -76,7 +75,7 @@ export default class MTPNetworker {
|
|||||||
private lastServerMessages: Array<string> = [];
|
private lastServerMessages: Array<string> = [];
|
||||||
|
|
||||||
private sentMessages: {
|
private sentMessages: {
|
||||||
[msgID: string]: Message
|
[msgID: string]: MTMessage
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
private pendingMessages: {[msgID: string]: number} = {};
|
private pendingMessages: {[msgID: string]: number} = {};
|
||||||
@ -195,7 +194,7 @@ export default class MTPNetworker {
|
|||||||
return seqNo;
|
return seqNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public wrapMtpCall(method: string, params: any = {}, options: MessageOptions = {}) {
|
public wrapMtpCall(method: string, params: any = {}, options: MTMessageOptions = {}) {
|
||||||
const serializer = new TLSerialization({mtproto: true});
|
const serializer = new TLSerialization({mtproto: true});
|
||||||
|
|
||||||
serializer.storeMethod(method, params);
|
serializer.storeMethod(method, params);
|
||||||
@ -215,7 +214,7 @@ export default class MTPNetworker {
|
|||||||
return this.pushMessage(message, options);
|
return this.pushMessage(message, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public wrapMtpMessage(object: any = {}, options: MessageOptions = {}) {
|
public wrapMtpMessage(object: any = {}, options: MTMessageOptions = {}) {
|
||||||
const serializer = new TLSerialization({mtproto: true});
|
const serializer = new TLSerialization({mtproto: true});
|
||||||
serializer.storeObject(object, 'Object');
|
serializer.storeObject(object, 'Object');
|
||||||
|
|
||||||
@ -424,7 +423,7 @@ export default class MTPNetworker {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleSentEncryptedRequestHTTP(promise: ReturnType<MTPNetworker['sendEncryptedRequest']>, message: Message, noResponseMsgs: string[]) {
|
private handleSentEncryptedRequestHTTP(promise: ReturnType<MTPNetworker['sendEncryptedRequest']>, message: MTMessage, noResponseMsgs: string[]) {
|
||||||
promise
|
promise
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.toggleOffline(false);
|
this.toggleOffline(false);
|
||||||
@ -481,7 +480,7 @@ export default class MTPNetworker {
|
|||||||
seq_no: number,
|
seq_no: number,
|
||||||
body: Uint8Array | number[],
|
body: Uint8Array | number[],
|
||||||
isAPI?: boolean
|
isAPI?: boolean
|
||||||
}, options: MessageOptions = {}) {
|
}, options: MTMessageOptions = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.sentMessages[message.msg_id] = Object.assign(message, options, {
|
this.sentMessages[message.msg_id] = Object.assign(message, options, {
|
||||||
deferred: {resolve, reject}
|
deferred: {resolve, reject}
|
||||||
@ -587,7 +586,7 @@ export default class MTPNetworker {
|
|||||||
|
|
||||||
if(this.pendingResends.length) {
|
if(this.pendingResends.length) {
|
||||||
const resendMsgIDs: Array<string> = this.pendingResends.slice();
|
const resendMsgIDs: Array<string> = this.pendingResends.slice();
|
||||||
const resendOpts: MessageOptions = {
|
const resendOpts: MTMessageOptions = {
|
||||||
noSchedule: true,
|
noSchedule: true,
|
||||||
notContentRelated: true,
|
notContentRelated: true,
|
||||||
messageID: '' // will set in wrapMtpMessage->pushMessage
|
messageID: '' // will set in wrapMtpMessage->pushMessage
|
||||||
@ -706,7 +705,7 @@ export default class MTPNetworker {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var containerSentMessage: Message = {
|
var containerSentMessage: MTMessage = {
|
||||||
msg_id: timeManager.generateID(),
|
msg_id: timeManager.generateID(),
|
||||||
seq_no: this.generateSeqNo(true),
|
seq_no: this.generateSeqNo(true),
|
||||||
container: true,
|
container: true,
|
||||||
@ -776,7 +775,7 @@ export default class MTPNetworker {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendEncryptedRequest(message: Message, options: any = {}) {
|
public sendEncryptedRequest(message: MTMessage, options: any = {}) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
this.log.debug('Send encrypted', message, options, this.authKeyID);
|
this.log.debug('Send encrypted', message, options, this.authKeyID);
|
||||||
|
2
src/types.d.ts
vendored
2
src/types.d.ts
vendored
@ -11,9 +11,11 @@ export type InvokeApiOptions = Partial<{
|
|||||||
singleInRequest: true,
|
singleInRequest: true,
|
||||||
startMaxLength: number,
|
startMaxLength: number,
|
||||||
|
|
||||||
|
prepareTempMessageID: string,
|
||||||
afterMessageID: string,
|
afterMessageID: string,
|
||||||
resultType: string,
|
resultType: string,
|
||||||
|
|
||||||
|
timeout: number,
|
||||||
waitTime: number,
|
waitTime: number,
|
||||||
stopTime: number,
|
stopTime: number,
|
||||||
rawError: any
|
rawError: any
|
||||||
|
Loading…
x
Reference in New Issue
Block a user