fix: last incoming message sort (#4972)
This commit is contained in:
@@ -11,14 +11,14 @@ module SortHandler
|
||||
end
|
||||
|
||||
def self.last_messaged_conversations
|
||||
Message.except(:order).select('DISTINCT ON (conversation_id) *').order('conversation_id, created_at DESC')
|
||||
Message.except(:order).select(
|
||||
'DISTINCT ON (conversation_id) conversation_id, id, created_at, message_type'
|
||||
).order('conversation_id, created_at DESC')
|
||||
end
|
||||
|
||||
def self.sort_on_last_user_message_at
|
||||
where(
|
||||
'grouped_conversations.message_type = 0'
|
||||
).order(
|
||||
'grouped_conversations.created_at ASC'
|
||||
order(
|
||||
'grouped_conversations.message_type', 'grouped_conversations.created_at ASC'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,7 +72,7 @@ class Conversation < ApplicationRecord
|
||||
|
||||
scope :last_user_message_at, lambda {
|
||||
joins(
|
||||
"INNER JOIN (#{last_messaged_conversations.to_sql}) grouped_conversations
|
||||
"INNER JOIN (#{last_messaged_conversations.to_sql}) AS grouped_conversations
|
||||
ON grouped_conversations.conversation_id = conversations.id"
|
||||
).sort_on_last_user_message_at
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class Mention < ApplicationRecord
|
||||
# Then select only latest incoming message from the conversations which doesn't have last message as outgoing
|
||||
# Order by message created_at
|
||||
Mention.joins(
|
||||
"INNER JOIN (#{last_messaged_conversations.to_sql}) grouped_conversations
|
||||
"INNER JOIN (#{last_messaged_conversations.to_sql}) AS grouped_conversations
|
||||
ON grouped_conversations.conversation_id = mentions.conversation_id"
|
||||
).sort_on_last_user_message_at
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user