mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 13:47:33 +01:00
refactor: conversation mongo query - add text/userStyle/contributor - sort inside
This commit is contained in:
@@ -86,20 +86,23 @@ export async function listConversations (owner) {
|
||||
{
|
||||
$group: {
|
||||
_id: '$uuid',
|
||||
user: {$first: '$user' },
|
||||
username: {$first: '$username' },
|
||||
timestamp: {$max: '$timestamp'}, // sort before group doesn't work - use the max value to sort it again after
|
||||
user: {$last: '$user' },
|
||||
username: {$last: '$username' },
|
||||
timestamp: {$last: '$timestamp'},
|
||||
text: {$last: '$text'},
|
||||
userStyles: {$last: '$userStyles'},
|
||||
contributor: {$last: '$contributor'},
|
||||
count: {$sum: 1},
|
||||
},
|
||||
},
|
||||
{ $sort: {timestamp: -1}}, // sort by latest message
|
||||
]);
|
||||
|
||||
const conversationsList = orderBy(await query.exec(), ['timestamp'], ['desc']);
|
||||
const conversationsList = await query.exec();
|
||||
|
||||
const conversations = conversationsList.map(({_id, user, username, timestamp}) => ({
|
||||
uuid: _id,
|
||||
user,
|
||||
username,
|
||||
timestamp,
|
||||
const conversations = conversationsList.map((res) => ({
|
||||
uuid: res._id,
|
||||
...res,
|
||||
}));
|
||||
|
||||
return conversations;
|
||||
|
||||
Reference in New Issue
Block a user