1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-27 22:18:52 +00:00

Can delete notifications related to a friendship request

This commit is contained in:
Pierre HUBERT 2020-03-24 18:29:56 +01:00
parent 4bf99cb550
commit 9ced519618
3 changed files with 47 additions and 9 deletions

View File

@ -53,9 +53,9 @@ export interface NotifBuilder {
seen ?: boolean,
fromUserID: number,
destUserID ?: number,
onElemID: number,
onElemID ?: number,
onElemType: NotifElemType,
type: NotifEventType,
type ?: NotifEventType,
eventVisibility ?: NotifEventVisibility,
fromContainerID ?: number,
fromContainerType ?: NotifElemType
@ -67,9 +67,9 @@ export class Notif implements NotifBuilder {
seen ?: boolean;
fromUserID: number;
destUserID ?: number;
onElemID: number;
onElemID ?: number;
onElemType: NotifElemType;
type: NotifEventType;
type ?: NotifEventType;
eventVisibility ?: NotifEventVisibility;
fromContainerID ?: number;
fromContainerType ?: NotifElemType;

View File

@ -197,6 +197,22 @@ export class NotificationsHelper {
)
}
/**
* Delete notifications
*
* @param n Notification
*/
public static async Delete(n: Notif) {
// Delete a specific notification
if(n.hasId)
throw new Error("Please implement notification deletion with known ID!");
// Delete wider range of notifications
else
await DatabaseHelper.DeleteRows(NOTIFICATIONS_TABLE, this.NotifToDB(n, false))
}
/**
* Count the number of unread notifications of a user
*

View File

@ -32,20 +32,42 @@ export class NotificationsUtils {
* Create & push friendship request notification
*
* @param fromUser Source user ID
* @param toUser Destination user ID
* @param destUser Destination user ID
* @param action The kind of action
*/
public static async CreateFriendsNotifications(fromUser: number, toUser: number, action: NotifEventType) {
// TODO : Delete all the previous notifications
public static async CreateFriendsNotifications(fromUser: number, destUser: number, action: NotifEventType) {
await this.DeleteNotificationsFrienshipRequest(fromUser, destUser);
// PUsh the notification
// Push the notification
await NotificationsHelper.Push(new Notif({
fromUserID: fromUser,
destUserID: toUser,
destUserID: destUser,
onElemID: fromUser, // Same as fromUser
onElemType: NotifElemType.FRIENDSHIP_REQUEST,
type: action
}));
}
/**
* Delete all the notifications related to a friendship request between two users
*
* @param userOne First user
* @param userTwo Second user
*/
public static async DeleteNotificationsFrienshipRequest(userOne: number, userTwo: number) {
// Delete notifications in two ways
await NotificationsHelper.Delete(new Notif({
onElemType: NotifElemType.FRIENDSHIP_REQUEST,
destUserID: userOne,
fromUserID: userTwo,
}));
await NotificationsHelper.Delete(new Notif({
onElemType: NotifElemType.FRIENDSHIP_REQUEST,
destUserID: userTwo,
fromUserID: userOne,
}));
}
}