Shunm634-source 3 лет назад
Родитель
Сommit
50ea9d79a7

+ 1 - 2
packages/app/src/interfaces/subscription.ts

@@ -1,5 +1,4 @@
-import { Ref } from 'react';
-
+import { Ref } from './common';
 import { IPage } from './page';
 import { IUser } from './user';
 

+ 4 - 1
packages/app/src/server/models/activity.ts

@@ -9,6 +9,8 @@ import {
   AllSupportedTargetModels, SupportedTargetModelType,
   AllSupportedEventModels, SupportedEventModelType,
 } from '~/interfaces/activity';
+import { Ref } from '~/interfaces/common';
+import { IPage } from '~/interfaces/page';
 
 import loggerFactory from '../../utils/logger';
 
@@ -23,7 +25,7 @@ export interface ActivityDocument extends Document {
   ip: string
   endpoint: string
   targetModel: SupportedTargetModelType
-  target: Types.ObjectId
+  target: Ref<IPage>
   eventModel: SupportedEventModelType
   event: Types.ObjectId
   action: SupportedActionType
@@ -60,6 +62,7 @@ const activitySchema = new Schema<ActivityDocument, ActivityModel>({
   },
   target: {
     type: Schema.Types.ObjectId,
+    ref: 'Page',
     refPath: 'targetModel',
   },
   eventModel: {

+ 5 - 4
packages/app/src/server/models/subscription.ts

@@ -1,4 +1,3 @@
-import { Ref } from 'react';
 
 import { getOrCreateModel } from '@growi/core';
 import {
@@ -6,6 +5,7 @@ import {
 } from 'mongoose';
 
 import { AllSupportedTargetModels } from '~/interfaces/activity';
+import { Ref } from '~/interfaces/common';
 import { IPage } from '~/interfaces/page';
 import { SubscriptionStatusType, AllSubscriptionStatusType, ISubscription } from '~/interfaces/subscription';
 import { IUser } from '~/interfaces/user';
@@ -15,7 +15,7 @@ export interface SubscriptionDocument extends ISubscription, Document {}
 export interface SubscriptionModel extends Model<SubscriptionDocument> {
   findByUserIdAndTargetId(userId: Types.ObjectId | string, targetId: Types.ObjectId | string): any
   upsertSubscription(user: Ref<IUser>, targetModel: string, target: Ref<IPage>, status: string): any
-  subscribeByPageId(user: Ref<IUser>, pageId: Types.ObjectId, status: string): any
+  subscribeByPageId(userId: Types.ObjectId, pageId: Types.ObjectId, status: string): any
   getSubscription(target: Ref<IPage>): Promise<Ref<IUser>[]>
   getUnsubscription(target: Ref<IPage>): Promise<Ref<IUser>[]>
   getSubscriptions(targets: Ref<IPage>[]): Promise<Ref<IUser>[]>
@@ -35,6 +35,7 @@ const subscriptionSchema = new Schema<SubscriptionDocument, SubscriptionModel>({
   },
   target: {
     type: Schema.Types.ObjectId,
+    ref: 'Page',
     refPath: 'targetModel',
     required: true,
   },
@@ -68,8 +69,8 @@ subscriptionSchema.statics.upsertSubscription = function(user, targetModel, targ
   return this.findOneAndUpdate(query, doc, options);
 };
 
-subscriptionSchema.statics.subscribeByPageId = function(user, pageId, status) {
-  return this.upsertSubscription(user, 'Page', pageId, status);
+subscriptionSchema.statics.subscribeByPageId = function(userId, pageId, status) {
+  return this.upsertSubscription(userId, 'Page', pageId, status);
 };
 
 subscriptionSchema.statics.getSubscription = async function(target: Ref<IPage>) {

+ 2 - 1
packages/app/src/server/service/activity.ts

@@ -4,6 +4,7 @@ import {
   IActivity, SupportedAction, SupportedActionType, AllSupportedActions, ActionGroupSize,
   AllEssentialActions, AllSmallGroupActions, AllMediumGroupActions, AllLargeGroupActions,
 } from '~/interfaces/activity';
+import { Ref } from '~/interfaces/common';
 import { IPage } from '~/interfaces/page';
 import Activity from '~/server/models/activity';
 
@@ -40,7 +41,7 @@ class ActivityService {
   }
 
   initActivityEventListeners(): void {
-    this.activityEvent.on('update', async(activityId: string, parameters, target?: IPage, descendantPages?: PageDocument[]) => {
+    this.activityEvent.on('update', async(activityId: string, parameters, target?: IPage, descendantPages?: Ref<IPage>[]) => {
       let activity: IActivity;
       const shoudUpdate = this.shoudUpdateActivity(parameters.action);
 

+ 3 - 2
packages/app/src/server/service/in-app-notification.ts

@@ -2,6 +2,7 @@ import { subDays } from 'date-fns';
 import { Types } from 'mongoose';
 
 import { AllEssentialActions, SupportedAction } from '~/interfaces/activity';
+import { Ref } from '~/interfaces/common';
 import { HasObjectId } from '~/interfaces/has-object-id';
 import { InAppNotificationStatuses, PaginateResult } from '~/interfaces/in-app-notification';
 import { IPage } from '~/interfaces/page';
@@ -52,7 +53,7 @@ export default class InAppNotificationService {
   }
 
   initActivityEventListeners(): void {
-    this.activityEvent.on('updated', async(activity: ActivityDocument, target: IPage, descendantPages?: PageDocument[]) => {
+    this.activityEvent.on('updated', async(activity: ActivityDocument, target: IPage, descendantPages?: Ref<IPage>[]) => {
       try {
         const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
         if (shouldNotification) {
@@ -200,7 +201,7 @@ export default class InAppNotificationService {
     return;
   };
 
-  createInAppNotification = async function(activity: ActivityDocument, target: IPage, descendantPages?: PageDocument[]): Promise<void> {
+  createInAppNotification = async function(activity: ActivityDocument, target: IPage, descendantPages?: Ref<IPage>[]): Promise<void> {
     const shouldNotification = activity != null && target != null && (AllEssentialActions as ReadonlyArray<string>).includes(activity.action);
     if (shouldNotification) {
       let mentionedUsers: IUser[] = [];