|
|
@@ -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);
|
|
|
@@ -205,7 +205,7 @@ class PageService {
|
|
|
// delete completely
|
|
|
this.pageEvent.on('deleteCompletely', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, null, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE_COMPLETELY);
|
|
|
+ await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE_COMPLETELY);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -215,7 +215,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);
|
|
|
@@ -225,7 +225,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);
|
|
|
@@ -235,7 +235,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);
|
|
|
@@ -2242,7 +2242,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);
|
|
|
@@ -2256,12 +2256,12 @@ class PageService {
|
|
|
};
|
|
|
const activity = await activityService.createByParameters(parameters);
|
|
|
// Get user to be notified
|
|
|
- const targetUsers = await activity.getNotificationTargetUsers();
|
|
|
- if (descendantPages != null) {
|
|
|
+ let targetUsers = await activity.getNotificationTargetUsers();
|
|
|
+ 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()));
|
|
|
- targetUsers.concat(await User.find({
|
|
|
+ targetUsers = targetUsers.concat(await User.find({
|
|
|
_id: { $in: descendantsUsers },
|
|
|
status: User.STATUS_ACTIVE,
|
|
|
}).distinct('_id'));
|