Add notifications viewed flag endpoint and persistence
This commit is contained in:
+24
-1
@@ -284,13 +284,36 @@ userDB = (DB) => {
|
||||
postid,
|
||||
commentIndx,
|
||||
actorid,
|
||||
viewed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
return DB.profileCols.updateOne({ _id }, update).catch((err) => {
|
||||
const r = await DB.profileCols.updateOne({ _id }, update).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
if (userProfileCache[profileid]) delete userProfileCache[profileid];
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.markNotificationsViewed = async (profileid) => {
|
||||
const _id = DB.ObjectID(profileid);
|
||||
const update = {
|
||||
$set: {
|
||||
"notifications.$[n].viewed": true
|
||||
}
|
||||
};
|
||||
const options = {
|
||||
arrayFilters: [
|
||||
{ "n.viewed": { $ne: true } }
|
||||
]
|
||||
};
|
||||
const r = await DB.profileCols.updateOne({ _id }, update, options).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
if (userProfileCache[profileid]) delete userProfileCache[profileid];
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.isSubscriptor = async (profileid) => {
|
||||
|
||||
@@ -784,6 +784,26 @@ DB.getDB.then((DB) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/notifications/viewed", async (req, res) => {
|
||||
try {
|
||||
const profileid = getProfileId(req);
|
||||
const result = await DB.markNotificationsViewed(profileid);
|
||||
if (!result) {
|
||||
return res.status(400).json({
|
||||
status: "Could not update notifications"
|
||||
});
|
||||
}
|
||||
return res.json({
|
||||
status: "ok"
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error marking notifications as viewed", error);
|
||||
return res.status(500).json({
|
||||
status: "Internal server error"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /user/{id}:
|
||||
|
||||
Reference in New Issue
Block a user