Meteor.methods setAvatarFromService: (dataURI, contentType, service) -> if not Meteor.userId() throw new Meteor.Error('invalid-user', "[methods] setAvatarFromService -> Invalid user") console.log '[methods] setAvatarFromService -> '.green, 'userId:', Meteor.userId(), 'contentType:', contentType, 'service:', service user = Meteor.user() if service is 'initials' RocketChat.models.Users.setAvatarOrigin user._id, service return {image, contentType} = RocketChatFile.dataURIParse dataURI rs = RocketChatFile.bufferToStream new Buffer(image, 'base64') ws = RocketChatFileAvatarInstance.createWriteStream "#{user.username}.jpg", contentType ws.on 'end', Meteor.bindEnvironment -> Meteor.setTimeout -> RocketChat.models.Users.setAvatarOrigin user._id, service RocketChat.Notifications.notifyAll 'updateAvatar', {username: user.username} , 500 rs.pipe(ws) return DDPRateLimiter.addRule type: 'method' name: 'setAvatarFromService' userId: -> return true , 1, 60000