Browse Source

Merge pull request #4710 from weseek/feat/81696-81698-create-like-event

feat: 81696 81698 create like event
Yuki Takei 4 years ago
parent
commit
87da1b6af1

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

@@ -79,6 +79,10 @@ const InAppNotificationElm = (props: Props): JSX.Element | null => {
   let actionIcon: string;
 
   switch (actionType) {
+    case 'PAGE_LIKE':
+      actionMsg = 'liked';
+      actionIcon = 'icon-like';
+      break;
     case 'PAGE_UPDATE':
       actionMsg = 'updated on';
       actionIcon = 'ti-agenda';

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

@@ -255,6 +255,10 @@ module.exports = (crowi) => {
     res.apiv3({ result });
 
     if (isLiked) {
+      const pageEvent = crowi.event('page');
+      // in-app notification
+      pageEvent.emit('like', page, req.user);
+
       try {
         // global notification
         await globalNotificationService.fire(GlobalNotificationSetting.EVENT.PAGE_LIKE, page, req.user);

+ 12 - 2
packages/app/src/server/service/page.js

@@ -31,6 +31,9 @@ class PageService {
     // create
     this.pageEvent.on('create', this.pageEvent.onCreate);
 
+    // createMany
+    this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
+
     // update
     this.pageEvent.on('update', async(page, user) => {
 
@@ -64,8 +67,15 @@ class PageService {
       }
     });
 
-    // createMany
-    this.pageEvent.on('createMany', this.pageEvent.onCreateMany);
+    // likes
+    this.pageEvent.on('like', async(page, user) => {
+      try {
+        await this.createAndSendNotifications(page, user, ActivityDefine.ACTION_PAGE_LIKE);
+      }
+      catch (err) {
+        logger.error(err);
+      }
+    });
   }
 
 

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

@@ -1,6 +1,7 @@
 const MODEL_PAGE = 'Page';
 const MODEL_COMMENT = 'Comment';
 
+const ACTION_PAGE_LIKE = 'PAGE_LIKE';
 const ACTION_PAGE_UPDATE = 'PAGE_UPDATE';
 const ACTION_PAGE_RENAME = 'PAGE_RENAME';
 const ACTION_PAGE_DELETE = 'PAGE_DELETE';
@@ -17,6 +18,7 @@ const getSupportEventModelNames = () => {
 
 const getSupportActionNames = () => {
   return [
+    ACTION_PAGE_LIKE,
     ACTION_PAGE_UPDATE,
     ACTION_PAGE_RENAME,
     ACTION_PAGE_DELETE,
@@ -29,6 +31,7 @@ const activityDefine = {
   MODEL_PAGE,
   MODEL_COMMENT,
 
+  ACTION_PAGE_LIKE,
   ACTION_PAGE_UPDATE,
   ACTION_PAGE_RENAME,
   ACTION_PAGE_DELETE,