rough reply job
parent
b14a2a603f
commit
e61c88f6c9
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
belongs_to :user
|
||||||
|
|
||||||
has_many :messages, dependent: :destroy
|
has_many :messages, dependent: :destroy
|
||||||
|
|
||||||
|
def pending_reply?
|
||||||
|
messages.last.promt?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,8 @@
|
||||||
|
|
||||||
class Message < ApplicationRecord
|
class Message < ApplicationRecord
|
||||||
belongs_to :conversation
|
belongs_to :conversation
|
||||||
|
|
||||||
|
def promt?
|
||||||
|
!reply?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue