@abtnode/util 1.16.43-beta-20250507-124320-c405ab23 → 1.16.43-beta-20250508-132430-79f0da2d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  const { joinURL } = require('ufo');
2
+ const isEmpty = require('lodash/isEmpty');
2
3
  const { getConfigByChainId, EVM_PREFIX } = require('./config');
3
4
 
4
5
  const isEVMChain = (chainId) => {
@@ -61,6 +62,68 @@ const getImagePath = (url) => {
61
62
  return getImageBinFilePath(url);
62
63
  };
63
64
 
65
+ /**
66
+ * 判断通知是否包含activity
67
+ * @param {Object} notification - 通知对象
68
+ * @returns {boolean} - 是否包含activity
69
+ */
70
+ const isActivityIncluded = (notification) => {
71
+ return !isEmpty(notification.activity) && !!notification.activity.type && !!notification.activity.actor;
72
+ };
73
+
74
+ /**
75
+ * 判断 actor 是否是用户的 DID
76
+ * actor 的类型有两种 1) 用户 2) 组件
77
+ * @param {*} notification
78
+ * @returns
79
+ */
80
+ const isUserActor = (notification) => {
81
+ // 1. 如果是 isActivityIncluded 并且 notification 中有 actorInfo 则认为是用户
82
+ // 2. 如果是 isActivityIncluded 并且 actorInfo 没有查询到用户,则认为是 component
83
+ return isActivityIncluded(notification) && !!notification.actorInfo && !!notification.actorInfo.did;
84
+ };
85
+
86
+ /**
87
+ * Activity types enum for type safety
88
+ * @readonly
89
+ * @enum {string}
90
+ */
91
+ const ACTIVITY_TYPES = {
92
+ COMMENT: 'comment',
93
+ LIKE: 'like',
94
+ FOLLOW: 'follow',
95
+ TIPS: 'tips',
96
+ MENTION: 'mention',
97
+ ASSIGN: 'assign',
98
+ UN_ASSIGN: 'un_assign',
99
+ };
100
+
101
+ /**
102
+ * Activity descriptions mapping
103
+ * @type {Object.<string, React.ReactNode>}
104
+ */
105
+ const ACTIVITY_DESCRIPTIONS = {
106
+ [ACTIVITY_TYPES.COMMENT]: (targetType, count, isAuthor) =>
107
+ count > 1
108
+ ? `have left ${count} comments on ${isAuthor ? 'your' : 'the'} ${targetType}:`
109
+ : `has commented on ${isAuthor ? 'your' : 'the'} ${targetType}:`,
110
+ [ACTIVITY_TYPES.LIKE]: (targetType, count, isAuthor) =>
111
+ count > 1
112
+ ? `have liked ${isAuthor ? 'your' : 'the'} ${targetType}:`
113
+ : `has liked ${isAuthor ? 'your' : 'the'} ${targetType}:`,
114
+ [ACTIVITY_TYPES.FOLLOW]: (targetType, count) => (count > 1 ? 'have followed you' : 'has followed you'),
115
+ [ACTIVITY_TYPES.TIPS]: (targetType, count, isAuthor) =>
116
+ count > 1
117
+ ? `left tips for ${isAuthor ? 'your' : 'the'} ${targetType}:`
118
+ : `left a tip for ${isAuthor ? 'your' : 'the'} ${targetType}:`,
119
+ [ACTIVITY_TYPES.MENTION]: (targetType, count, isAuthor) =>
120
+ count > 1
121
+ ? `have mentioned you in ${isAuthor ? 'your' : 'the'} ${targetType}:`
122
+ : `mentioned you in ${isAuthor ? 'your' : 'the'} ${targetType}:`,
123
+ [ACTIVITY_TYPES.ASSIGN]: () => 'has assigned you a task: ',
124
+ [ACTIVITY_TYPES.UN_ASSIGN]: () => 'has revoked your task assignment: ',
125
+ };
126
+
64
127
  // 导出所有函数
65
128
  module.exports = {
66
129
  isEVMChain,
@@ -71,4 +134,7 @@ module.exports = {
71
134
  removeNotificationQueryParams,
72
135
  getImagePath,
73
136
  getImageBinFilePath,
137
+ isActivityIncluded,
138
+ isUserActor,
139
+ ACTIVITY_DESCRIPTIONS,
74
140
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.43-beta-20250507-124320-c405ab23",
6
+ "version": "1.16.43-beta-20250508-132430-79f0da2d",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,15 +18,15 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.43-beta-20250507-124320-c405ab23",
22
- "@arcblock/did": "1.20.4",
21
+ "@abtnode/constant": "1.16.43-beta-20250508-132430-79f0da2d",
22
+ "@arcblock/did": "1.20.6",
23
23
  "@arcblock/pm2": "^5.4.0",
24
- "@blocklet/constant": "1.16.43-beta-20250507-124320-c405ab23",
25
- "@blocklet/meta": "1.16.43-beta-20250507-124320-c405ab23",
26
- "@ocap/client": "1.20.4",
27
- "@ocap/mcrypto": "1.20.4",
28
- "@ocap/util": "1.20.4",
29
- "@ocap/wallet": "1.20.4",
24
+ "@blocklet/constant": "1.16.43-beta-20250508-132430-79f0da2d",
25
+ "@blocklet/meta": "1.16.43-beta-20250508-132430-79f0da2d",
26
+ "@ocap/client": "1.20.6",
27
+ "@ocap/mcrypto": "1.20.6",
28
+ "@ocap/util": "1.20.6",
29
+ "@ocap/wallet": "1.20.6",
30
30
  "archiver": "^7.0.1",
31
31
  "axios": "^1.7.9",
32
32
  "axios-mock-adapter": "^2.1.0",
@@ -86,5 +86,5 @@
86
86
  "fs-extra": "^11.2.0",
87
87
  "jest": "^29.7.0"
88
88
  },
89
- "gitHead": "4e5087dfaa52788676f313d23bfdd3ac68d63503"
89
+ "gitHead": "d9fc34b79948644ab30abc83e8e58ffb174332d6"
90
90
  }