Files
fizzy/app/models/conversation/message.rb
T
2025-08-13 15:14:12 +02:00

25 lines
648 B
Ruby

class Conversation::Message < ApplicationRecord
include Pagination, Broadcastable, ClientIdentifiable, Promptable, Respondable
ALL_EMOJI_REGEX = /\A(\p{Emoji_Presentation}|\p{Extended_Pictographic}|\uFE0F)+\z/u
has_rich_text :content
belongs_to :conversation, inverse_of: :messages
has_one :owner, through: :conversation, source: :user
enum :role, %w[ user assistant ].index_by(&:itself)
validates :client_message_id, presence: true
scope :ordered, -> { order(created_at: :asc, id: :asc) }
def all_emoji?
content.to_plain_text.match?(ALL_EMOJI_REGEX)
end
def to_partial_path
"conversations/messages"
end
end