-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send email notifications for replies (#62)
- Loading branch information
Showing
23 changed files
with
501 additions
and
396 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
AllCops: | ||
TargetRubyVersion: 2.3 | ||
Style/AsciiComments: | ||
Enabled: false | ||
Security/YAMLLoad: | ||
Enabled: false |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module CommentThreadsHelper | ||
def comment_thread_url(locale, comment_thread) | ||
"#{case_url(locale, comment_thread.card.case.slug)}" \ | ||
"/#{comment_thread.card.element.case_element.position}" \ | ||
"/cards/#{comment_thread.card_id}/comments" | ||
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
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class ReplyNotificationMailer < ApplicationMailer | ||
helper :cases | ||
helper :comment_threads | ||
|
||
def notify(notification) | ||
@notification = notification | ||
reader = @notification.reader | ||
return unless reader.send_reply_notifications | ||
|
||
mail(to: reader.name_and_email, | ||
from: from_header, | ||
subject: subject_header) do |format| | ||
format.text | ||
format.html | ||
end | ||
end | ||
|
||
private | ||
|
||
# Build the from header. We’re setting the from name to the name of the | ||
# reader whose comment triggered the notification, but the from address | ||
# remains our notification address so as not to trip spam filters | ||
def from_header | ||
"#{@notification.notifier.name} <#{ApplicationMailer::FROM_ADDRESS}>" | ||
end | ||
|
||
# Build the email subject as follows | ||
# RE: [National Adaptation] “I understand that Ethiopia would be a...” (# 46) | ||
# | ||
# Every notification of a reply to the same original comment will have the | ||
# same subject so that they can be threaded | ||
def subject_header | ||
comment_thread = @notification.comment_thread | ||
"RE: [#{@notification.case.kicker}] " \ | ||
"“#{comment_thread.comments.first.content.truncate(40)}” " \ | ||
"(##{comment_thread.id})" | ||
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
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class ReplyNotification < ApplicationRecord | ||
belongs_to :reader | ||
belongs_to :notifier, class_name: 'Reader' | ||
belongs_to :comment | ||
belongs_to :comment_thread | ||
belongs_to :case | ||
belongs_to :page | ||
belongs_to :card | ||
|
||
after_create_commit { ReplyNotificationBroadcastJob.perform_now self } | ||
after_create_commit { ReplyNotificationMailer.notify(self).deliver } | ||
|
||
def message | ||
I18n.t 'notifications.replied_to_your_comment', | ||
notifier: notifier.name, | ||
case_kicker: self.case.kicker | ||
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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
<% headline one_liner "#{@notification.notifier.name} replied to your comment" %> | ||
<% background_image_url ix_cover_image @notification.case, :email %> | ||
|
||
<%= @notification.comment.content %> | ||
|
||
<%= md_button_to "Reply online", | ||
comment_thread_url(I18n.locale, @notification.comment_thread) %> | ||
|
||
<% email_footer <<-FOOTER | ||
You are receiving this email because someone replied to a comment you made on a | ||
Michigan Sustainability Case you’re studying. If you do not want to receive | ||
emails like this, you can [change your notification settings](#{ | ||
edit_reader_url @notification.reader.locale, @notification.reader | ||
}). | ||
FOOTER | ||
%> |
14 changes: 14 additions & 0 deletions
14
app/views/reply_notifications/_reply_notification.json.jbuilder
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
json.key_format! camelize: :lower | ||
|
||
json.extract! reply_notification, :id, :message, :card_id, :comment_thread_id | ||
json.notifier do | ||
json.extract! reply_notification.notifier, :id, :name, :initials | ||
end | ||
json.case do | ||
json.extract! reply_notification.case, :slug, :kicker | ||
end | ||
json.element do | ||
json.extract! reply_notification.page.case_element, :position | ||
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
7 changes: 7 additions & 0 deletions
7
db/migrate/20170705153826_add_reply_notification_flag_to_reader.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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddReplyNotificationFlagToReader < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :readers, :send_reply_notifications, :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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateReplyNotifications < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :reply_notifications do |t| | ||
t.references :reader | ||
|
||
t.integer :notifier_id | ||
t.integer :comment_id | ||
t.integer :comment_thread_id | ||
t.integer :case_id | ||
t.integer :page_id | ||
t.integer :card_id | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class DropNotifications < ActiveRecord::Migration[5.0] | ||
def change | ||
drop_table :notifications do |t| | ||
t.boolean :email_sent | ||
t.boolean :read | ||
t.references :reader, foreign_key: true | ||
t.integer :category | ||
t.jsonb :data | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.