mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can delete notifications related to a friendship request
This commit is contained in:
parent
4bf99cb550
commit
9ced519618
@ -53,9 +53,9 @@ export interface NotifBuilder {
|
|||||||
seen ?: boolean,
|
seen ?: boolean,
|
||||||
fromUserID: number,
|
fromUserID: number,
|
||||||
destUserID ?: number,
|
destUserID ?: number,
|
||||||
onElemID: number,
|
onElemID ?: number,
|
||||||
onElemType: NotifElemType,
|
onElemType: NotifElemType,
|
||||||
type: NotifEventType,
|
type ?: NotifEventType,
|
||||||
eventVisibility ?: NotifEventVisibility,
|
eventVisibility ?: NotifEventVisibility,
|
||||||
fromContainerID ?: number,
|
fromContainerID ?: number,
|
||||||
fromContainerType ?: NotifElemType
|
fromContainerType ?: NotifElemType
|
||||||
@ -67,9 +67,9 @@ export class Notif implements NotifBuilder {
|
|||||||
seen ?: boolean;
|
seen ?: boolean;
|
||||||
fromUserID: number;
|
fromUserID: number;
|
||||||
destUserID ?: number;
|
destUserID ?: number;
|
||||||
onElemID: number;
|
onElemID ?: number;
|
||||||
onElemType: NotifElemType;
|
onElemType: NotifElemType;
|
||||||
type: NotifEventType;
|
type ?: NotifEventType;
|
||||||
eventVisibility ?: NotifEventVisibility;
|
eventVisibility ?: NotifEventVisibility;
|
||||||
fromContainerID ?: number;
|
fromContainerID ?: number;
|
||||||
fromContainerType ?: NotifElemType;
|
fromContainerType ?: NotifElemType;
|
||||||
|
@ -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
|
* Count the number of unread notifications of a user
|
||||||
*
|
*
|
||||||
|
@ -32,20 +32,42 @@ export class NotificationsUtils {
|
|||||||
* Create & push friendship request notification
|
* Create & push friendship request notification
|
||||||
*
|
*
|
||||||
* @param fromUser Source user ID
|
* @param fromUser Source user ID
|
||||||
* @param toUser Destination user ID
|
* @param destUser Destination user ID
|
||||||
* @param action The kind of action
|
* @param action The kind of action
|
||||||
*/
|
*/
|
||||||
public static async CreateFriendsNotifications(fromUser: number, toUser: number, action: NotifEventType) {
|
public static async CreateFriendsNotifications(fromUser: number, destUser: number, action: NotifEventType) {
|
||||||
// TODO : Delete all the previous notifications
|
await this.DeleteNotificationsFrienshipRequest(fromUser, destUser);
|
||||||
|
|
||||||
// PUsh the notification
|
// Push the notification
|
||||||
await NotificationsHelper.Push(new Notif({
|
await NotificationsHelper.Push(new Notif({
|
||||||
fromUserID: fromUser,
|
fromUserID: fromUser,
|
||||||
destUserID: toUser,
|
destUserID: destUser,
|
||||||
onElemID: fromUser, // Same as fromUser
|
onElemID: fromUser, // Same as fromUser
|
||||||
onElemType: NotifElemType.FRIENDSHIP_REQUEST,
|
onElemType: NotifElemType.FRIENDSHIP_REQUEST,
|
||||||
type: action
|
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,
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user