Add notifications to user when a follow profile posted
This commit is contained in:
@@ -198,6 +198,16 @@ userDB = (DB) => {
|
||||
});
|
||||
}
|
||||
|
||||
DB.getFollowingTheProfile = async (profileId) => {
|
||||
//const profile_id = DB.ObjectID(profileId);
|
||||
let r = await DB.profileCols.find({ following: (profileId+'') })
|
||||
.toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return [];
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.getData = async (profileid, key) => {
|
||||
let profile = await DB.getProfile(profileid);
|
||||
return profile.data[key];
|
||||
|
||||
@@ -445,6 +445,21 @@ const Notifications = {
|
||||
return this.yourGroupGotANewPost(profile, profile, message, post);
|
||||
}
|
||||
},
|
||||
async yourSubscriptionProfileHasNewPost(post) {
|
||||
const whoPostedId = post.profileid;
|
||||
const message = post.content;
|
||||
const DB = await DBGetter.getDB;
|
||||
const profile = await DB.getProfileCache(whoPostedId);
|
||||
const subscribed_profiles = await DB.getFollowingTheProfile(whoPostedId);
|
||||
subscribed_profiles.forEach((subscribed_id, index) => {
|
||||
const userProfile = subscribed_profiles[index];
|
||||
if (userProfile._id == whoPostedId._id) return 0;
|
||||
const notifBody = `${profile.profile.firstName} posted: ${message.substring(0, 50)}...`;
|
||||
sendPushNotification(userProfile.token, notifBody, {});
|
||||
//sendWebNotification(userProfile.webSubscription, notifBody, message);
|
||||
DB.addNotification(userProfile._id, notifBody, post._id, null, profile._id);
|
||||
});
|
||||
},
|
||||
youHaveAnInvitation,
|
||||
broadcastNews,
|
||||
async yourGroupHasARequest(requesterProfileId, groupId) {
|
||||
|
||||
@@ -163,9 +163,12 @@ DB.getDB.then((DB) => {
|
||||
post = postObj.toObj();
|
||||
post._id = dbr.insertedId;
|
||||
if ((post.toProfile && post.toProfile != post.profileid) || post.nonOrganicType == 'News') {
|
||||
Notifications.youGotANewPost(post);
|
||||
await Notifications.youGotANewPost(post);
|
||||
}
|
||||
await Notifications.yourGroupMakeANewPost(post);
|
||||
if(!isGroupPrivate){
|
||||
await Notifications.yourSubscriptionProfileHasNewPost(post);
|
||||
}
|
||||
Notifications.yourGroupGotANewPost(post);
|
||||
return res.json({
|
||||
status: "ok",
|
||||
...post
|
||||
|
||||
Reference in New Issue
Block a user