refactor message notifications

all visibilities are already in the conversation, so we can send
all notifications at once.
This commit is contained in:
Benjamin Neff 2016-05-12 05:01:04 +02:00
parent 9b0e40bf91
commit ae96b4bf55
2 changed files with 10 additions and 11 deletions

View file

@ -8,23 +8,22 @@ module Notifications
"notifications.private_message"
end
def self.notify(object, recipient_user_ids)
def self.notify(object, _recipient_user_ids)
case object
when Conversation
object.messages.each do |message|
recipient_ids = recipient_user_ids - [message.author.owner_id]
User.where(id: recipient_ids).find_each {|recipient| notify_message(message, recipient) }
end
object.messages.each {|message| notify_message(message) }
when Message
recipients = object.conversation.participants.select(&:local?) - [object.author]
recipients.each {|recipient| notify_message(object, recipient.owner) }
notify_message(object)
end
end
def self.notify_message(message, recipient)
def self.notify_message(message)
recipient_ids = message.conversation.participants.local.where.not(id: message.author_id).pluck(:owner_id)
User.where(id: recipient_ids).find_each do |recipient|
message.increase_unread(recipient)
new(recipient: recipient).email_the_user(message, message.author)
end
end
private_class_method :notify_message
end
end

View file

@ -37,7 +37,7 @@ module Diaspora
def self.conversation(entity)
author = author_of(entity)
try_load_existing_guid(Conversation, entity.guid, author) do
ignore_existing_guid(Conversation, entity.guid, author) do
Conversation.new(
author: author,
guid: entity.guid,