Skip to content
Snippets Groups Projects
Commit 3fe5ae9c authored by Sven Mueller's avatar Sven Mueller
Browse files

Code review fixes

* Client-side showUserInfo is no longer cleared
* Server-side now handles empty messages
* Added error message if username or message are empty
parent a81ebed4
No related branches found
No related tags found
No related merge requests found
RocketChat.slashCommands.add 'msg', (command, params, item) -> RocketChat.slashCommands.add 'msg', null,
trimmedParams = params.trim()
username = trimmedParams.slice(0, trimmedParams.indexOf(' '))
if username is ''
return
username = username.replace('@', '')
if Session.get('showUserInfo') is username
Session.set('showUserInfo', null)
,
description: TAPi18n.__ 'Direct_message_someone' description: TAPi18n.__ 'Direct_message_someone'
params: '@username <message>' params: '@username <message>'
{ {
"Direct_message_someone" : "Jemandem eine private Nachricht schicken",
"Username_doesnt_exist" : "Der Benutzername `%s` existiert nicht.", "Username_doesnt_exist" : "Der Benutzername `%s` existiert nicht.",
"Direct_message_someone" : "Jemandem eine private Nachricht schicken" "Username_and_message_must_not_be_empty" : "Benutzername und Nachricht dürfen nicht leer sein."
} }
{ {
"Direct_message_someone" : "Direct message someone",
"Username_doesnt_exist" : "The username `%s` doesn't exist.", "Username_doesnt_exist" : "The username `%s` doesn't exist.",
"Direct_message_someone" : "Direct message someone" "Username_and_message_must_not_be_empty" : "Username and message must not be empty."
} }
...@@ -8,28 +8,35 @@ class Msg ...@@ -8,28 +8,35 @@ class Msg
return return
trimmedParams = params.trim() trimmedParams = params.trim()
separator = trimmedParams.indexOf(' ')
usernameOrig = trimmedParams.slice(0, trimmedParams.indexOf(' ')) user = Meteor.users.findOne Meteor.userId()
message = trimmedParams.slice(trimmedParams.indexOf(' ') + 1)
username = usernameOrig.replace('@', '')
if username is '' if separator is -1
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id()
rid: item.rid
ts: new Date
msg: TAPi18n.__('Username_and_message_must_not_be_empty', null, user.language)
}
return return
user = Meteor.users.findOne Meteor.userId() message = trimmedParams.slice(separator + 1)
msgUser = RocketChat.models.Users.findOneByUsername username
targetUsernameOrig = trimmedParams.slice(0, separator)
targetUsername = targetUsernameOrig.replace('@', '')
targetUser = RocketChat.models.Users.findOneByUsername targetUsername
if not msgUser? if not targetUser?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', { RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {
_id: Random.id() _id: Random.id()
rid: item.rid rid: item.rid
ts: new Date ts: new Date
msg: TAPi18n.__('Username_doesnt_exist', { postProcess: 'sprintf', sprintf: [ usernameOrig ] }, user.language) msg: TAPi18n.__('Username_doesnt_exist', { postProcess: 'sprintf', sprintf: [ targetUsernameOrig ] }, user.language)
} }
return return
rid = Meteor.call 'createDirectMessage', username rid = Meteor.call 'createDirectMessage', targetUsername
msgObject = { _id: Random.id(), rid: rid.rid, msg: message} msgObject = { _id: Random.id(), rid: rid.rid, msg: message}
Meteor.call 'sendMessage', msgObject Meteor.call 'sendMessage', msgObject
......
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