Skip to content

Commit

Permalink
Merge pull request RocketChat#36 from WideChat/ear_real_user_name_invite
Browse files Browse the repository at this point in the history
Ear real user name invite
  • Loading branch information
ear-dev authored Apr 16, 2019
2 parents bfa55b3 + 1951c11 commit bc168f1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/rocketchat-api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ RocketChat.API.v1.addRoute('invite.email', { authRequired: true }, {
return RocketChat.API.v1.failure('Invalid email address');
}

const result = Meteor.runAsUser(this.userId, () => Meteor.call('sendInvitationEmail', [this.bodyParams.email], this.bodyParams.language));
const result = Meteor.runAsUser(this.userId, () => Meteor.call('sendInvitationEmail', [this.bodyParams.email], this.bodyParams.language, this.bodyParams.realname));
if (result.indexOf(this.bodyParams.email) >= 0) {
return RocketChat.API.v1.success();
} else {
Expand All @@ -210,7 +210,7 @@ RocketChat.API.v1.addRoute('invite.sms', { authRequired: true }, {
return RocketChat.API.v1.failure('Invalid number');
}

const result = Meteor.runAsUser(this.userId, () => Meteor.call('sendInvitationSMS', [phone], this.bodyParams.language));
const result = Meteor.runAsUser(this.userId, () => Meteor.call('sendInvitationSMS', [phone], this.bodyParams.language, this.bodyParams.realname));
if (result.indexOf(phone) >= 0) {
return RocketChat.API.v1.success();
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1540,11 +1540,11 @@
"invisible": "invisible",
"Invisible": "Invisible",
"Invitation": "Invitation",
"Invitation_Email_Default":"Hi, a friend (username=[Username]) has invited you to chat on [Site_Name]. Click [Invite_Link] to respond.",
"Invitation_Email_Default":"Hi, your friend [Username] has invited you to chat on [Site_Name]. Click [Invite_Link] to respond.",
"Invitation_Email_Description": "You may use the following placeholders: <br/><ul><li>[email] for the recipient email.</li><li>[Site_Name] and [Site_URL] for the Application Name and URL respectively. [Invite_Link] for Invitation dynamic link, and [Username] for the user who is sending the invite.</li></ul>",
"Invitation_Subject": "Invitation Subject",
"Invitation_Subject_Default": "Invitation to chat from your friend [Username] on [Site_Name]",
"Invitation_SMS_Default_Body": "Hi, a friend (username=[Username]) has invited you to chat on Viasat Connect. Click [Invite_Link] to respond.",
"Invitation_SMS_Default_Body": "Hi, your friend [name] has invited you to chat on Viasat Connect. Click [Invite_Link] to respond.",
"Invite_user_to_join_channel": "Invite one user to join this channel",
"Invite_user_to_join_channel_all_from": "Invite all users from [#channel] to join this channel",
"Invite_user_to_join_channel_all_to": "Invite all users from this channel to join [#channel]",
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-i18n/i18n/es.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,11 +1428,11 @@
"invisible": "invisible",
"Invisible": "Invisible",
"Invitation": "Invitación",
"Invitation_Email_Default":"Hola, un amigo (username = [Username]) lo ha invitado a chatear en [Site_Name]. Haga clic en [Invite_Link] para responder.",
"Invitation_Email_Default":"Hola, su amigo [Username] lo ha invitado a chatear en [Site_Name]. Haga clic en [Invite_Link] para responder.",
"Invitation_Email_Description": "Es posible utilizar los siguientes marcadores: <br/><ul><li> [email] para el correo electrónico del destinatario. </li><li> [Site_Name] y [Site_URL] para el nombre de la aplicación y la URL, respectivamente. [Invite_Link] para el enlace dinámico de Invitación, y [Username] para el usuario que envía la invitación.</li></ul>",
"Invitation_Subject": "Invitation Subject",
"Invitation_Subject_Default": "Invitación al chat de su amigo [Username] en [Site_Name]",
"Invitation_SMS_Default_Body": "Hola, un amigo (username = [Username]) lo ha invitado a chatear en [Site_Name]. Haga clic en [Invite_Link] para responder.",
"Invitation_SMS_Default_Body": "Hola, su amigo [name] lo ha invitado a chatear en [Site_Name]. Haga clic en [Invite_Link] para responder.",
"Invite_user_to_join_channel": "Invitar a un usuario a unirse a este canal",
"Invite_user_to_join_channel_all_from": "Invitar a todos los usuarios de [#channell] para unirse a este canal",
"Invite_user_to_join_channel_all_to": "Invitar a todos los usuarios de este canal a unirse a [#channel]",
Expand Down
11 changes: 9 additions & 2 deletions packages/rocketchat-lib/server/methods/sendInvitationEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Meteor.startup(() => {
});

Meteor.methods({
sendInvitationEmail(emails, language) {
sendInvitationEmail(emails, language, realname) {
check(emails, [String]);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
Expand All @@ -24,6 +24,13 @@ Meteor.methods({
}
const validEmails = emails.filter(Mailer.checkAddressFormat);

let inviter;
if (!realname) {
inviter = Meteor.user().username;
} else {
inviter = realname;
}

const subject = RocketChat.settings.get('Invitation_Subject');
return validEmails.filter((email) => {
try {
Expand All @@ -35,7 +42,7 @@ Meteor.methods({
data: {
email,
Invite_Link:Meteor.runAsUser(Meteor.userId(), () => Meteor.call('getInviteLink')),
Username:Meteor.user().username,
Username:inviter,
Avatar_Link:`${ RocketChat.settings.get('Site_Url').slice(0, -1) }${ getAvatarUrlFromUsername(Meteor.user().username) }`,
},
lng: language,
Expand Down
12 changes: 10 additions & 2 deletions packages/rocketchat-lib/server/methods/sendInvitationSMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import _ from 'underscore';
const supportedLanguages = ['en', 'es'];

Meteor.methods({
sendInvitationSMS(phones, language) {
sendInvitationSMS(phones, language, realname) {
const twilioService = RocketChat.SMS.getService('twilio');
if (!RocketChat.SMS.enabled || !twilioService) {
throw new Meteor.Error('error-twilio-not-active', 'Twilio service not active', {
Expand Down Expand Up @@ -41,6 +41,14 @@ Meteor.methods({
}
}));
const user = Meteor.user();

let inviter;
if (!realname) {
inviter = user.username;
} else {
inviter = realname;
}

let body;
if (RocketChat.settings.get('Invitation_SMS_Customized')) {
body = RocketChat.settings.get('Invitation_SMS_Customized_Body');
Expand All @@ -53,7 +61,7 @@ Meteor.methods({
lng,
});
}
body = RocketChat.placeholders.replace(body);
body = RocketChat.placeholders.replace(body, { name:inviter });
validPhones.forEach((phone) => {
try {
twilioService.send(messageFrom, phone, body);
Expand Down

0 comments on commit bc168f1

Please sign in to comment.