Skip to content

Commit

Permalink
fix(avatar): Prefer avatar url from jwt identity.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Aug 26, 2024
1 parent f59d045 commit 00d1693
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
18 changes: 12 additions & 6 deletions conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import {
import {
getLocalParticipant,
getNormalizedDisplayName,
getParticipantByIdOrUndefined,
getVirtualScreenshareParticipantByOwnerId
} from './react/features/base/participants/functions';
import { updateSettings } from './react/features/base/settings/actions';
Expand Down Expand Up @@ -1775,12 +1776,17 @@ export default {
room.addCommandListener(
this.commands.defaults.AVATAR_URL,
(data, from) => {
APP.store.dispatch(
participantUpdated({
conference: room,
id: from,
avatarURL: data.value
}));
const participant = getParticipantByIdOrUndefined(APP.store, from);

// if already set from presence(jwt), skip the command processing
if (!participant?.avatarURL) {
APP.store.dispatch(
participantUpdated({
conference: room,
id: from,
avatarURL: data.value
}));
}
});

room.on(
Expand Down
4 changes: 3 additions & 1 deletion modules/API/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ function initCommands() {
sendAnalytics(createApiEvent('email.changed'));
APP.conference.changeLocalEmail(email);
},
'avatar-url': avatarUrl => {
'avatar-url': avatarUrl => { // @deprecated
console.warn('Using command avatarUrl is deprecated. Use context.user.avatar in the jwt.');

sendAnalytics(createApiEvent('avatar.url.changed'));
APP.conference.changeLocalAvatarUrl(avatarUrl);
},
Expand Down
19 changes: 13 additions & 6 deletions react/features/base/conference/actions.any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
participantSourcesUpdated,
participantUpdated
} from '../participants/actions';
import { getNormalizedDisplayName } from '../participants/functions';
import { getNormalizedDisplayName, getParticipantByIdOrUndefined } from '../participants/functions';
import { IJitsiParticipant } from '../participants/types';
import { toState } from '../redux/functions';
import {
Expand Down Expand Up @@ -277,11 +277,18 @@ function _addConferenceListeners(conference: IJitsiConference, dispatch: IStore[

conference.addCommandListener(
AVATAR_URL_COMMAND,
(data: { value: string; }, id: string) => dispatch(participantUpdated({
conference,
id,
avatarURL: data.value
})));
(data: { value: string; }, id: string) => {
const participant = getParticipantByIdOrUndefined(state, id);

// if already set from presence(jwt), skip the command processing
if (!participant?.avatarURL) {
return dispatch(participantUpdated({
conference,
id,
avatarURL: data.value
}));
}
});
conference.addCommandListener(
EMAIL_COMMAND,
(data: { value: string; }, id: string) => dispatch(participantUpdated({
Expand Down
2 changes: 2 additions & 0 deletions react/features/base/conference/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export function commonUserJoinedHandling(
} else {
const isReplacing = user?.isReplacing();

// the identity and avatar come from jwt and never change in the presence
dispatch(participantJoined({
avatarURL: user.getIdentity()?.user?.avatar,
botType: user.getBotType(),
conference,
id,
Expand Down

0 comments on commit 00d1693

Please sign in to comment.