Skip to content

Commit 587be45

Browse files
committed
fix(mam): normalize reactor identifiers for consistent message reactions
1 parent 201cefe commit 587be45

File tree

1 file changed

+15
-5
lines changed
  • packages/fluux-sdk/src/core/modules

1 file changed

+15
-5
lines changed

packages/fluux-sdk/src/core/modules/MAM.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,12 @@ export class MAM extends BaseModule {
338338
const { complete, rsm } = this.parseMAMResponse(response)
339339

340340
// Apply modifications to collected messages (full JID comparison for rooms)
341-
const unresolved = this.applyModifications(collectedMessages, modifications, (msg, from) => msg.from === from)
341+
// normalizeReactor extracts nick from full MUC JID for consistent reactor identifiers
342+
const unresolved = this.applyModifications(
343+
collectedMessages, modifications,
344+
(msg, from) => msg.from === from,
345+
(from) => getResource(from) || from
346+
)
342347

343348
// Emit modifications targeting messages already in the store (from prior queries/cache)
344349
this.emitUnresolvedRoomModifications(roomJid, unresolved)
@@ -1099,7 +1104,8 @@ export class MAM extends BaseModule {
10991104
private applyModifications<T extends Message | RoomMessage>(
11001105
messages: T[],
11011106
modifications: MAMModifications,
1102-
senderMatches: (msg: T, from: string) => boolean
1107+
senderMatches: (msg: T, from: string) => boolean,
1108+
normalizeReactor?: (from: string) => string
11031109
): UnresolvedModifications {
11041110
const unresolved: UnresolvedModifications = {
11051111
retractions: [],
@@ -1160,14 +1166,18 @@ export class MAM extends BaseModule {
11601166
for (const reaction of modifications.reactions) {
11611167
const target = messages.find(m => m.id === reaction.targetId || m.stanzaId === reaction.targetId)
11621168
if (target) {
1169+
// Normalize reactor identifier (e.g., extract nick from full MUC JID)
1170+
// to stay consistent with how the store identifies reactors for live reactions
1171+
const reactorId = normalizeReactor ? normalizeReactor(reaction.from) : reaction.from
1172+
11631173
// Initialize reactions object if not present
11641174
if (!target.reactions) {
11651175
target.reactions = {}
11661176
}
11671177

11681178
// Remove this user from all existing reactions on this message
11691179
for (const emoji of Object.keys(target.reactions)) {
1170-
target.reactions[emoji] = target.reactions[emoji].filter(jid => jid !== reaction.from)
1180+
target.reactions[emoji] = target.reactions[emoji].filter(id => id !== reactorId)
11711181
if (target.reactions[emoji].length === 0) {
11721182
delete target.reactions[emoji]
11731183
}
@@ -1178,8 +1188,8 @@ export class MAM extends BaseModule {
11781188
if (!target.reactions[emoji]) {
11791189
target.reactions[emoji] = []
11801190
}
1181-
if (!target.reactions[emoji].includes(reaction.from)) {
1182-
target.reactions[emoji].push(reaction.from)
1191+
if (!target.reactions[emoji].includes(reactorId)) {
1192+
target.reactions[emoji].push(reactorId)
11831193
}
11841194
}
11851195

0 commit comments

Comments
 (0)