Skip to content
Snippets Groups Projects
Commit c6cd46d7 authored by Zach Auclair's avatar Zach Auclair
Browse files

fix(message-ui/edit-info): handle the case where editor can't be found

This uses a special "?" character that is understood by the /avatar/
route and will be treated specially. This change also adds url
encoding/decoding around username usage via the url for the avatar.
parent 60e4620b
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@
path = Meteor.absoluteUrl()
else
path = '/'
return "#{path}avatar/#{username}.jpg?_dc=#{random}"
"#{path}avatar/#{encodeURIComponent(username)}.jpg?_dc=#{random}"
Blaze.registerHelper 'avatarUrlFromUsername', getAvatarUrlFromUsername
......
......@@ -54,7 +54,17 @@ Template.message.helpers
moment(@ets).format('LL hh:mma') #TODO profile pref for 12hr/24hr clock?
editedBy: ->
return "" unless wasEdited(@)
Meteor.users.findOne(@editBy ? Meteor.userId())?.username
# try to return the username of the editor,
# otherwise a special "?" character that will be
# rendered as a special avatar
if @editBy
user = Meteor.users.findOne(@editBy)
if user?
user.username
else
"?"
else
"?"
pinned: ->
return this.pinned
canEdit: ->
......
......@@ -30,13 +30,14 @@ Meteor.startup ->
WebApp.connectHandlers.use '/avatar/', (req, res, next) ->
this.params =
username: req.url.replace(/^\//, '').replace(/\?.*$/, '')
username: decodeURIComponent(req.url.replace(/^\//, '').replace(/\?.*$/, ''))
if this.params.username[0] isnt '@'
file = RocketChatFileAvatarInstance.getFileWithReadStream this.params.username
else
this.params.username = this.params.username.replace '@', ''
#console.log "[avatar] checking username #{@params.username} (derrived from path #{req.url})"
res.setHeader 'Content-Disposition', 'inline'
if not file?
......@@ -45,19 +46,22 @@ Meteor.startup ->
colors = ['#F44336','#E91E63','#9C27B0','#673AB7','#3F51B5','#2196F3','#03A9F4','#00BCD4','#009688','#4CAF50','#8BC34A','#CDDC39','#FFC107','#FF9800','#FF5722','#795548','#9E9E9E','#607D8B']
username = this.params.username.replace('.jpg', '')
position = username.length % colors.length
color = colors[position]
username = username.replace(/[^A-Za-z0-9]/g, '.').replace(/\.+/g, '.').replace(/(^\.)|(\.$)/g, '')
usernameParts = username.split('.')
username = @params.username.replace('.jpg', '')
color = ''
initials = ''
if usernameParts.length > 1
initials = _.first(usernameParts)[0] + _.last(usernameParts)[0]
if username is "?"
color = "#000"
initials = username
else
initials = username.replace(/[^A-Za-z0-9]/g, '').substr(0, 2)
initials = initials.toUpperCase()
position = username.length % colors.length
color = colors[position]
username = username.replace(/[^A-Za-z0-9]/g, '.').replace(/\.+/g, '.').replace(/(^\.)|(\.$)/g, '')
usernameParts = username.split('.')
initials = if usernameParts.length > 1
_.first(usernameParts)[0] + _.last(usernameParts)[0]
else
username.replace(/[^A-Za-z0-9]/g, '').substr(0, 2)
initials = initials.toUpperCase()
svg = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
......
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