diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-19 19:20:07 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-19 19:20:07 +0100 |
commit | 2b116131d78460e5cbb8eacc30aaaf04106ea0fa (patch) | |
tree | 62ff3751b4f94b36335d5bd7d45374e024cd1d19 /app/services | |
parent | e2b846f630cae00096a42dffeff759d0ef8e1c3e (diff) |
Adding e-mail notifications about mentions, follows, favourites and reblogs. Fixing another mention recording bug
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/fan_out_on_write_service.rb | 3 | ||||
-rw-r--r-- | app/services/favourite_service.rb | 9 | ||||
-rw-r--r-- | app/services/process_feed_service.rb | 7 | ||||
-rw-r--r-- | app/services/process_interaction_service.rb | 5 | ||||
-rw-r--r-- | app/services/process_mentions_service.rb | 14 | ||||
-rw-r--r-- | app/services/reblog_service.rb | 9 |
6 files changed, 35 insertions, 12 deletions
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 87a7c55ac..87a83e892 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -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 diff --git a/app/services/favourite_service.rb b/app/services/favourite_service.rb index 547811e73..4a8ecfacb 100644 --- a/app/services/favourite_service.rb +++ b/app/services/favourite_service.rb @@ -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 diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index ccdf07cc1..504d58aed 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -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) diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index cdc720083..c00f8c66a 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -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) diff --git a/app/services/process_mentions_service.rb b/app/services/process_mentions_service.rb index 6e92d16b4..d566b65c7 100644 --- a/app/services/process_mentions_service.rb +++ b/app/services/process_mentions_service.rb @@ -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 diff --git a/app/services/reblog_service.rb b/app/services/reblog_service.rb index 7078e3aff..606970e23 100644 --- a/app/services/reblog_service.rb +++ b/app/services/reblog_service.rb @@ -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 |