Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create mailer and worker for updated discussions
- Loading branch information
Showing
15 changed files
with
128 additions
and
2 deletions.
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
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ class Discussion < ApplicationRecord | |
|
||
|
||
has_many :user_messages, as: :parent | ||
has_many :discussion_followers | ||
|
||
|
||
end |
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
50 changes: 50 additions & 0 deletions
50
app/views/mailers/event_communication_mailer/discussions_updated_email.html.erb
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 @@ | ||
|
||
<table style="width: 550px; margin: 0 auto; background-color: white; border-radius: 5px; padding: 25px;"> | ||
<tbody> | ||
|
||
<tr> | ||
<td> | ||
<p>Hi <%= @user.name %>!</p> | ||
<p> | ||
Here's the list of your followed discussions which have updates! | ||
</p> | ||
<div style="text-align: center"> | ||
</div> | ||
<div> | ||
<ul style="padding: 0 2px;"> | ||
<% @discussions.group_by(&:parent).each do |parent, discussions| %> | ||
<li style="list-style: none; padding: 3px; background: #84f1ff12;"> | ||
<h4> Session :: <%= parent.title.blank? ? parent.event.name : parent.title %></h4> | ||
<ul style="padding: 0;"> | ||
<% discussions.each do |discussion| %> | ||
<li style="list-style: none; padding: 5px; background: #d3d3d33b; border-bottom: 1px dotted lightgrey;"> | ||
<p style="font-weight: bold; margin: 0;"> | ||
<%= discussion.topic %> | ||
<br> | ||
<small style="background-color: #f99952; color: white; border-radius: 15px; padding: 2px 5px;"> | ||
<% if discussion.discussion_followers.length == 1 %> | ||
New! | ||
<% else %> | ||
<%= discussion.discussion_followers.length %> Followers | ||
<% end %> | ||
</small> | ||
</p> | ||
<p style="margin: 0;"> | ||
<small> | ||
<%= simple_format(discussion.description) %> | ||
</small> | ||
</p> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
|
||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
|
||
</table> |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class DiscussionMessagesWorker | ||
@queue = :discussion_messages_mails | ||
|
||
# send an email for all the new messages to the speaker and the person who created the discussion | ||
# this email needs to be sent exactly at 11.59pm everyday for perfect functioning | ||
def self.perform | ||
# get all the discussions which were created from the last time | ||
discussions = Discussion.where(created_at: Time.now.beginning_of_day..Time.now) | ||
|
||
# get all the messages which were created from the last time | ||
messages = UserMessage.includes(:user).where(created_at: Time.now.beginning_of_day..Time.now, parent_type: "Discussion") | ||
|
||
|
||
all_discussion_ids = (discussions.map(&:id) + messages.map(&:parent_id)).uniq | ||
# get all the discussion followers and send them an update about all these discussions updated | ||
DiscussionFollower.where(discussion_id: all_discussion_ids).group_by(&:user).each do |user, followers| | ||
discussions = Discussion.where(id: followers.map(&:discussion_id)).uniq | ||
EventCommunicationMailer.discussions_updated_email(user, discussions).deliver_now | ||
end | ||
|
||
|
||
|
||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20181224154449_add_send_discussion_mails_to_users.rb
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,5 @@ | ||
class AddSendDiscussionMailsToUsers < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :users, :send_discussion_mails, :boolean, default: true | ||
end | ||
end |
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