Skip to content

Commit 899d940

Browse files
authored
fix: address parent message as well if not yet loaded
1 parent 1134c36 commit 899d940

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/thread.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,15 @@ export class Thread extends WithSubscriptions {
662662
};
663663

664664
public handleUserUpdated = (event: PipelineEvent) => {
665-
if (!event.user) return;
666-
this.messagePaginator.reflectUserUpdate(event.user);
665+
const { user } = event;
666+
if (!user) return;
667+
this.messagePaginator.reflectUserUpdate(user);
668+
669+
// the parent message might not yet be loaded in channel.messagePaginator
670+
const parent = this.client.messageStore.get(this.id);
671+
if (parent?.user?.id === user.id && parent.user !== user) {
672+
this.client.messageStore.upsert({ ...parent, user });
673+
}
667674
};
668675

669676
// Applies a user ban or deletion to this thread's replies.

‎test/unit/threads.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,30 @@ describe('Threads 2.0', () => {
24122412
thread.unregisterSubscriptions();
24132413
});
24142414

2415+
it('replaces an updated user in the parent message on "user.updated" when no channel paginator holds it', () => {
2416+
const authorId = 'renamed-parent-author';
2417+
const thread = createTestThread({
2418+
parentMessageOverrides: { user: { id: authorId, name: 'Old name' } },
2419+
});
2420+
subscribeThread(thread);
2421+
expect(channel.messagePaginator.getItem(thread.id)).to.be.undefined;
2422+
expect(thread.state.getLatestValue().parentMessage.user?.name).to.equal(
2423+
'Old name',
2424+
);
2425+
2426+
client.dispatchEvent({
2427+
type: 'user.updated',
2428+
user: { id: authorId, name: 'New name' },
2429+
created_at: nowNs(),
2430+
});
2431+
2432+
expect(thread.state.getLatestValue().parentMessage.user?.name).to.equal(
2433+
'New name',
2434+
);
2435+
2436+
thread.unregisterSubscriptions();
2437+
});
2438+
24152439
it('applies "reaction.new" to a reply the thread paginator already holds', () => {
24162440
const thread = createTestThread();
24172441
subscribeThread(thread);

0 commit comments

Comments
 (0)