Skip to content
Snippets Groups Projects
Unverified Commit 3e2d7008 authored by Matheus Barbosa Silva's avatar Matheus Barbosa Silva Committed by GitHub
Browse files

fix: avatar is reset in the UI when username is changed (#29685)

parent ca8d94b9
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
---
fix: Avatar is reset in the UI when username is changed
......@@ -49,6 +49,16 @@ export async function saveUserIdentity({ _id, name: rawName, username: rawUserna
// if coming from old username, update all references
if (previousUsername) {
if (usernameChanged && typeof rawUsername !== 'undefined') {
const fileStore = FileUpload.getStore('Avatars');
const previousFile = await fileStore.model.findOneByName(previousUsername);
const file = await fileStore.model.findOneByName(username);
if (file) {
await fileStore.model.deleteFile(file._id);
}
if (previousFile) {
await fileStore.model.updateFileNameById(previousFile._id, username);
}
await Messages.updateAllUsernamesByUserId(user._id, username);
await Messages.updateUsernameOfEditByUserId(user._id, username);
......@@ -64,16 +74,6 @@ export async function saveUserIdentity({ _id, name: rawName, username: rawUserna
await Subscriptions.setUserUsernameByUserId(user._id, username);
await LivechatDepartmentAgents.replaceUsernameOfAgentByUserId(user._id, username);
const fileStore = FileUpload.getStore('Avatars');
const previousFile = await fileStore.model.findOneByName(previousUsername);
const file = await fileStore.model.findOneByName(username);
if (file) {
await fileStore.model.deleteFile(file._id);
}
if (previousFile) {
await fileStore.model.updateFileNameById(previousFile._id, username);
}
}
// update other references if either the name or username has changed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment