-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mail messages #1733
Merged
Merged
Mail messages #1733
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d694b01
mail messages
marceloschmidt 7f40155
select messages to send e-mail
marceloschmidt c594c23
Merge branch 'develop' into mail-messages
marceloschmidt a3d6215
Added fields for sending mail
marceloschmidt 6ad7f44
Email selected messages
marceloschmidt e33e82b
Remove selection of messages on roomExit
marceloschmidt 34a1147
Set moment locale
marceloschmidt fb31335
Load moment locale for formatting date on mail messages
marceloschmidt 4c1ea21
Fix: don't change locale globally
marceloschmidt 55a31e3
Add authorization for mail messages
marceloschmidt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,7 @@ rocketchat:[email protected] | |
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
rocketchat:[email protected] | ||
|
9 changes: 9 additions & 0 deletions
9
packages/rocketchat-channel-settings-mail-messages/client/lib/startup.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Meteor.startup -> | ||
RocketChat.ChannelSettings.addOption | ||
id: 'mail-messages' | ||
template: 'channelSettingsMailMessages' | ||
|
||
RocketChat.callbacks.add 'roomExit', (mainNode) -> | ||
instance = Blaze.getView($('.messages-box')?[0])?.templateInstance() | ||
instance?.resetSelection(false) | ||
, RocketChat.callbacks.priority.MEDIUM, 'room-exit-mail-messages' |
24 changes: 24 additions & 0 deletions
24
packages/rocketchat-channel-settings-mail-messages/client/stylesheets/mail-messages.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.flex-tab { | ||
.mail-message { | ||
form { | ||
margin-top: 20px; | ||
|
||
.input-line.double-col { | ||
margin-bottom: 20px; | ||
|
||
label { | ||
line-height: 15px; | ||
} | ||
|
||
div { | ||
line-height: 15px; | ||
i.octicon { | ||
font-size: 13px; | ||
opacity: 0.4; | ||
vertical-align: top; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...rocketchat-channel-settings-mail-messages/client/views/channelSettingsMailMessages.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Template.channelSettingsMailMessages.events | ||
'click button.mail-messages': (e, t) -> | ||
Session.set 'channelSettingsMailMessages', Session.get('openedRoom') | ||
RocketChat.TabBar.setTemplate('mailMessagesInstructions') | ||
view = Blaze.getView($('.messages-box')[0]) | ||
view?.templateInstance?().resetSelection?(true) | ||
|
||
Template.channelSettingsMailMessages.onCreated -> | ||
view = Blaze.getView($('.messages-box')[0]) | ||
view?.templateInstance?().resetSelection?(false) |
8 changes: 8 additions & 0 deletions
8
...s/rocketchat-channel-settings-mail-messages/client/views/channelSettingsMailMessages.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<template name="channelSettingsMailMessages"> | ||
<li> | ||
<label>{{_ "Mail_Messages"}}</label> | ||
<div> | ||
<button type="button" class="button primary mail-messages">{{_ "Choose_messages"}}</button> | ||
</div> | ||
</li> | ||
</template> |
79 changes: 79 additions & 0 deletions
79
...es/rocketchat-channel-settings-mail-messages/client/views/mailMessagesInstructions.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
Template.mailMessagesInstructions.helpers | ||
name: -> | ||
return Meteor.user().name | ||
email: -> | ||
return Meteor.user().emails?[0]?.address | ||
roomName: -> | ||
return ChatRoom.findOne(Session.get('openedRoom'))?.name | ||
erroredEmails: -> | ||
return Template.instance()?.erroredEmails.get().join(', ') | ||
|
||
Template.mailMessagesInstructions.events | ||
'click .cancel': (e, t) -> | ||
t.reset() | ||
|
||
'click .send': (e, t) -> | ||
t.$('.error').hide() | ||
$btn = t.$('button.send') | ||
oldBtnValue = $btn.html() | ||
$btn.html(TAPi18n.__('Sending')) | ||
|
||
selectedMessages = $('.messages-box .message.selected') | ||
|
||
error = false | ||
if selectedMessages.length is 0 | ||
t.$('.error-select').show() | ||
error = true | ||
|
||
if t.$('input[name=to]').val().trim() | ||
rfcMailPatternWithName = /^(?:.*<)?([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)(?:>?)$/ | ||
emails = t.$('input[name=to]').val().trim().split(',') | ||
erroredEmails = [] | ||
for email in emails | ||
unless rfcMailPatternWithName.test email.trim() | ||
erroredEmails.push email.trim() | ||
|
||
t.erroredEmails.set erroredEmails | ||
if erroredEmails.length > 0 | ||
t.$('.error-invalid-emails').show() | ||
error = true | ||
else | ||
t.$('.error-missing-to').show() | ||
error = true | ||
|
||
if error | ||
$btn.html(oldBtnValue) | ||
else | ||
data = | ||
rid: Session.get('openedRoom') | ||
to: t.$('input[name=to]').val().trim() | ||
subject: t.$('input[name=subject]').val().trim() | ||
messages: selectedMessages.map((i, message) -> return message.id).toArray() | ||
language: localStorage.getItem('userLanguage') | ||
|
||
Meteor.call 'mailMessages', data, (err, result) -> | ||
$btn.html(oldBtnValue) | ||
if err? | ||
return toastr.error(err.reason or err.message) | ||
|
||
toastr.success(TAPi18n.__('Your_email_has_been_queued_for_sending')) | ||
t.reset() | ||
|
||
'click .select-all': (e, t) -> | ||
t.$('.error-select').hide() | ||
|
||
view = Blaze.getView($('.messages-box')[0]) | ||
view?.templateInstance?().selectedMessages = _.pluck(ChatMessage.find({rid: Session.get('openedRoom')})?.fetch(), '_id') | ||
$(".messages-box .message").addClass('selected') | ||
|
||
Template.mailMessagesInstructions.onCreated -> | ||
@erroredEmails = new ReactiveVar [] | ||
|
||
@reset = -> | ||
RocketChat.TabBar.setTemplate('channelSettings') | ||
view = Blaze.getView($('.messages-box')[0]) | ||
view?.templateInstance?().resetSelection?(false) | ||
|
||
@autorun => | ||
if Session.get('channelSettingsMailMessages') isnt Session.get('openedRoom') | ||
this.reset() |
44 changes: 44 additions & 0 deletions
44
...ages/rocketchat-channel-settings-mail-messages/client/views/mailMessagesInstructions.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<template name="mailMessagesInstructions"> | ||
<div class="content"> | ||
<div class="list-view mail-message"> | ||
<div class="status"> | ||
<h2>{{_ "Mail_Messages"}}</h2> | ||
</div> | ||
<p>{{_ "Mail_Messages_Instructions"}}</p> | ||
<form> | ||
<fieldset> | ||
<div class="input-line double-col"> | ||
<label>{{_ "From"}}</label> | ||
<div>{{name}}</div> | ||
<div>{{email}}</div> | ||
</div> | ||
<div class="input-line double-col"> | ||
<label>{{_ "To"}}</label> | ||
<div> | ||
<input type="text" name="to" value="" /> | ||
</div> | ||
</div> | ||
<div class="input-line double-col"> | ||
<label>{{_ "Subject"}}</label> | ||
<div> | ||
<input type="text" name="subject" value="{{_ "Mail_Messages_Subject" roomName}}" /> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</form> | ||
<div class="error error-missing-to alert alert-danger" style="display: none"> | ||
{{_ "Mail_Message_Missing_to"}} | ||
</div> | ||
<div class="error error-invalid-emails alert alert-danger" style="display: none"> | ||
{{_ "Mail_Message_Invalid_emails" erroredEmails}} | ||
</div> | ||
<div class="error error-select alert alert-danger" style="display: none"> | ||
{{{_ "Mail_Message_No_messages_selected_select_all"}}} | ||
</div> | ||
<p style="margin-top: 30px"> | ||
<button type="button" class="button secondary cancel">{{_ "Cancel"}}</button> | ||
<button type="button" class="button primary send">{{_ "Send"}}</button> | ||
</p> | ||
</div> | ||
</div> | ||
</template> |
17 changes: 17 additions & 0 deletions
17
packages/rocketchat-channel-settings-mail-messages/i18n/en.i18n.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"Body" : "Body", | ||
"Cancel" : "Cancel", | ||
"Choose_messages" : "Choose messages", | ||
"From" : "From", | ||
"Mail_Message_Missing_to" : "You must provide one or more To e-mail addresses, separated by commas.", | ||
"Mail_Message_No_messages_selected_select_all" : "You haven't selected any messages. Would you like to <a href='#' class='select-all'>select all</a> visible messages?", | ||
"Mail_Messages" : "Mail Messages", | ||
"Mail_Messages_Instructions" : "Choose which messages you want to send via e-mail by clicking the messages", | ||
"Mail_Messages_Subject" : "Here's a selected portion of %s messages", | ||
"Mail_Message_Invalid_emails" : "You have provided one or more invalid e-mails: %s", | ||
"Send" : "Send", | ||
"Sending" : "Sending...", | ||
"Subject" : "Subject", | ||
"To" : "To", | ||
"Your_email_has_been_queued_for_sending" : "Your email has been queued for sending" | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/rocketchat-channel-settings-mail-messages/package.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Package.describe({ | ||
name: 'rocketchat:channel-settings-mail-messages', | ||
version: '0.0.1', | ||
summary: 'Channel Settings - Mail Messages', | ||
git: '' | ||
}); | ||
|
||
Package.onUse(function(api) { | ||
api.versionsFrom('1.0'); | ||
|
||
api.use([ | ||
'coffeescript', | ||
'templating', | ||
'reactive-var', | ||
'[email protected]', | ||
'rocketchat:[email protected]', | ||
'rocketchat:channel-settings', | ||
'momentjs:moment' | ||
]); | ||
|
||
api.addFiles([ | ||
'client/lib/startup.coffee', | ||
'client/stylesheets/mail-messages.less', | ||
'client/views/channelSettingsMailMessages.html', | ||
'client/views/channelSettingsMailMessages.coffee', | ||
'client/views/mailMessagesInstructions.html', | ||
'client/views/mailMessagesInstructions.coffee' | ||
], 'client'); | ||
|
||
|
||
api.addFiles([ | ||
'server/methods/mailMessages.coffee' | ||
], 'server'); | ||
|
||
// TAPi18n | ||
var _ = Npm.require('underscore'); | ||
var fs = Npm.require('fs'); | ||
tapi18nFiles = _.compact(_.map(fs.readdirSync('packages/rocketchat-channel-settings-mail-messages/i18n'), function(filename) { | ||
if (fs.statSync('packages/rocketchat-channel-settings-mail-messages/i18n/' + filename).size > 16) { | ||
return 'i18n/' + filename; | ||
} | ||
})); | ||
api.use('tap:[email protected]'); | ||
api.imply('tap:i18n'); | ||
api.addFiles(tapi18nFiles); | ||
}); | ||
|
||
Package.onTest(function(api) { | ||
|
||
}); |
44 changes: 44 additions & 0 deletions
44
packages/rocketchat-channel-settings-mail-messages/server/methods/mailMessages.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Meteor.methods | ||
'mailMessages': (data) -> | ||
if not Meteor.userId() | ||
throw new Meteor.Error('invalid-user', "[methods] mailMessages -> Invalid user") | ||
|
||
check(data, Match.ObjectIncluding({ rid: String, to: String, subject: String, messages: [ String ], language: String })) | ||
|
||
room = Meteor.call 'canAccessRoom', data.rid, Meteor.userId() | ||
unless room | ||
throw new Meteor.Error('invalid-room', "[methods] mailMessages -> Invalid room") | ||
|
||
rfcMailPatternWithName = /^(?:.*<)?([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)(?:>?)$/ | ||
emails = data.to.trim().split(',') | ||
for email in emails | ||
unless rfcMailPatternWithName.test email.trim() | ||
throw new Meteor.Error('invalid-email', "[methods] mailMessages -> Invalid e-mail") | ||
|
||
user = Meteor.user() | ||
name = user.name | ||
email = user.emails?[0]?.address | ||
|
||
if data.language isnt 'en' | ||
localeFn = Meteor.call 'loadLocale', data.language | ||
if localeFn | ||
Function(localeFn)() | ||
moment.locale(data.language) | ||
|
||
html = "" | ||
RocketChat.models.Messages.findByRoomIdAndMessageIds(data.rid, data.messages, { sort: { ts: 1 } }).forEach (message) -> | ||
dateTime = moment(message.ts).format('L LT') | ||
html += "<p style='margin-bottom: 5px'><b>#{message.u.username}</b> <span style='color: #aaa; font-size: 12px'>#{dateTime}</span><br />" + RocketChat.Message.parse(message, data.language) + "</p>" | ||
|
||
Meteor.defer -> | ||
Email.send | ||
to: emails | ||
from: RocketChat.settings.get('From_Email') | ||
replyTo: email | ||
subject: data.subject | ||
html: html | ||
|
||
console.log 'Sending email to ' + emails.join(', ') | ||
|
||
|
||
return true |
29 changes: 29 additions & 0 deletions
29
packages/rocketchat-channel-settings/client/lib/ChannelSettings.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
RocketChat.ChannelSettings = new class | ||
options = new ReactiveVar {} | ||
|
||
### | ||
# Adds an option in Channel Settings | ||
# @config (object) | ||
# id: option id (required) | ||
# template (string): template name to render (required) | ||
# validation (function): if option should be displayed | ||
### | ||
addOption = (config) -> | ||
unless config?.id | ||
throw new Meteor.Error "ChannelSettings-addOption-error", "Option id was not informed." | ||
|
||
Tracker.nonreactive -> | ||
opts = options.get() | ||
opts[config.id] = config | ||
options.set opts | ||
|
||
getOptions = -> | ||
allOptions = _.toArray options.get() | ||
allowedOptions = _.compact _.map allOptions, (option) -> | ||
if not option.validation? or option.validation() | ||
return option | ||
|
||
return _.sortBy allowedOptions, 'order' | ||
|
||
addOption: addOption | ||
getOptions: getOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are you changing the locale forever?
What happens if you send a mail in PT then another one in EN?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! I should have used
localMoment = moment().locale(...)
. I'll fix that.