Skip to content

Instantly share code, notes, and snippets.

@domagude
Last active November 28, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domagude/a807bd2751ba43df312969d4c4b11c80 to your computer and use it in GitHub Desktop.
Save domagude/a807bd2751ba43df312969d4c4b11c80 to your computer and use it in GitHub Desktop.
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