1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Can create a private conversation

This commit is contained in:
2019-12-07 12:00:28 +01:00
parent d348e58ecd
commit 19aec6942f
3 changed files with 63 additions and 0 deletions

View File

@ -342,6 +342,35 @@ export class ConversationsHelper {
}
/**
* Search for private conversations between two users
*
* @param user1 The first user
* @param user2 The second user
* @returns The entire list of found conversations
*/
public static async FindPrivate(user1: number, user2: number) : Promise<Array<number>> {
const result = await DatabaseHelper.Query({
table: USERS_TABLE,
tableAlias: "t1",
joins: [
{
table: USERS_TABLE,
tableAlias: "t2",
condition: "t1.conv_id = t2.conv_id"
}
],
where: {
"t1.user_id": user1,
"t2.user_id": user2
},
customWhere: "(SELECT COUNT(*) FROM " + USERS_TABLE + " WHERE conv_id = t1.conv_id) = 2",
fields: ["t1.conv_id AS conv_id"]
});
return result.map(r => r.conv_id);
}
/**
* Get the list of members of a conversation
*