Adding e-mail notifications about mentions, follows, favourites and reblogs. Fixing another mention recording bug

This commit is contained in:
Eugen Rochko
2016-03-19 19:20:07 +01:00
parent e2b846f630
commit 2b116131d7
15 changed files with 185 additions and 12 deletions

View File

@ -16,7 +16,8 @@ class FanOutOnWriteService < BaseService
end
# Deliver to local mentioned
status.mentions.each do |mentioned_account|
status.mentioned_accounts.each do |mention|
mentioned_account = mention.account
next unless mentioned_account.local?
push(:mentions, mentioned_account.id, status)
end

View File

@ -6,8 +6,13 @@ class FavouriteService < BaseService
def call(account, status)
favourite = Favourite.create!(account: account, status: status)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
return favourite if status.local?
send_interaction_service.(favourite.stream_entry, status.account)
if status.local?
NotificationMailer.favourite(status, account).deliver_later
else
send_interaction_service.(favourite.stream_entry, status.account)
end
favourite
end

View File

@ -51,11 +51,11 @@ class ProcessFeedService < BaseService
unless mentioned_account.nil?
mentioned_account.mentions.where(status: status).first_or_create(status: status)
NotificationMailer.mention(mentioned_account, status).deliver_later
end
end
end
fan_out_on_write_service.(status)
end
end
@ -74,7 +74,10 @@ class ProcessFeedService < BaseService
status.reblog = fetch_remote_status(entry)
end
status.save! unless status.reblog.nil?
if !status.reblog.nil?
status.save!
NotificationMailer.reblog(status.reblog, status.account).deliver_later
end
end
def add_reply!(entry, status)

View File

@ -55,6 +55,7 @@ class ProcessInteractionService < BaseService
def follow!(account, target_account)
account.follow!(target_account)
NotificationMailer.follow(target_account, account).deliver_later
end
def unfollow!(account, target_account)
@ -62,7 +63,9 @@ class ProcessInteractionService < BaseService
end
def favourite!(xml, from_account)
status(xml).favourites.where(account: from_account).first_or_create!(account: from_account)
current_status = status(xml)
current_status.favourites.where(account: from_account).first_or_create!(account: from_account)
NotificationMailer.favourite(current_status, from_account).deliver_later
end
def add_post!(body, account)

View File

@ -10,16 +10,22 @@ class ProcessMentionsService < BaseService
username, domain = match.first.split('@')
mentioned_account = Account.find_by(username: username, domain: domain)
if mentioned_account.nil?
if mentioned_account.nil? && !domain.nil?
mentioned_account = follow_remote_account_service.("#{match.first}")
next if mentioned_account.nil?
end
mentioned_account.mentions.where(status: status).first_or_create(status: status)
end
status.mentions.each do |mentioned_account|
next if mentioned_account.local?
send_interaction_service.(status.stream_entry, mentioned_account)
status.mentioned_accounts.each do |mention|
mentioned_account = mention.account
if mentioned_account.local?
NotificationMailer.mention(mentioned_account, status).deliver_later
else
send_interaction_service.(status.stream_entry, mentioned_account)
end
end
end

View File

@ -7,8 +7,13 @@ class ReblogService < BaseService
reblog = account.statuses.create!(reblog: reblogged_status, text: '')
fan_out_on_write_service.(reblog)
account.ping!(account_url(account, format: 'atom'), [Rails.configuration.x.hub_url])
return reblog if reblogged_status.local?
send_interaction_service.(reblog.stream_entry, reblogged_status.account)
if reblogged_status.local?
NotificationMailer.reblog(reblogged_status, account).deliver_later
else
send_interaction_service.(reblog.stream_entry, reblogged_status.account)
end
reblog
end