Class: Chat::MessageRelayJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/chat/message_relay_job.rb

Instance Method Summary collapse

Instance Method Details

#content(message) ⇒ Object



18
19
20
21
22
23
24
# File 'app/jobs/chat/message_relay_job.rb', line 18

def content(message)
  if message.image?
    { message: renderer.image_tag(message.image.url), image: true }
  else
    { message: message.text, image: false }
  end
end

#perform(message_id) ⇒ Object



5
6
7
8
9
10
# File 'app/jobs/chat/message_relay_job.rb', line 5

def perform(message_id)
  message = Chat::Message.find(message_id)
  broadcast(
    "chats::#{message.conversation_id}::messages", render_message(message)
  )
end

#render_message(message) ⇒ Object



12
13
14
15
16
# File 'app/jobs/chat/message_relay_job.rb', line 12

def render_message(message)
  {
    user: message.user_id, avatar: renderer.chat_avatar(message.user).to_s
  }.merge(content(message))
end