Browse Source

Fix generating random long

master
Eduard Kuzmenko 3 years ago
parent
commit
c8ceec3c46
  1. 2
      src/helpers/random.ts
  2. 5
      src/layer.d.ts
  3. 33
      src/lib/appManagers/appMessagesManager.ts
  4. 5
      src/lib/mtproto/authorizer.ts
  5. 5
      src/scripts/in/schema_additional_params.json

2
src/helpers/random.ts

@ -16,5 +16,5 @@ export function nextRandomUint(bits: 8 | 16 | 32) {
} }
export function randomLong() { export function randomLong() {
return '' + nextRandomUint(32) + nextRandomUint(32); return '' + nextRandomUint(32) + nextRandomUint(32) % 0xFFFFFF;
} }

5
src/layer.d.ts vendored

@ -856,7 +856,10 @@ export namespace Message {
random_id?: string, random_id?: string,
rReply?: string, rReply?: string,
viaBotId?: number, viaBotId?: number,
clear_history?: boolean clear_history?: boolean,
pending?: boolean,
error?: any,
send?: () => Promise<any>
}; };
export type messageService = { export type messageService = {

33
src/lib/appManagers/appMessagesManager.ts

@ -480,7 +480,7 @@ export class AppMessagesManager {
}; };
} }
const toggleError = (on: any) => { const toggleError = (on: boolean) => {
if(on) { if(on) {
message.error = true; message.error = true;
} else { } else {
@ -525,7 +525,9 @@ export class AppMessagesManager {
} */ } */
//this.log('sendText', message.mid); //this.log('sendText', message.mid);
apiPromise.then((updates: Updates) => { this.pendingAfterMsgs[peerId] = sentRequestOptions;
return apiPromise.then((updates: Updates) => {
//this.log('sendText sent', message.mid); //this.log('sendText sent', message.mid);
//if(is<Updates.updateShortSentMessage>(updates, updates._ === 'updateShortSentMessage')) { //if(is<Updates.updateShortSentMessage>(updates, updates._ === 'updateShortSentMessage')) {
if(updates._ === 'updateShortSentMessage') { if(updates._ === 'updateShortSentMessage') {
@ -579,9 +581,7 @@ export class AppMessagesManager {
delete this.pendingAfterMsgs[peerId]; delete this.pendingAfterMsgs[peerId];
} }
}); });
};
this.pendingAfterMsgs[peerId] = sentRequestOptions;
}
this.beforeMessageSending(message, { this.beforeMessageSending(message, {
isScheduled: !!options.scheduleDate || undefined, isScheduled: !!options.scheduleDate || undefined,
@ -831,7 +831,7 @@ export class AppMessagesManager {
_: 'messageMediaDocument', _: 'messageMediaDocument',
pFlags: {}, pFlags: {},
document: file document: file
} : media; } as MessageMedia.messageMediaDocument : media as any;
const toggleError = (on: boolean) => { const toggleError = (on: boolean) => {
if(on) { if(on) {
@ -888,6 +888,7 @@ export class AppMessagesManager {
this.log('appMessagesManager: sendFile uploaded:', inputFile); this.log('appMessagesManager: sendFile uploaded:', inputFile);
} */ } */
// @ts-ignore
delete message.media.preloader; delete message.media.preloader;
inputFile.name = apiFileName; inputFile.name = apiFileName;
@ -1163,7 +1164,7 @@ export class AppMessagesManager {
const message = this.generateOutgoingMessage(peerId, options); const message = this.generateOutgoingMessage(peerId, options);
const replyToMsgId = options.replyToMsgId ? this.getServerMessageId(options.replyToMsgId) : undefined; const replyToMsgId = options.replyToMsgId ? this.getServerMessageId(options.replyToMsgId) : undefined;
let media; let media: MessageMedia;
switch(inputMedia._) { switch(inputMedia._) {
case 'inputMediaPoll': { case 'inputMediaPoll': {
inputMedia.poll.id = message.id; inputMedia.poll.id = message.id;
@ -1291,7 +1292,9 @@ export class AppMessagesManager {
}, sentRequestOptions); }, sentRequestOptions);
} }
apiPromise.then((updates) => { this.pendingAfterMsgs[peerId] = sentRequestOptions;
return apiPromise.then((updates) => {
if(updates.updates) { if(updates.updates) {
updates.updates.forEach((update: any) => { updates.updates.forEach((update: any) => {
if(update._ === 'updateDraftMessage') { if(update._ === 'updateDraftMessage') {
@ -1308,8 +1311,7 @@ export class AppMessagesManager {
delete this.pendingAfterMsgs[peerId]; delete this.pendingAfterMsgs[peerId];
} }
}); });
this.pendingAfterMsgs[peerId] = sentRequestOptions; };
}
this.beforeMessageSending(message, { this.beforeMessageSending(message, {
isScheduled: !!options.scheduleDate || undefined, isScheduled: !!options.scheduleDate || undefined,
@ -1402,7 +1404,7 @@ export class AppMessagesManager {
options.replyToMsgId = options.threadId; options.replyToMsgId = options.threadId;
} }
const message: any = { const message: Message.message = {
_: 'message', _: 'message',
id: this.generateTempMessageId(peerId), id: this.generateTempMessageId(peerId),
from_id: this.generateFromId(peerId), from_id: this.generateFromId(peerId),
@ -5102,17 +5104,18 @@ export class AppMessagesManager {
} }
private handleReleasingMessage(message: MyMessage) { private handleReleasingMessage(message: MyMessage) {
if('media' in message) { const media = (message as Message.message).media;
if(media) {
// @ts-ignore // @ts-ignore
const c = message.media.webpage || message.media; const c = media.webpage || media;
const smth: Photo.photo | MyDocument = c.photo || c.document; const smth: Photo.photo | MyDocument = c.photo || c.document;
if(smth?.file_reference) { if(smth?.file_reference) {
referenceDatabase.deleteContext(smth.file_reference, {type: 'message', peerId: message.peerId, messageId: message.mid}); referenceDatabase.deleteContext(smth.file_reference, {type: 'message', peerId: message.peerId, messageId: message.mid});
} }
if('webpage' in message.media) { if('webpage' in media) {
appWebPagesManager.deleteWebPageFromPending(message.media.webpage, message.mid); appWebPagesManager.deleteWebPageFromPending(media.webpage, message.mid);
} }
} }
} }

5
src/lib/mtproto/authorizer.ts

@ -534,7 +534,8 @@ export class Authorizer {
const newNonceHash1 = (await CryptoWorker.invokeCrypto('sha1-hash', auth.newNonce.concat([1], authKeyAux))).slice(-16); const newNonceHash1 = (await CryptoWorker.invokeCrypto('sha1-hash', auth.newNonce.concat([1], authKeyAux))).slice(-16);
if(!bytesCmp(newNonceHash1, response.new_nonce_hash1)) { if(!bytesCmp(newNonceHash1, response.new_nonce_hash1)) {
throw new Error('[MT] Set_client_DH_params_answer new_nonce_hash1 mismatch'); this.log.error('Set_client_DH_params_answer new_nonce_hash1 mismatch', newNonceHash1, response);
throw new Error('new_nonce_hash1 mismatch');
} }
const serverSalt = bytesXor(auth.newNonce.slice(0, 8), auth.serverNonce.slice(0, 8)); const serverSalt = bytesXor(auth.newNonce.slice(0, 8), auth.serverNonce.slice(0, 8));
@ -591,7 +592,7 @@ export class Authorizer {
this.cached[dcId] = promise; this.cached[dcId] = promise;
return await promise; return await promise;
} catch(err) { } catch(err) {
if(err.originalError === -404 && auth.localTry <= 3) { if(/* err.originalError === -404 && */auth.localTry <= 3) {
return this.sendReqPQ({ return this.sendReqPQ({
dcId: auth.dcId, dcId: auth.dcId,
nonce: new Uint8Array(16).randomize(), nonce: new Uint8Array(16).randomize(),

5
src/scripts/in/schema_additional_params.json

@ -53,7 +53,10 @@
{"name": "is_outgoing", "type": "true"}, {"name": "is_outgoing", "type": "true"},
{"name": "rReply", "type": "string"}, {"name": "rReply", "type": "string"},
{"name": "viaBotId", "type": "number"}, {"name": "viaBotId", "type": "number"},
{"name": "clear_history", "type": "boolean"} {"name": "clear_history", "type": "boolean"},
{"name": "pending", "type": "boolean"},
{"name": "error", "type": "any"},
{"name": "send", "type": "() => Promise<any>"}
] ]
}, { }, {
"predicate": "messageService", "predicate": "messageService",

Loading…
Cancel
Save