Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve avatar download issue on setUsername by refining service selection logic #33193

Merged
merged 9 commits into from
Sep 17, 2024
5 changes: 5 additions & 0 deletions .changeset/small-crabs-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed avatar blob image setting in setUserAvatar method by correcting service handling logic.
23 changes: 11 additions & 12 deletions apps/meteor/app/lib/server/functions/setUsername.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ export const _setUsername = async function (userId: string, u: string, fullUser:
// Set new username*
await Users.setUsername(user._id, username);
user.username = username;

if (!previousUsername && settings.get('Accounts_SetDefaultAvatar') === true) {
// eslint-disable-next-line @typescript-eslint/ban-types
const avatarSuggestions = (await getAvatarSuggestionForUser(user)) as {};
let gravatar;
for await (const service of Object.keys(avatarSuggestions)) {
const avatarData = avatarSuggestions[+service as keyof typeof avatarSuggestions];
const avatarSuggestions = await getAvatarSuggestionForUser(user);
let avatarData;
let serviceName = 'gravatar';

for (const service of Object.keys(avatarSuggestions)) {
avatarData = avatarSuggestions[service];
if (service !== 'gravatar') {
// eslint-disable-next-line dot-notation
await setUserAvatar(user, avatarData['blob'], avatarData['contentType'], service);
gravatar = null;
serviceName = service;
break;
}
gravatar = avatarData;
}
if (gravatar != null) {
// eslint-disable-next-line dot-notation
await setUserAvatar(user, gravatar['blob'], gravatar['contentType'], 'gravatar');

if (avatarData) {
await setUserAvatar(user, avatarData.blob, avatarData.contentType, serviceName);
}
}

Expand Down
Loading