Skip to content
Snippets Groups Projects
Commit d4d3f164 authored by Fahad Alduraibi's avatar Fahad Alduraibi
Browse files

Fixed indentation and added unicode support

The avatar image move need to only be done if a previous username exists. 
Also we need `encodeURIComponent` to support names in unicode.
parent b023db6f
No related branches found
No related tags found
No related merge requests found
......@@ -45,13 +45,13 @@ RocketChat._setUsername = (userId, username) ->
RocketChat.models.Subscriptions.setUserUsernameByUserId user._id, username
RocketChat.models.Subscriptions.setNameForDirectRoomsWithOldName previousUsername, username
rs = RocketChatFileAvatarInstance.getFileWithReadStream("#{previousUsername}.jpg")
if rs?
RocketChatFileAvatarInstance.deleteFile "#{username}.jpg"
ws = RocketChatFileAvatarInstance.createWriteStream "#{username}.jpg", rs.contentType
ws.on 'end', Meteor.bindEnvironment ->
RocketChatFileAvatarInstance.deleteFile "#{previousUsername}.jpg"
rs.readStream.pipe(ws)
rs = RocketChatFileAvatarInstance.getFileWithReadStream(encodeURIComponent("#{previousUsername}.jpg"))
if rs?
RocketChatFileAvatarInstance.deleteFile encodeURIComponent("#{username}.jpg")
ws = RocketChatFileAvatarInstance.createWriteStream encodeURIComponent("#{username}.jpg"), rs.contentType
ws.on 'end', Meteor.bindEnvironment ->
RocketChatFileAvatarInstance.deleteFile encodeURIComponent("#{previousUsername}.jpg")
rs.readStream.pipe(ws)
# Set new username
RocketChat.models.Users.setUsername user._id, username
......
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