23 lines
443 B
Ruby
23 lines
443 B
Ruby
class Mention < ApplicationRecord
|
|
include Notifiable
|
|
|
|
belongs_to :source, polymorphic: true
|
|
belongs_to :mentioner, class_name: "User"
|
|
belongs_to :mentionee, class_name: "User", inverse_of: :mentions
|
|
|
|
after_create_commit :watch_source_by_mentionee
|
|
|
|
def self_mention?
|
|
mentioner == mentionee
|
|
end
|
|
|
|
def notifiable_target
|
|
source
|
|
end
|
|
|
|
private
|
|
def watch_source_by_mentionee
|
|
source.watch_by(mentionee)
|
|
end
|
|
end
|