Skip to content

Commit

Permalink
feat: refresh stored names when list of participants change
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Jun 24, 2024
1 parent cb2ec77 commit b48aa43
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/assemblies/inbox/InboxMessaging.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import {
import {
JID,
Room,
ParticipantInfo,
SendMessageRequest,
SendMessageRequestBody
} from "@prose-im/prose-sdk-js";
Expand Down Expand Up @@ -485,6 +486,13 @@ export default {
Store.$inbox.trimMessages(oldValue.id, ROOM_TRIM_MESSAGES_RETAIN);
}
}
},

"room.participants": {
handler(newValue: Array<ParticipantInfo>) {
// Re-register global participant names
this.registerGlobalParticipantNames(newValue);
}
}
},

Expand Down Expand Up @@ -635,7 +643,8 @@ export default {
runtime.MessagingStore.flush();

// Register global names
this.registerGlobalNames();
this.registerGlobalSelfName();
this.registerGlobalParticipantNames();

// Identify all parties
this.identifyAllParties(runtime);
Expand Down Expand Up @@ -719,7 +728,7 @@ export default {
}
},

registerGlobalNames(): void {
registerGlobalSelfName(): void {
const roomId = this.room?.id || null;

if (roomId !== null) {
Expand All @@ -730,13 +739,21 @@ export default {
this.selfName,
InboxNameOrigin.Global
);
}
},

registerGlobalParticipantNames(
participants?: Array<ParticipantInfo>
): void {
const roomId = this.room?.id || null;

if (roomId !== null) {
// Register participant names
// Notice: those names are preferred over the per-message names, since \
// they are guaranteed to be always up-to-date. Those are defined \
// secondly since they may overwrite per-message names, which is \
// desired.
this.room?.participants.forEach(member => {
(participants || this.room?.participants)?.forEach(member => {
if (member.jid) {
Store.$inbox.setName(
roomId,
Expand Down

0 comments on commit b48aa43

Please sign in to comment.