3868910dde
* actioncable needs puma not webrick * add framework * remove the old way * send events from server to client * get all events working * clean up receivable * map is polymorphic on message * add the moved event * make todo comments clear * verify before streaming from map channel * rubocop fixes * wasn't set up correctly for nodejs realtime
22 lines
481 B
Ruby
22 lines
481 B
Ruby
# frozen_string_literal: true
|
|
class Message < ApplicationRecord
|
|
belongs_to :user
|
|
belongs_to :resource, polymorphic: true
|
|
|
|
delegate :name, to: :user, prefix: true
|
|
|
|
after_create :after_created
|
|
|
|
def user_image
|
|
user.image.url
|
|
end
|
|
|
|
def as_json(_options = {})
|
|
json = super(methods: [:user_name, :user_image])
|
|
json
|
|
end
|
|
|
|
def after_created
|
|
ActionCable.server.broadcast 'map_' + resource.id.to_s, type: 'messageCreated', message: self.as_json
|
|
end
|
|
end
|