|
|
@@ -160,7 +160,7 @@ class PageService {
|
|
|
this.pageEvent.onUpdate();
|
|
|
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, null, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_UPDATE);
|
|
|
+ await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_UPDATE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -173,7 +173,7 @@ class PageService {
|
|
|
const isRecursively = descendantPages != null;
|
|
|
const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_RENAME : SUPPORTED_ACTION_TYPE.ACTION_PAGE_RENAME;
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, descendantPages, user, action);
|
|
|
+ await this.createAndSendNotifications(page, user, action, descendantPages);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -183,7 +183,7 @@ class PageService {
|
|
|
// duplicate
|
|
|
this.pageEvent.on('duplicate', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, null, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DUPLICATE);
|
|
|
+ await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DUPLICATE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -195,7 +195,7 @@ class PageService {
|
|
|
const isRecursively = descendantPages != null;
|
|
|
const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_DELETE : SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE;
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, descendantPages, user, action);
|
|
|
+ await this.createAndSendNotifications(page, user, action, descendantPages);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -208,7 +208,7 @@ class PageService {
|
|
|
console.log('isRecursively?\n', isRecursively);
|
|
|
const action = isRecursively ? SUPPORTED_ACTION_TYPE.ACTION_PAGE_RECURSIVELY_DELETE_COMPLETELY : SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE_COMPLETELY;
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, descendantPages, user, action);
|
|
|
+ await this.createAndSendNotifications(page, user, action, descendantPages);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -218,7 +218,7 @@ class PageService {
|
|
|
// revert
|
|
|
this.pageEvent.on('revert', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, null, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_REVERT);
|
|
|
+ await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_REVERT);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -228,7 +228,7 @@ class PageService {
|
|
|
// likes
|
|
|
this.pageEvent.on('like', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, null, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_LIKE);
|
|
|
+ await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_LIKE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -238,7 +238,7 @@ class PageService {
|
|
|
// bookmark
|
|
|
this.pageEvent.on('bookmark', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, null, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_BOOKMARK);
|
|
|
+ await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_BOOKMARK);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -2247,7 +2247,7 @@ class PageService {
|
|
|
return shortBodiesMap;
|
|
|
}
|
|
|
|
|
|
- private async createAndSendNotifications(page, descendantPages, user, action) {
|
|
|
+ private async createAndSendNotifications(page: PageDocument, user: any, action: any, descendantPages?: PageDocument[]) {
|
|
|
const { activityService, inAppNotificationService } = this.crowi;
|
|
|
|
|
|
const snapshot = stringifySnapshot(page);
|
|
|
@@ -2260,20 +2260,17 @@ class PageService {
|
|
|
action,
|
|
|
};
|
|
|
const activity = await activityService.createByParameters(parameters);
|
|
|
- console.log('What are the descendant pages\n', descendantPages);
|
|
|
// Get user to be notified
|
|
|
let targetUsers = await activity.getNotificationTargetUsers();
|
|
|
- if (descendantPages != null) {
|
|
|
+ if (descendantPages !== undefined && descendantPages.length > 0) {
|
|
|
const User = this.crowi.model('User');
|
|
|
const targetDescendantsUsers = await Subscription.getSubscriptions(descendantPages);
|
|
|
const descendantsUsers = targetDescendantsUsers.filter(item => (item.toString() !== user._id.toString()));
|
|
|
- console.log('Who are the target users?\n', descendantsUsers);
|
|
|
targetUsers = targetUsers.concat(await User.find({
|
|
|
_id: { $in: descendantsUsers },
|
|
|
status: User.STATUS_ACTIVE,
|
|
|
}).distinct('_id'));
|
|
|
}
|
|
|
- console.log('Who are the target users?\n', targetUsers);
|
|
|
// Create and send notifications
|
|
|
await inAppNotificationService.upsertByActivity(targetUsers, activity, snapshot);
|
|
|
await inAppNotificationService.emitSocketIo(targetUsers);
|