Просмотр исходного кода

Merge pull request #4736 from weseek/feat/81861-81860-create-bookmark-event

feat: 81861 81860 create bookmark event
Yuki Takei 4 лет назад
Родитель
Сommit
18ca814395

+ 4 - 0
packages/app/src/components/InAppNotification/InAppNotificationElm.tsx

@@ -83,6 +83,10 @@ const InAppNotificationElm = (props: Props): JSX.Element | null => {
       actionMsg = 'liked';
       actionIcon = 'icon-like';
       break;
+    case 'PAGE_BOOKMARK':
+      actionMsg = 'bookmarked on';
+      actionIcon = 'icon-star';
+      break;
     case 'PAGE_UPDATE':
       actionMsg = 'updated on';
       actionIcon = 'ti-agenda';

+ 4 - 0
packages/app/src/server/routes/apiv3/bookmarks.js

@@ -261,6 +261,10 @@ module.exports = (crowi) => {
       }
       if (bool) {
         bookmark = await Bookmark.add(page, req.user);
+
+        const pageEvent = crowi.event('page');
+        // in-app notification
+        pageEvent.emit('bookmark', page, req.user);
       }
       else {
         bookmark = await Bookmark.removeBookmark(page, req.user);

+ 10 - 0
packages/app/src/server/service/page.js

@@ -76,6 +76,16 @@ class PageService {
         logger.error(err);
       }
     });
+
+    // bookmark
+    this.pageEvent.on('bookmark', async(page, user) => {
+      try {
+        await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_BOOKMARK);
+      }
+      catch (err) {
+        logger.error(err);
+      }
+    });
   }
 
 

+ 3 - 0
packages/app/src/server/util/activityDefine.ts

@@ -2,6 +2,7 @@ const MODEL_PAGE = 'Page';
 const MODEL_COMMENT = 'Comment';
 
 const ACTION_PAGE_LIKE = 'PAGE_LIKE';
+const ACTION_PAGE_BOOKMARK = 'PAGE_BOOKMARK';
 const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
 const ACTION_PAGE_RENAME = 'PAGE_RENAME';
 const ACTION_PAGE_DELETE = 'PAGE_DELETE';
@@ -19,6 +20,7 @@ const getSupportEventModelNames = () => {
 const getSupportActionNames = () => {
   return [
     ACTION_PAGE_LIKE,
+    ACTION_PAGE_BOOKMARK,
     ACTION_PAGE_UPDATE,
     ACTION_PAGE_RENAME,
     ACTION_PAGE_DELETE,
@@ -32,6 +34,7 @@ const activityDefine = {
   MODEL_COMMENT,
 
   ACTION_PAGE_LIKE,
+  ACTION_PAGE_BOOKMARK,
   ACTION_PAGE_UPDATE,
   ACTION_PAGE_RENAME,
   ACTION_PAGE_DELETE,