Last active
November 28, 2017 16:06
-
-
Save domagude/a807bd2751ba43df312969d4c4b11c80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perform(message, previous_message, current_user) | |
# if the message's attribute added_new_users has present values | |
# broadcast a notification to those users that they were added to a group conv | |
if message.added_new_users.present? | |
conversation = message.conversation | |
message.added_new_users.each do |user_id| | |
ActionCable.server.broadcast( | |
"notifications_#{user_id}", | |
notification: 'added-to-group-conversation', | |
conversation_id: conversation.id, | |
message_author: message.user_id, | |
link_to_conversation: render_link_to_conversation(conversation, | |
user_id, | |
current_user) | |
) | |
end | |
else | |
# broadcast message to all conversation's participants | |
conversation_id = message.conversation_id | |
ActionCable.server.broadcast( | |
"group_conversation_#{conversation_id}", | |
message: render_message(message, previous_message), | |
conversation_id: conversation_id, | |
user_id: message.user_id | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment