metamaps--metamaps/app/models/message.rb
Connor Turland b0deafc53e Follows and some new notifications (#1063)
* all the good changes

* follows

* dont send duplicates

* remove follow_type for now

* dont add all the extra stuff we're not implementing yet

* refactor

* lots of fixes

* Delete activity.html.erb

* Delete activity.text.erb

* Update 20170209215819_create_follows.rb

* Update schema.rb

* Update mapping.rb

* Update mailboxer.rb
2017-02-11 00:20:42 -05:00

30 lines
718 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
#after_create :after_created_async
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: as_json
end
def after_created_async
FollowService.follow(resource, user, 'commented')
NotificationService.notify_followers(resource, 'map_message', self)
end
handle_asynchronously :after_created_async
end