docbrown/app/models/message.rb
Mac Siri b4292ade33 Implement chatroom (#308)
* Fix multiple chat loading bug

* Open profile links in chat via new tab

* Add unmount handling for chat

* Add overscroll property to chat

* Add channel_name to ChatChannel model

* Create route and page for chatroom WIP

* Expose ChatChannel id to live page

* Implement multichannel support WIP

* Implement chatroom page WIP

* Add css for chatroom

* Update chat's moderation

* Refactor chat's message type

* Swap the use of :message_markdown & :message_html

* Add channel permissions WIP

* Fix failing specs

* Adjust json reponses

* Add empty message prevention

* Update participant error message

* Change Workshop channel to General
2018-05-14 12:50:32 -04:00

30 lines
733 B
Ruby

class Message < ApplicationRecord
belongs_to :user
belongs_to :chat_channel
validates :message_html, presence: true
validates :message_markdown, presence: true, length: { maximum: 600 }
before_validation :evaluate_markdown
before_validation :evaluate_channel_permission
def timestamp
created_at.strftime("%H:%M:%S")
end
private
def evaluate_markdown
self.message_html = message_markdown
end
def evaluate_channel_permission
channel_type = ChatChannel.find(chat_channel_id).channel_type
return if channel_type == "open"
if user&.has_role?(:chatroom_beta_tester)
# this is fine
else
errors.add(:base, "You are not a participant of this chat channel.")
end
end
end