docbrown/app/models/message.rb
Mac Siri 7cb65649e4 Update chat app (#326)
* Fix spacing

* Update webpacker gem to 3.5

* Add custom preact-compact config

* Add babel-loader to resolve a weird issue

* Add react-textarea-autocomplete

* Move 2 dependencies into devDependencies

* Add babel-eslint & eslint-plugin-babel

* Refactor chat

* Add fixed width to chat's channels

* Add timestamp for chat

* Fix long word issue

* Add showTimestamp options to chat

* Add profile image to chat

* Make profile image in chat circle

* Improve message send logic

* Add proper user session handling for chat

* Choose profile user image source for chat

* Adjust user's text color

* Fix lint
2018-05-21 13:19:56 -04:00

31 lines
846 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 preferred_user_color
color_options = [user.bg_color_hex || "#000000", user.text_color_hex || "#000000"]
HexComparer.new(color_options).brightness(0.9)
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