2022-06-22 05:34:42 +00:00
|
|
|
module SortHandler
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
def self.latest
|
|
|
|
order(last_activity_at: :desc)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.sort_on_created_at
|
|
|
|
order(created_at: :asc)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.last_messaged_conversations
|
2022-07-05 19:07:43 +00:00
|
|
|
Message.except(:order).select(
|
|
|
|
'DISTINCT ON (conversation_id) conversation_id, id, created_at, message_type'
|
|
|
|
).order('conversation_id, created_at DESC')
|
2022-06-22 05:34:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.sort_on_last_user_message_at
|
2022-07-05 19:07:43 +00:00
|
|
|
order(
|
|
|
|
'grouped_conversations.message_type', 'grouped_conversations.created_at ASC'
|
2022-06-22 05:34:42 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|