|
|
@@ -171,6 +171,14 @@ module.exports = (crowi) => {
|
|
|
],
|
|
|
};
|
|
|
|
|
|
+ const getDefaultSubscriptionStatus = async(pageId, userId) => {
|
|
|
+ console.log(pageId, userId);
|
|
|
+ const page = await Page.findById(pageId);
|
|
|
+ if (!page) throw new Error('Page not found');
|
|
|
+ const targetUsers = await page.getNotificationTargetUsers();
|
|
|
+ return targetUsers.some(user => user.toString() === userId.toString());
|
|
|
+ };
|
|
|
+
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
@@ -542,13 +550,7 @@ module.exports = (crowi) => {
|
|
|
const userId = req.user._id;
|
|
|
try {
|
|
|
const subscription = await Subscription.findByUserIdAndTargetId(userId, pageId);
|
|
|
- const getDefaultStatus = async() => {
|
|
|
- const page = await Page.findById(pageId);
|
|
|
- if (!page) throw new Error('Page not found');
|
|
|
- const targetUsers = await page.getNotificationTargetUsers();
|
|
|
- return targetUsers.some(user => user.toString() === userId.toString());
|
|
|
- };
|
|
|
- const subscribing = subscription ? subscription.isSubscribing() : await getDefaultStatus();
|
|
|
+ const subscribing = subscription ? subscription.isSubscribing() : await getDefaultSubscriptionStatus();
|
|
|
return res.apiv3({ subscribing });
|
|
|
}
|
|
|
catch (err) {
|