Skip to content

Commit 691e7a5

Browse files
committed
Merge branch 'master' of https://github.com/morethanwords/tweb
2 parents a28d50e + 4efbdb0 commit 691e7a5

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

‎src/lib/appManagers/appMessagesManager.ts‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,7 @@ export class AppMessagesManager extends AppManager {
32993299

33003300
delete this.pendingByRandomId[randomId];
33013301
this.deleteMessageFromStorage(storage, tempId);
3302+
this.deletePendingTopMsg(peerId, tempId);
33023303

33033304
return true;
33043305
}
@@ -3343,6 +3344,12 @@ export class AppMessagesManager extends AppManager {
33433344
return outDialogs;
33443345
} */
33453346

3347+
private deletePendingTopMsg(peerId: PeerId, id: number) {
3348+
if(this.pendingTopMsgs[peerId] === id) {
3349+
delete this.pendingTopMsgs[peerId];
3350+
}
3351+
}
3352+
33463353
public async fillConversations(folderId = GLOBAL_FOLDER_ID): Promise<void> {
33473354
const middleware = this.middleware.get();
33483355
while(!this.dialogsStorage.isDialogsLoaded(folderId)) {
@@ -4564,11 +4571,11 @@ export class AppMessagesManager extends AppManager {
45644571
return;
45654572
}
45664573

4567-
if(!threadOrSavedId) {
4568-
this.flushStoragesByPeerId(peerId);
4569-
}
45704574

45714575
if(justClear) {
4576+
if(!threadOrSavedId) {
4577+
this.flushStoragesByPeerId(peerId);
4578+
}
45724579
this.rootScope.dispatchEvent('dialog_flush', {peerId, dialog: this.getDialogOnly(peerId)});
45734580
} else {
45744581
const key = this.getTypingKey(peerId, threadOrSavedId);
@@ -4588,7 +4595,7 @@ export class AppMessagesManager extends AppManager {
45884595
});
45894596
}
45904597

4591-
private flushStoragesByPeerId(peerId: PeerId) {
4598+
public flushStoragesByPeerId(peerId: PeerId) {
45924599
[
45934600
this.historiesStorage[peerId],
45944601
this.searchesStorage[peerId],
@@ -7900,7 +7907,11 @@ export class AppMessagesManager extends AppManager {
79007907
if(historyUpdated.msgs.has(dialog.top_message)) {
79017908
const historyStorage = this.getHistoryStorage(dialog.peerId, _isDialog ? undefined : getDialogKey(dialog));
79027909
const slice = historyStorage.history.first;
7903-
if(slice.isEnd(SliceEnd.Bottom) && slice.length) {
7910+
7911+
// If there are some temporary messages in the history, we still want to reload the dialog in case it was fully deleted (e.g. from other client)
7912+
const hasMessages = !!slice.filter(id => !isTempId(id)).length;
7913+
7914+
if(slice.isEnd(SliceEnd.Bottom) && hasMessages) {
79047915
const mid = slice[0];
79057916
const message = this.getMessageByPeer(peerId, mid);
79067917
this.setDialogTopMessage(message, dialog);
@@ -8317,6 +8328,13 @@ export class AppMessagesManager extends AppManager {
83178328
if(randomIds.size === 0) {
83188329
this.typingBotforumMessages.delete(peerId);
83198330
}
8331+
8332+
const pendingMessage = this.pendingByRandomId[randomId];
8333+
if(pendingMessage) {
8334+
const storages: HistoryStorage[] = [this.getHistoryStorage(peerId), this.getHistoryStorage(peerId, pendingMessage.threadId)]
8335+
.filter(Boolean);
8336+
storages.forEach(storage => storage.history?.delete(pendingMessage.tempId))
8337+
}
83208338
}
83218339

83228340
public mutePeer(options: {peerId: PeerId, muteUntil: number, threadId?: number}) {
@@ -8422,6 +8440,7 @@ export class AppMessagesManager extends AppManager {
84228440
this.rootScope.dispatchEvent('messages_pending');
84238441

84248442
delete this.pendingByRandomId[randomId];
8443+
this.deletePendingTopMsg(peerId, tempId);
84258444

84268445
this.finalizePendingMessageCallbacks(storage, tempId, finalMessage);
84278446

‎src/lib/storages/dialogs.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,10 @@ export default class DialogsStorage extends AppManager {
11341134
this.clearDialogFromState(dialog, keepLocal);
11351135
}
11361136

1137+
if(!topicOrSavedId) {
1138+
this.appMessagesManager.flushStoragesByPeerId(peerId);
1139+
}
1140+
11371141
return foundDialog;
11381142
}
11391143

0 commit comments

Comments
 (0)