mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
And frienship notifications support
This commit is contained in:
parent
27a0c7d1c8
commit
4bf99cb550
@ -2,6 +2,8 @@ import { Friend } from "../entities/Friend";
|
|||||||
import { RequestHandler } from "../entities/RequestHandler";
|
import { RequestHandler } from "../entities/RequestHandler";
|
||||||
import { FriendsHelper } from "../helpers/FriendsHelper";
|
import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||||
import { UserHelper } from "../helpers/UserHelper";
|
import { UserHelper } from "../helpers/UserHelper";
|
||||||
|
import { NotificationsUtils } from "../utils/NotificationsUtils";
|
||||||
|
import { NotifEventType } from "../entities/Notification";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Friends controller
|
* Friends controller
|
||||||
@ -110,7 +112,9 @@ export class FriendsController {
|
|||||||
// Send the request
|
// Send the request
|
||||||
await FriendsHelper.SendRequest(h.getUserId(), friendID);
|
await FriendsHelper.SendRequest(h.getUserId(), friendID);
|
||||||
|
|
||||||
// TODO : create the notification
|
// Create the notification
|
||||||
|
await NotificationsUtils.CreateFriendsNotifications(
|
||||||
|
h.getUserId(), friendID, NotifEventType.SENT_FRIEND_REQUEST)
|
||||||
|
|
||||||
h.success("Send (create) the friendship request");
|
h.success("Send (create) the friendship request");
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export enum NotifElemType {
|
export enum NotifElemType {
|
||||||
|
EMPTY = "",
|
||||||
USER_PAGE = "user_page",
|
USER_PAGE = "user_page",
|
||||||
GROUP_PAGE = "group_page",
|
GROUP_PAGE = "group_page",
|
||||||
CONVERSATION = "conversation",
|
CONVERSATION = "conversation",
|
||||||
|
@ -105,7 +105,21 @@ export class NotificationsHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Frienship notifications
|
||||||
|
else if(n.onElemType == NotifElemType.FRIENDSHIP_REQUEST) {
|
||||||
|
n.fromContainerID = 0
|
||||||
|
n.fromContainerType = NotifElemType.EMPTY;
|
||||||
|
await this.PushPrivate(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO : continue
|
// TODO : continue
|
||||||
|
|
||||||
|
// Unsupported notification type
|
||||||
|
else {
|
||||||
|
console.error(n)
|
||||||
|
throw new Error("Type of notification not supported!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,4 +27,25 @@ export class NotificationsUtils {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create & push friendship request notification
|
||||||
|
*
|
||||||
|
* @param fromUser Source user ID
|
||||||
|
* @param toUser 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
|
||||||
|
|
||||||
|
// PUsh the notification
|
||||||
|
await NotificationsHelper.Push(new Notif({
|
||||||
|
fromUserID: fromUser,
|
||||||
|
destUserID: toUser,
|
||||||
|
onElemID: fromUser, // Same as fromUser
|
||||||
|
onElemType: NotifElemType.FRIENDSHIP_REQUEST,
|
||||||
|
type: action
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user