refactor message notifications
all visibilities are already in the conversation, so we can send all notifications at once.
This commit is contained in:
parent
9b0e40bf91
commit
ae96b4bf55
2 changed files with 10 additions and 11 deletions
|
|
@ -8,22 +8,21 @@ module Notifications
|
||||||
"notifications.private_message"
|
"notifications.private_message"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.notify(object, recipient_user_ids)
|
def self.notify(object, _recipient_user_ids)
|
||||||
case object
|
case object
|
||||||
when Conversation
|
when Conversation
|
||||||
object.messages.each do |message|
|
object.messages.each {|message| notify_message(message) }
|
||||||
recipient_ids = recipient_user_ids - [message.author.owner_id]
|
|
||||||
User.where(id: recipient_ids).find_each {|recipient| notify_message(message, recipient) }
|
|
||||||
end
|
|
||||||
when Message
|
when Message
|
||||||
recipients = object.conversation.participants.select(&:local?) - [object.author]
|
notify_message(object)
|
||||||
recipients.each {|recipient| notify_message(object, recipient.owner) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.notify_message(message, recipient)
|
def self.notify_message(message)
|
||||||
message.increase_unread(recipient)
|
recipient_ids = message.conversation.participants.local.where.not(id: message.author_id).pluck(:owner_id)
|
||||||
new(recipient: recipient).email_the_user(message, message.author)
|
User.where(id: recipient_ids).find_each do |recipient|
|
||||||
|
message.increase_unread(recipient)
|
||||||
|
new(recipient: recipient).email_the_user(message, message.author)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
private_class_method :notify_message
|
private_class_method :notify_message
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ module Diaspora
|
||||||
|
|
||||||
def self.conversation(entity)
|
def self.conversation(entity)
|
||||||
author = author_of(entity)
|
author = author_of(entity)
|
||||||
try_load_existing_guid(Conversation, entity.guid, author) do
|
ignore_existing_guid(Conversation, entity.guid, author) do
|
||||||
Conversation.new(
|
Conversation.new(
|
||||||
author: author,
|
author: author,
|
||||||
guid: entity.guid,
|
guid: entity.guid,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue