Pending message fixes:
Fix poll voting Fix message editing
This commit is contained in:
parent
2ddc209ee5
commit
f249f7b82b
@ -1,13 +1,13 @@
|
|||||||
import appPollsManager, { PollResults, Poll } from "../lib/appManagers/appPollsManager";
|
|
||||||
import { RichTextProcessor } from "../lib/richtextprocessor";
|
|
||||||
import { findUpClassName, cancelEvent } from "../lib/utils";
|
|
||||||
import appSidebarRight from "./sidebarRight";
|
|
||||||
import appImManager from "../lib/appManagers/appImManager";
|
|
||||||
import serverTimeManager from "../lib/mtproto/serverTimeManager";
|
|
||||||
import { ripple } from "./ripple";
|
|
||||||
import mediaSizes from "../helpers/mediaSizes";
|
import mediaSizes from "../helpers/mediaSizes";
|
||||||
import $rootScope from "../lib/rootScope";
|
|
||||||
import { isTouchSupported } from "../helpers/touchSupport";
|
import { isTouchSupported } from "../helpers/touchSupport";
|
||||||
|
import appImManager from "../lib/appManagers/appImManager";
|
||||||
|
import appPollsManager, { Poll, PollResults } from "../lib/appManagers/appPollsManager";
|
||||||
|
import serverTimeManager from "../lib/mtproto/serverTimeManager";
|
||||||
|
import { RichTextProcessor } from "../lib/richtextprocessor";
|
||||||
|
import $rootScope from "../lib/rootScope";
|
||||||
|
import { cancelEvent, findUpClassName } from "../lib/utils";
|
||||||
|
import { ripple } from "./ripple";
|
||||||
|
import appSidebarRight from "./sidebarRight";
|
||||||
|
|
||||||
let lineTotalLength = 0;
|
let lineTotalLength = 0;
|
||||||
const tailLength = 9;
|
const tailLength = 9;
|
||||||
@ -380,11 +380,17 @@ export default class PollElement extends HTMLElement {
|
|||||||
|
|
||||||
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
|
||||||
// вызывается при изменении одного из перечисленных выше атрибутов
|
// вызывается при изменении одного из перечисленных выше атрибутов
|
||||||
|
console.log('Poll: attributeChangedCallback', name, oldValue, newValue, this.isConnected);
|
||||||
if(name == 'poll-id') {
|
if(name == 'poll-id') {
|
||||||
this.pollID = newValue;
|
this.pollID = newValue;
|
||||||
} else if(name == 'message-id') {
|
} else if(name == 'message-id') {
|
||||||
this.mid = +newValue;
|
this.mid = +newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.mid > 0 && oldValue !== undefined && +oldValue < 0) {
|
||||||
|
this.disconnectedCallback();
|
||||||
|
connectedPolls.push({id: this.pollID, element: this});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
adoptedCallback() {
|
adoptedCallback() {
|
||||||
|
@ -464,7 +464,14 @@ export class AppMessagesManager {
|
|||||||
public pendingTopMsgs: {[peerID: string]: number} = {};
|
public pendingTopMsgs: {[peerID: string]: number} = {};
|
||||||
public sendFilePromise: CancellablePromise<void> = Promise.resolve();
|
public sendFilePromise: CancellablePromise<void> = Promise.resolve();
|
||||||
public tempID = -1;
|
public tempID = -1;
|
||||||
public tempFinalizeCallbacks: any = {};
|
public tempFinalizeCallbacks: {
|
||||||
|
[mid: string]: {
|
||||||
|
[callbackName: string]: Partial<{
|
||||||
|
deferred: CancellablePromise<void>,
|
||||||
|
callback: (mid: number) => Promise<any>
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
} = {};
|
||||||
|
|
||||||
public lastSearchFilter: any = {};
|
public lastSearchFilter: any = {};
|
||||||
public lastSearchResults: any = [];
|
public lastSearchResults: any = [];
|
||||||
@ -663,27 +670,28 @@ export class AppMessagesManager {
|
|||||||
return sendEntites;
|
return sendEntites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public invokeAfterMessageIsSent(messageID: number, callbackName: string, callback: (mid: number) => Promise<any>) {
|
||||||
|
const finalize = this.tempFinalizeCallbacks[messageID] ?? (this.tempFinalizeCallbacks[messageID] = {});
|
||||||
|
const obj = finalize[callbackName] ?? (finalize[callbackName] = {deferred: deferredPromise<void>()});
|
||||||
|
|
||||||
|
obj.callback = callback;
|
||||||
|
|
||||||
|
return obj.deferred;
|
||||||
|
}
|
||||||
|
|
||||||
public editMessage(messageID: number, text: string, options: Partial<{
|
public editMessage(messageID: number, text: string, options: Partial<{
|
||||||
noWebPage: true,
|
noWebPage: true,
|
||||||
newMedia: any
|
newMedia: any
|
||||||
}> = {}) {
|
}> = {}): Promise<void> {
|
||||||
/* if(!this.canEditMessage(messageID)) {
|
/* if(!this.canEditMessage(messageID)) {
|
||||||
return Promise.reject({type: 'MESSAGE_EDIT_FORBIDDEN'});
|
return Promise.reject({type: 'MESSAGE_EDIT_FORBIDDEN'});
|
||||||
} */
|
} */
|
||||||
|
|
||||||
if(messageID < 0) {
|
if(messageID < 0) {
|
||||||
if(this.tempFinalizeCallbacks[messageID] === undefined) {
|
return this.invokeAfterMessageIsSent(messageID, 'edit', (mid) => {
|
||||||
this.tempFinalizeCallbacks[messageID] = {}
|
this.log('invoke editMessage callback', mid);
|
||||||
}
|
return this.editMessage(mid, text, options);
|
||||||
|
|
||||||
const promise = new Promise((resolve, reject) => {
|
|
||||||
this.tempFinalizeCallbacks[messageID].edit = (mid: number) => {
|
|
||||||
this.log('invoke callback', mid)
|
|
||||||
this.editMessage(mid, text).then(resolve, reject);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let entities: any[];
|
let entities: any[];
|
||||||
@ -4010,12 +4018,15 @@ export class AppMessagesManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public finalizePendingMessageCallbacks(tempID: number, mid: number) {
|
public finalizePendingMessageCallbacks(tempID: number, mid: number) {
|
||||||
var callbacks = this.tempFinalizeCallbacks[tempID];
|
const callbacks = this.tempFinalizeCallbacks[tempID];
|
||||||
this.log.warn(callbacks, tempID);
|
this.log.warn(callbacks, tempID);
|
||||||
if(callbacks !== undefined) {
|
if(callbacks !== undefined) {
|
||||||
callbacks.forEach((callback: any) => {
|
for(const name in callbacks) {
|
||||||
callback(mid);
|
const {deferred, callback} = callbacks[name];
|
||||||
});
|
this.log(`finalizePendingMessageCallbacks: will invoke ${name} callback`);
|
||||||
|
callback(mid).then(deferred.resolve, deferred.reject);
|
||||||
|
}
|
||||||
|
|
||||||
delete this.tempFinalizeCallbacks[tempID];
|
delete this.tempFinalizeCallbacks[tempID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ class AppPollsManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendVote(mid: number, optionIDs: number[]) {
|
public sendVote(mid: number, optionIDs: number[]): Promise<void> {
|
||||||
const message = appMessagesManager.getMessage(mid);
|
const message = appMessagesManager.getMessage(mid);
|
||||||
const poll: Poll = message.media.poll;
|
const poll: Poll = message.media.poll;
|
||||||
|
|
||||||
@ -170,6 +170,13 @@ class AppPollsManager {
|
|||||||
const inputPeer = appPeersManager.getInputPeerByID(message.peerID);
|
const inputPeer = appPeersManager.getInputPeerByID(message.peerID);
|
||||||
const messageID = message.id;
|
const messageID = message.id;
|
||||||
|
|
||||||
|
if(mid < 0) {
|
||||||
|
return appMessagesManager.invokeAfterMessageIsSent(mid, 'sendVote', (mid) => {
|
||||||
|
this.log('invoke sendVote callback');
|
||||||
|
return this.sendVote(mid, optionIDs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return apiManager.invokeApi('messages.sendVote', {
|
return apiManager.invokeApi('messages.sendVote', {
|
||||||
peer: inputPeer,
|
peer: inputPeer,
|
||||||
msg_id: messageID,
|
msg_id: messageID,
|
||||||
|
Loading…
Reference in New Issue
Block a user