|
|
@@ -6,7 +6,9 @@ import escapeStringRegexp from 'escape-string-regexp';
|
|
|
import mongoose, { ObjectId, QueryCursor } from 'mongoose';
|
|
|
import streamToPromise from 'stream-to-promise';
|
|
|
|
|
|
-import { SUPPORTED_TARGET_MODEL_TYPE, SUPPORTED_ACTION_TYPE } from '~/interfaces/activity';
|
|
|
+import {
|
|
|
+ SUPPORTED_TARGET_MODEL_TYPE, SUPPORTED_ACTION_TYPE, SupportedActionType, ISnapshot,
|
|
|
+} from '~/interfaces/activity';
|
|
|
import { Ref } from '~/interfaces/common';
|
|
|
import { V5ConversionErrCode } from '~/interfaces/errors/v5-conversion-error';
|
|
|
import { HasObjectId } from '~/interfaces/has-object-id';
|
|
|
@@ -159,7 +161,7 @@ class PageService {
|
|
|
this.pageEvent.onUpdate();
|
|
|
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_UPDATE);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_UPDATE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -169,7 +171,7 @@ class PageService {
|
|
|
// rename
|
|
|
this.pageEvent.on('rename', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_RENAME);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_RENAME);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -179,7 +181,7 @@ class PageService {
|
|
|
// duplicate
|
|
|
this.pageEvent.on('duplicate', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DUPLICATE);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DUPLICATE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -189,7 +191,7 @@ class PageService {
|
|
|
// delete
|
|
|
this.pageEvent.on('delete', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -199,7 +201,7 @@ class PageService {
|
|
|
// delete completely
|
|
|
this.pageEvent.on('deleteCompletely', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE_COMPLETELY);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_DELETE_COMPLETELY);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -209,7 +211,7 @@ class PageService {
|
|
|
// revert
|
|
|
this.pageEvent.on('revert', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_REVERT);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_REVERT);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -219,7 +221,7 @@ class PageService {
|
|
|
// likes
|
|
|
this.pageEvent.on('like', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_LIKE);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_LIKE);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -229,7 +231,7 @@ class PageService {
|
|
|
// bookmark
|
|
|
this.pageEvent.on('bookmark', async(page, user) => {
|
|
|
try {
|
|
|
- await this.createAndSendNotifications(page, user, SUPPORTED_ACTION_TYPE.ACTION_PAGE_BOOKMARK);
|
|
|
+ await this.createAndSendNotifications(user, page, SUPPORTED_ACTION_TYPE.ACTION_PAGE_BOOKMARK);
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -2231,17 +2233,17 @@ class PageService {
|
|
|
return shortBodiesMap;
|
|
|
}
|
|
|
|
|
|
- private async createAndSendNotifications(page, user, action) {
|
|
|
+ private async createAndSendNotifications(user: IUserHasId, target: IPage, action: SupportedActionType) {
|
|
|
const { activityService, inAppNotificationService } = this.crowi;
|
|
|
|
|
|
- const snapshot = stringifySnapshot(page);
|
|
|
-
|
|
|
// Create activity
|
|
|
+ const snapshotForActivity: ISnapshot = { username: user.username };
|
|
|
const parameters = {
|
|
|
user: user._id,
|
|
|
targetModel: SUPPORTED_TARGET_MODEL_TYPE.MODEL_PAGE,
|
|
|
- target: page,
|
|
|
+ target,
|
|
|
action,
|
|
|
+ snapshot: snapshotForActivity,
|
|
|
};
|
|
|
const activity = await activityService.createByParameters(parameters);
|
|
|
|
|
|
@@ -2249,7 +2251,8 @@ class PageService {
|
|
|
const targetUsers = await activity.getNotificationTargetUsers();
|
|
|
|
|
|
// Create and send notifications
|
|
|
- await inAppNotificationService.upsertByActivity(targetUsers, activity, snapshot);
|
|
|
+ const snapshotForInAppNotification = stringifySnapshot(target);
|
|
|
+ await inAppNotificationService.upsertByActivity(targetUsers, activity, snapshotForInAppNotification);
|
|
|
await inAppNotificationService.emitSocketIo(targetUsers);
|
|
|
}
|
|
|
|