Adding e-mail notifications about mentions, follows, favourites and reblogs. Fixing another mention recording bug
parent
e2b846f630
commit
2b116131d7
@ -0,0 +1,4 @@ |
||||
class ApplicationMailer < ActionMailer::Base |
||||
default from: (ENV['SMTP_FROM_ADDRESS'] || 'notifications@localhost') |
||||
layout 'mailer' |
||||
end |
@ -0,0 +1,34 @@ |
||||
class NotificationMailer < ApplicationMailer |
||||
helper StreamEntriesHelper |
||||
helper AtomBuilderHelper |
||||
|
||||
def mention(mentioned_account, status) |
||||
@me = mentioned_account |
||||
@status = status |
||||
|
||||
mail to: @me.user.email, subject: "You were mentioned by #{@status.account.acct}" |
||||
end |
||||
|
||||
def follow(followed_account, follower) |
||||
@me = followed_account |
||||
@account = follower |
||||
|
||||
mail to: @me.user.email, subject: "#{@account.acct} is now following you" |
||||
end |
||||
|
||||
def favourite(target_status, from_account) |
||||
@me = target_status.account |
||||
@account = from_account |
||||
@status = target_status |
||||
|
||||
mail to: @me.user.email, subject: "#{@account.acct} favourited your status" |
||||
end |
||||
|
||||
def reblog(target_status, from_account) |
||||
@me = target_status.account |
||||
@account = from_account |
||||
@status = target_status |
||||
|
||||
mail to: @me.user.email, subject: "#{@account.acct} reblogged your status" |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
<%= yield %> |
||||
|
||||
--- |
||||
|
||||
Mastodon notifications from <%= Rails.configuration.x.local_domain %> |
@ -0,0 +1,5 @@ |
||||
<%= display_name(@me) %>, |
||||
|
||||
Your status was favourited by <%= @account.acct %>: |
||||
|
||||
<%= account_stream_entry_url(@me, @status.stream_entry) %> |
@ -0,0 +1,5 @@ |
||||
<%= display_name(@me) %>, |
||||
|
||||
<%= @account.acct %> is now following you! |
||||
|
||||
<%= url_for_target(@account) %> |
@ -0,0 +1,7 @@ |
||||
<%= display_name(@me) %>, |
||||
|
||||
You were mentioned by <%= @status.account.acct %> in: |
||||
|
||||
<%= @status.content %> |
||||
|
||||
<%= url_for_target(@status) %> |
@ -0,0 +1,5 @@ |
||||
<%= display_name(@me) %>, |
||||
|
||||
Your status was reblogged by <%= @account.acct %>: |
||||
|
||||
<%= account_stream_entry_url(@me, @status.stream_entry) %> |
@ -0,0 +1,61 @@ |
||||
require "rails_helper" |
||||
|
||||
RSpec.describe NotificationMailer, type: :mailer do |
||||
let(:receiver) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } |
||||
let(:sender) { Fabricate(:account, username: 'bob') } |
||||
let(:foreign_status) { Fabricate(:status, account: sender) } |
||||
let(:own_status) { Fabricate(:status, account: receiver.account) } |
||||
|
||||
describe "mention" do |
||||
let(:mail) { NotificationMailer.mention(receiver.account, foreign_status) } |
||||
|
||||
it "renders the headers" do |
||||
expect(mail.subject).to eq("You were mentioned by bob") |
||||
expect(mail.to).to eq([receiver.email]) |
||||
end |
||||
|
||||
it "renders the body" do |
||||
expect(mail.body.encoded).to match("You were mentioned by bob") |
||||
end |
||||
end |
||||
|
||||
describe "follow" do |
||||
let(:mail) { NotificationMailer.follow(receiver.account, sender) } |
||||
|
||||
it "renders the headers" do |
||||
expect(mail.subject).to eq("bob is now following you") |
||||
expect(mail.to).to eq([receiver.email]) |
||||
end |
||||
|
||||
it "renders the body" do |
||||
expect(mail.body.encoded).to match("bob is now following you") |
||||
end |
||||
end |
||||
|
||||
describe "favourite" do |
||||
let(:mail) { NotificationMailer.favourite(own_status, sender) } |
||||
|
||||
it "renders the headers" do |
||||
expect(mail.subject).to eq("bob favourited your status") |
||||
expect(mail.to).to eq([receiver.email]) |
||||
end |
||||
|
||||
it "renders the body" do |
||||
expect(mail.body.encoded).to match("Your status was favourited by bob") |
||||
end |
||||
end |
||||
|
||||
describe "reblog" do |
||||
let(:mail) { NotificationMailer.reblog(own_status, sender) } |
||||
|
||||
it "renders the headers" do |
||||
expect(mail.subject).to eq("bob reblogged your status") |
||||
expect(mail.to).to eq([receiver.email]) |
||||
end |
||||
|
||||
it "renders the body" do |
||||
expect(mail.body.encoded).to match("Your status was reblogged by bob") |
||||
end |
||||
end |
||||
|
||||
end |
@ -0,0 +1,24 @@ |
||||
# Preview all emails at http://localhost:3000/rails/mailers/notification_mailer |
||||
class NotificationMailerPreview < ActionMailer::Preview |
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notification_mailer/mention |
||||
def mention |
||||
# NotificationMailer.mention |
||||
end |
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notification_mailer/follow |
||||
def follow |
||||
# NotificationMailer.follow |
||||
end |
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notification_mailer/favourite |
||||
def favourite |
||||
# NotificationMailer.favourite |
||||
end |
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/notification_mailer/reblog |
||||
def reblog |
||||
# NotificationMailer.reblog |
||||
end |
||||
|
||||
end |
Loading…
Reference in new issue