diaspora/app/models/notifications/private_message.rb
Benjamin Neff ae96b4bf55 refactor message notifications
all visibilities are already in the conversation, so we can send
all notifications at once.
2016-06-26 06:20:59 +02:00

29 lines
820 B
Ruby

module Notifications
class PrivateMessage < Notification
def mail_job
Workers::Mail::PrivateMessage
end
def popup_translation_key
"notifications.private_message"
end
def self.notify(object, _recipient_user_ids)
case object
when Conversation
object.messages.each {|message| notify_message(message) }
when Message
notify_message(object)
end
end
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