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:
Pranav Raj S
2020-10-05 22:52:43 +05:30
committed by GitHub
parent ee119b2174
commit 399f9e004a
11 changed files with 56 additions and 7 deletions

View File

@@ -92,6 +92,7 @@ export const mutations = {
);
if (previousMessageIndex === -1) {
chat.messages.push(message);
chat.timestamp = message.created_at;
if (_state.selectedChatId === message.conversation_id) {
window.bus.$emit('scrollToMessage');
}

View File

@@ -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) }

View File

@@ -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

View File

@@ -32,7 +32,7 @@ class Conversations::EventDataPresenter < SimpleDelegator
{
agent_last_seen_at: agent_last_seen_at.to_i,
contact_last_seen_at: contact_last_seen_at.to_i,
timestamp: created_at.to_i
timestamp: last_activity_at.to_i
}
end
end

View File

@@ -11,7 +11,7 @@ json.data do
json.status conversation.status
json.muted conversation.muted?
json.can_reply conversation.can_reply?
json.timestamp conversation.messages.last.try(:created_at).try(:to_i)
json.timestamp conversation.last_activity_at.to_i
json.contact_last_seen_at conversation.contact_last_seen_at.to_i
json.agent_last_seen_at conversation.agent_last_seen_at.to_i
json.additional_attributes conversation.additional_attributes

View File

@@ -21,7 +21,7 @@ json.inbox_id conversation.inbox_id
json.status conversation.status
json.muted conversation.muted?
json.can_reply conversation.can_reply?
json.timestamp conversation.messages.last.try(:created_at).try(:to_i)
json.timestamp conversation.last_activity_at.to_i
json.contact_last_seen_at conversation.contact_last_seen_at.to_i
json.agent_last_seen_at conversation.agent_last_seen_at.to_i
json.unread_count conversation.unread_incoming_messages.count