Files
maybe/app/models/message.rb
Zach Gollwitzer 573ec67af8 Message styles
2025-03-25 07:52:38 -04:00

23 lines
570 B
Ruby

class Message < ApplicationRecord
belongs_to :chat
has_many :tool_calls, dependent: :destroy
enum :status, {
pending: "pending",
complete: "complete",
failed: "failed"
}
validates :content, presence: true, allow_blank: true
after_create_commit -> { broadcast_append_to chat, target: "messages" }, if: :broadcast?
after_update_commit -> { broadcast_update_to chat }, if: :broadcast?
scope :ordered, -> { order(created_at: :asc) }
private
def broadcast?
raise NotImplementedError, "subclasses must set #broadcast?"
end
end