Skip to content

Commit

Permalink
fix(ChatRoom) refactor handling of participant properties
Browse files Browse the repository at this point in the history
Avoid duplicates.
  • Loading branch information
saghul committed Oct 22, 2024
1 parent fac989a commit 6782e6c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
8 changes: 3 additions & 5 deletions JitsiConferenceEventManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,14 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
this.chatRoomForwarder.forward(XMPPEvents.PHONE_NUMBER_CHANGED,
JitsiConferenceEvents.PHONE_NUMBER_CHANGED);

chatRoom.setParticipantPropertyListener((node, from) => {
const participant = conference.getParticipantById(from);
chatRoom.setParticipantPropertyListener((id, prop, value) => {
const participant = conference.getParticipantById(id);

if (!participant) {
return;
}

participant.setProperty(
node.tagName.substring('jitsi_participant_'.length),
node.value);
participant.setProperty(prop, value);
});

chatRoom.addListener(XMPPEvents.KICKED,
Expand Down
33 changes: 21 additions & 12 deletions modules/xmpp/ChatRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ export default class ChatRoom extends Listenable {
}
}

const participantProperties = new Map();

// after we had fired member or room joined events, lets fire events
// for the rest info we got in presence
for (let i = 0; i < nodes.length; i++) {
Expand Down Expand Up @@ -850,11 +852,24 @@ export default class ChatRoom extends Listenable {
this.eventEmitter.emit(XMPPEvents.PHONE_NUMBER_CHANGED);
break;
}
default:
this.processNode(node, from);
default: {
if (node.tagName.startsWith('jitsi_participant_')) {
participantProperties
.set(node.tagName.substring('jitsi_participant_'.length), node.value);
} else {
this.processNode(node, from);
}
}
}
}

// All participant properties are in `participantProperties`, call the event handlers now.
const participantId = Strophe.getResourceFromJid(from);

for (const [ key, value ] of participantProperties) {
this.participantPropertyListener(participantId, key, value);
}

// Trigger status message update if necessary
if (hasStatusUpdate) {
this.eventEmitter.emit(
Expand Down Expand Up @@ -915,17 +930,11 @@ export default class ChatRoom extends Listenable {
// make sure we catch all errors coming from any handler
// otherwise we can remove the presence handler from strophe
try {
let tagHandlers = this.presHandlers[node.tagName];

if (node.tagName.startsWith('jitsi_participant_')) {
tagHandlers = [ this.participantPropertyListener ];
}
const tagHandlers = this.presHandlers[node.tagName] ?? [];

if (tagHandlers) {
tagHandlers.forEach(handler => {
handler(node, Strophe.getResourceFromJid(from), from);
});
}
tagHandlers.forEach(handler => {
handler(node, Strophe.getResourceFromJid(from), from);
});
} catch (e) {
logger.error(`Error processing:${node.tagName} node.`, e);
}
Expand Down

0 comments on commit 6782e6c

Please sign in to comment.