فهرست منبع

Merge branch 'feat/notification' into imprv/80008-make-page-title-strong

Shun Miyazawa 4 سال پیش
والد
کامیت
5895bc74c4

+ 3 - 4
packages/app/src/components/InAppNotification/InAppNotification.tsx

@@ -2,7 +2,7 @@ import React from 'react';
 
 
 import { UserPicture } from '@growi/ui';
 import { UserPicture } from '@growi/ui';
 import { InAppNotification as IInAppNotification } from '../../interfaces/in-app-notification';
 import { InAppNotification as IInAppNotification } from '../../interfaces/in-app-notification';
-import { PageUpdatedNotification, PageCommentCreatedNotification, PageCommentUpdatedNotification } from './NotificationContent';
+import { PageUpdateNotification, PageCommentNotification } from './NotificationContent';
 
 
 interface Props {
 interface Props {
   notification: IInAppNotification
   notification: IInAppNotification
@@ -55,11 +55,10 @@ export const InAppNotification = (props: Props): JSX.Element => {
     switch (componentName) {
     switch (componentName) {
       // TODO Is the naming of componentName too subtle?
       // TODO Is the naming of componentName too subtle?
       case 'Page:UPDATE':
       case 'Page:UPDATE':
-        return <PageUpdatedNotification {...propsNew} onClick={props.onClick(props.notification)} />;
+        return <PageUpdateNotification {...propsNew} onClick={props.onClick(props.notification)} />;
       case 'Page:COMMENT_CREATE':
       case 'Page:COMMENT_CREATE':
-        return <PageCommentCreatedNotification {...propsNew} onClick={props.onClick(props.notification)} />;
       case 'Page:COMMENT_UPDATE':
       case 'Page:COMMENT_UPDATE':
-        return <PageCommentUpdatedNotification {...propsNew} onClick={props.onClick(props.notification)} />;
+        return <PageCommentNotification {...propsNew} onClick={props.onClick(props.notification)} />;
       default:
       default:
         return <></>;
         return <></>;
     }
     }

+ 2 - 15
packages/app/src/components/InAppNotification/NotificationContent.tsx

@@ -11,7 +11,7 @@ interface Props {
   onClick: () => void
   onClick: () => void
 }
 }
 
 
-export const PageCommentCreatedNotification = (props: Props): JSX.Element => {
+export const PageCommentNotification = (props: Props): JSX.Element => {
 
 
   return (
   return (
     <>
     <>
@@ -24,20 +24,7 @@ export const PageCommentCreatedNotification = (props: Props): JSX.Element => {
   );
   );
 };
 };
 
 
-export const PageCommentUpdatedNotification = (props: Props): JSX.Element => {
-
-  return (
-    <>
-      <div>
-        <b>{props.actionUsers}</b> comment updated on <PagePath notification={props.notification} />
-      </div>
-      <i className="fa fa-comment-o mr-2" />
-      <FormattedDistanceDate id={props.notification._id} date={props.notification.createdAt} isShowTooltip={false} />
-    </>
-  );
-};
-
-export const PageUpdatedNotification = (props: Props): JSX.Element => {
+export const PageUpdateNotification = (props: Props): JSX.Element => {
 
 
   return (
   return (
     <>
     <>

+ 10 - 0
packages/app/src/server/routes/apiv3/in-app-notification.ts

@@ -1,6 +1,7 @@
 import { InAppNotification } from '../../models/in-app-notification';
 import { InAppNotification } from '../../models/in-app-notification';
 
 
 const express = require('express');
 const express = require('express');
+const { serializeUserSecurely } = require('../../models/serializers/user-serializer');
 
 
 const router = express.Router();
 const router = express.Router();
 
 
@@ -10,6 +11,7 @@ module.exports = (crowi) => {
   const loginRequiredStrictly = require('../../middlewares/login-required')(crowi);
   const loginRequiredStrictly = require('../../middlewares/login-required')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
   const csrf = require('../../middlewares/csrf')(crowi);
   const inAppNotificationService = crowi.inAppNotificationService;
   const inAppNotificationService = crowi.inAppNotificationService;
+  const User = crowi.model('User');
 
 
   router.get('/list', accessTokenParser, loginRequiredStrictly, async(req, res) => {
   router.get('/list', accessTokenParser, loginRequiredStrictly, async(req, res) => {
     const user = req.user;
     const user = req.user;
@@ -27,6 +29,14 @@ module.exports = (crowi) => {
     const requestLimit = limit + 1;
     const requestLimit = limit + 1;
 
 
     const paginationResult = await inAppNotificationService.getLatestNotificationsByUser(user._id, requestLimit, offset);
     const paginationResult = await inAppNotificationService.getLatestNotificationsByUser(user._id, requestLimit, offset);
+
+    // TODO: serialize actionUsers as well by #80112
+    paginationResult.docs.forEach((doc) => {
+      if (doc.user != null && doc.user instanceof User) {
+        doc.user = serializeUserSecurely(doc.user);
+      }
+    });
+
     return res.apiv3(paginationResult);
     return res.apiv3(paginationResult);
 
 
   });
   });