Skip to content

Commit

Permalink
Fix infinite loop
Browse files Browse the repository at this point in the history
Fix displaying deleted message in pinned bar
  • Loading branch information
morethanwords committed Nov 8, 2024
1 parent 7af3c67 commit 689ab90
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/lib/appManagers/appMessagesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3058,7 +3058,9 @@ export class AppMessagesManager extends AppManager {
const {mid} = message;

let inserted = true;
if(first.isEnd(SliceEnd.Bottom) && first[0] < mid) {
if(first.isEnd(SliceEnd.Both) && first[0] === undefined) {
searchStorage.history.unshift(mid);
} else if(first.isEnd(SliceEnd.Bottom) && first[0] < mid) {
searchStorage.history.unshift(mid);
} else if(last.isEnd(SliceEnd.Top) && last[last.length - 1] > mid) {
searchStorage.history.push(mid);
Expand Down Expand Up @@ -6588,11 +6590,7 @@ export class AppMessagesManager extends AppManager {
}, storage);
}

delete this.pinnedMessages[this.getPinnedMessagesKey(peerId)];
this.appStateManager.getState().then((state) => {
delete state.hiddenPinnedMessages[peerId];
this.rootScope.dispatchEvent('peer_pinned_messages', {peerId, mids, pinned});
});
this.resetPinnedMessagesCache(peerId, mids, pinned);
});
};

Expand Down Expand Up @@ -8111,6 +8109,7 @@ export class AppMessagesManager extends AppManager {
}

public fetchMessageReplyTo(message: MyMessage) {
message = this.getMessageByPeer(message.peerId, message.mid); // message can come from other thread
if(!message.reply_to) return Promise.resolve(this.generateEmptyMessage(0));
const replyTo = message.reply_to;
if(replyTo._ === 'messageReplyStoryHeader') {
Expand Down Expand Up @@ -8252,6 +8251,10 @@ export class AppMessagesManager extends AppManager {
this.deletedMessages.add(`${deletedPeerId}_${message.mid}`);
}

if((message as Message.message).pFlags.pinned) {
this.resetPinnedMessagesCache(peerId, [mid], false);
}

this.updateMessageRepliesIfNeeded(message, false);

if(!message.pFlags.out && !message.pFlags.is_outgoing && message.pFlags.unread) {
Expand Down Expand Up @@ -8405,6 +8408,14 @@ export class AppMessagesManager extends AppManager {
}
}

private resetPinnedMessagesCache(peerId: PeerId, mids: number[], pinned: boolean) {
delete this.pinnedMessages[this.getPinnedMessagesKey(peerId)];
this.appStateManager.getState().then((state) => {
delete state.hiddenPinnedMessages[peerId];
this.rootScope.dispatchEvent('peer_pinned_messages', {peerId, mids, pinned});
});
}

private getMessagesFromMap<T extends Map<any, any>>(map: T) {
const newMap: Map<Message.message, MapValueType<T>> = new Map();
for(const [key, value] of map) {
Expand Down

0 comments on commit 689ab90

Please sign in to comment.