2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2019-02-01 19:40:24 +00:00
|
|
|
class Comment < ApplicationRecord
|
2019-08-06 12:49:40 +00:00
|
|
|
# :host_id,
|
|
|
|
# :host_type, # parent: Event, Campaign, nil
|
|
|
|
# :profile_id,
|
|
|
|
# :body
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
validates :profile, presence: true
|
|
|
|
validates :body, presence: true, length: { maximum: 200 }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
has_one :activity, as: :attachment, dependent: :destroy
|
|
|
|
belongs_to :host, polymorphic: true
|
|
|
|
belongs_to :donation
|
|
|
|
belongs_to :profile
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
before_validation(on: :create) do
|
|
|
|
remove_newlines
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
after_create do
|
|
|
|
create_activity(
|
|
|
|
desc: 'commented',
|
|
|
|
profile_id: profile_id,
|
|
|
|
host_id: host_id,
|
|
|
|
host_type: host_type,
|
|
|
|
body: body
|
|
|
|
)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def remove_newlines
|
|
|
|
self.body = body && body.delete("\n")
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|