Skip to content

Commit

Permalink
fix: Convert actor type and id in federated signaling messages
Browse files Browse the repository at this point in the history
The "participants->update" signaling message provides the actor type and
id of the participants from the point of view of the host server.
However, when received by a federated participant, those values need to
be converted to the point of view of the federated server.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jul 31, 2024
1 parent cf60b91 commit 3c72fcf
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/utils/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { t } from '@nextcloud/l10n'
import {
generateOcsUrl,
generateUrl,
getBaseUrl,
} from '@nextcloud/router'

import CancelableRequest from './cancelableRequest.js'
import { PARTICIPANT } from '../constants.js'
import { ATTENDEE, PARTICIPANT } from '../constants.js'
import { EventBus } from '../services/EventBus.js'
import { rejoinConversation } from '../services/participantsService.js'
import { pullSignalingMessages } from '../services/signalingService.js'
Expand Down Expand Up @@ -1499,6 +1500,26 @@ Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) {
console.error('Unknown room participant event', data)
}
} else {
// Convert participant data in federated conversations
if (this.settings.federation?.nextcloudServer) {
for (let i = 0; i < data.event.update.users.length; i++) {
const user = data.event.update.users[i]
if (user.actorType === ATTENDEE.ACTOR_TYPE.USERS) {
user.actorType = ATTENDEE.ACTOR_TYPE.FEDERATED_USERS
user.actorId = user.actorId + '@' + this.settings.federation.nextcloudServer
} else if (user.actorType === ATTENDEE.ACTOR_TYPE.FEDERATED_USERS
&& (user.actorId.endsWith('@' + getBaseUrl())
|| user.actorId.endsWith('@' + getBaseUrl().replace('https://', ''))
)) {
let indexOfDomain = user.actorId.indexOf('@' + getBaseUrl())
if (indexOfDomain < 0) {
indexOfDomain = user.actorId.indexOf('@' + getBaseUrl().replace('https://', ''))
}
user.actorType = ATTENDEE.ACTOR_TYPE.USERS
user.actorId = user.actorId.substring(0, indexOfDomain)
}
}
}
// With updated user list
this._trigger('usersChanged', [data.event.update.users || []])
}
Expand Down

0 comments on commit 3c72fcf

Please sign in to comment.