fix: Use last_activity_at instead of updated_at for sorting (#1281)
Co-authored-by: Akash Srivastava <akash.srivastava.1911@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
# agent_last_seen_at :datetime
|
||||
# contact_last_seen_at :datetime
|
||||
# identifier :string
|
||||
# last_activity_at :datetime not null
|
||||
# locked :boolean default(FALSE)
|
||||
# status :integer default("open"), not null
|
||||
# uuid :uuid not null
|
||||
@@ -36,7 +37,7 @@ class Conversation < ApplicationRecord
|
||||
|
||||
enum status: { open: 0, resolved: 1, bot: 2 }
|
||||
|
||||
scope :latest, -> { order(updated_at: :desc) }
|
||||
scope :latest, -> { order(last_activity_at: :desc) }
|
||||
scope :unassigned, -> { where(assignee_id: nil) }
|
||||
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ class Message < ApplicationRecord
|
||||
def execute_after_create_commit_callbacks
|
||||
# rails issue with order of active record callbacks being executed
|
||||
# https://github.com/rails/rails/issues/20911
|
||||
set_conversation_activity
|
||||
dispatch_create_events
|
||||
send_reply
|
||||
execute_message_template_hooks
|
||||
@@ -191,4 +192,10 @@ class Message < ApplicationRecord
|
||||
def validate_attachments_limit(_attachment)
|
||||
errors.add(attachments: 'exceeded maximum allowed') if attachments.size >= NUMBER_OF_PERMITTED_ATTACHMENTS
|
||||
end
|
||||
|
||||
def set_conversation_activity
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
conversation.update_columns(last_activity_at: created_at)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user