rough reply job
parent
b14a2a603f
commit
e61c88f6c9
|
|
@ -5,6 +5,7 @@ class MessagesController < ApplicationController
|
|||
# TODO: Revisit auth once cancancan is installed
|
||||
@message = Message.new(message_params)
|
||||
if @message.save
|
||||
GenerateReplyJob.perform_later(@message.conversation)
|
||||
redirect_to @message.conversation
|
||||
else
|
||||
redirect_to conversations_path
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -4,4 +4,8 @@ class Conversation < ApplicationRecord
|
|||
belongs_to :user
|
||||
|
||||
has_many :messages, dependent: :destroy
|
||||
|
||||
def pending_reply?
|
||||
messages.last.promt?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,4 +2,8 @@
|
|||
|
||||
class Message < ApplicationRecord
|
||||
belongs_to :conversation
|
||||
|
||||
def promt?
|
||||
!reply?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue