From 209e0a0fb437541bab903914595f1c83a6e0af92 Mon Sep 17 00:00:00 2001 From: Sony Mathew Date: Tue, 24 Mar 2020 23:34:22 +0530 Subject: [PATCH] [Feature] Change conversation ordering (#640) * Update conversation's updated_at when a message is created/saved * changed teh ordering of conversation to be based on `updated_at` rather than `created_at` --- app/models/conversation.rb | 2 +- app/models/message.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 7ac815755..75ac69f5c 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -36,7 +36,7 @@ class Conversation < ApplicationRecord enum status: { open: 0, resolved: 1, bot: 2 } - scope :latest, -> { order(created_at: :desc) } + scope :latest, -> { order(updated_at: :desc) } scope :unassigned, -> { where(assignee_id: nil) } scope :assigned_to, ->(agent) { where(assignee_id: agent.id) } diff --git a/app/models/message.rb b/app/models/message.rb index 944cebabf..355b3216c 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -51,7 +51,7 @@ class Message < ApplicationRecord belongs_to :account belongs_to :inbox - belongs_to :conversation + belongs_to :conversation, touch: true belongs_to :user, required: false belongs_to :contact, required: false