mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-20 05:39:39 +02:00
23 lines
570 B
Ruby
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
|