1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-09-19 05:38:48 +00:00

Can get the list of unread conversations

This commit is contained in:
2019-12-07 17:35:14 +01:00
parent 94600597b4
commit 83e61f49ca
4 changed files with 90 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import { Conversation, BaseConversation } from "../entities/Conversation";
import { DatabaseHelper } from "./DatabaseHelper";
import { time } from "../utils/DateUtils";
import { ConversationMessage, BaseConversationMessage } from "../entities/ConversationMessage";
import { UnreadConversation } from "../entities/UnreadConversation";
/**
* Conversations helper
@@ -409,6 +410,52 @@ export class ConversationsHelper {
});
}
/**
* Get the list of unread conversations of the user
*
* @param userID Target user ID
*/
public static async GetListUnread(userID: number) : Promise<Array<UnreadConversation>> {
return (await DatabaseHelper.Query({
table: USERS_TABLE,
tableAlias: "users",
joins: [
// Join with conversations list table
{
table: LIST_TABLE,
tableAlias: "list",
condition: "users.conv_id = list.id"
},
// Join with message table to get the latest message
{
table: MESSAGES_TABLE,
tableAlias: "messages",
condition: "messages.conv_id = users.conv_id"
}
],
where: {
"users.user_id": userID,
"users.following": 1,
"users.saw_last_message": 0,
},
customWhere: "list.last_active = messages.time_insert",
order: "list.last_active DESC"
})).map(m => <UnreadConversation>{
id: m.conv_id,
name: m.name,
lastActive: m.last_active,
userID: m.user_id,
message: m.message,
});
}
/**
* Get the list of members of a conversation
*