rough reply job

main
Sebskyo 2025-03-01 23:20:27 +01:00
parent b14a2a603f
commit e61c88f6c9
4 changed files with 18 additions and 0 deletions

View File

@ -5,6 +5,7 @@ class MessagesController < ApplicationController
# TODO: Revisit auth once cancancan is installed # TODO: Revisit auth once cancancan is installed
@message = Message.new(message_params) @message = Message.new(message_params)
if @message.save if @message.save
GenerateReplyJob.perform_later(@message.conversation)
redirect_to @message.conversation redirect_to @message.conversation
else else
redirect_to conversations_path redirect_to conversations_path

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class GenerateReplyJob < ApplicationJob
queue_as :default
def perform(conversation)
conversation.messages.create(body: 'AI Reply', reply: true)
end
end

View File

@ -4,4 +4,8 @@ class Conversation < ApplicationRecord
belongs_to :user belongs_to :user
has_many :messages, dependent: :destroy has_many :messages, dependent: :destroy
def pending_reply?
messages.last.promt?
end
end end

View File

@ -2,4 +2,8 @@
class Message < ApplicationRecord class Message < ApplicationRecord
belongs_to :conversation belongs_to :conversation
def promt?
!reply?
end
end end