@nocobase/plugin-notification-in-app-message 1.9.0-beta.4 → 1.9.0-beta.6
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.
- package/dist/client/index.js +1 -1
- package/dist/client/observables/index.d.ts +0 -1
- package/dist/externalVersion.js +9 -9
- package/dist/locale/zh-CN.json +2 -2
- package/dist/server/InAppNotificationChannel.d.ts +2 -17
- package/dist/server/InAppNotificationChannel.js +28 -56
- package/dist/server/defineMyInAppChannels.d.ts +1 -3
- package/dist/server/defineMyInAppChannels.js +1 -2
- package/dist/server/defineMyInAppMessages.d.ts +1 -6
- package/dist/server/defineMyInAppMessages.js +27 -35
- package/package.json +2 -2
- package/dist/client/observables/sse.d.ts +0 -13
package/dist/externalVersion.js
CHANGED
|
@@ -9,24 +9,24 @@
|
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"react": "18.2.0",
|
|
12
|
-
"@nocobase/client": "1.9.0-beta.
|
|
13
|
-
"@nocobase/plugin-notification-manager": "1.9.0-beta.
|
|
14
|
-
"@nocobase/plugin-mobile": "1.9.0-beta.
|
|
15
|
-
"@nocobase/utils": "1.9.0-beta.
|
|
12
|
+
"@nocobase/client": "1.9.0-beta.6",
|
|
13
|
+
"@nocobase/plugin-notification-manager": "1.9.0-beta.6",
|
|
14
|
+
"@nocobase/plugin-mobile": "1.9.0-beta.6",
|
|
15
|
+
"@nocobase/utils": "1.9.0-beta.6",
|
|
16
16
|
"react-i18next": "11.18.6",
|
|
17
|
-
"@nocobase/server": "1.9.0-beta.
|
|
17
|
+
"@nocobase/server": "1.9.0-beta.6",
|
|
18
18
|
"sequelize": "6.35.2",
|
|
19
|
-
"@nocobase/actions": "1.9.0-beta.
|
|
20
|
-
"@nocobase/database": "1.9.0-beta.
|
|
19
|
+
"@nocobase/actions": "1.9.0-beta.6",
|
|
20
|
+
"@nocobase/database": "1.9.0-beta.6",
|
|
21
21
|
"antd": "5.24.2",
|
|
22
22
|
"@formily/reactive-react": "2.3.0",
|
|
23
|
-
"@formily/reactive": "2.3.0",
|
|
24
23
|
"antd-style": "3.7.1",
|
|
25
24
|
"@emotion/css": "11.13.0",
|
|
26
25
|
"@formily/react": "2.3.0",
|
|
27
26
|
"react-router-dom": "6.28.1",
|
|
28
27
|
"@formily/core": "2.3.0",
|
|
29
28
|
"@ant-design/icons": "5.6.1",
|
|
30
|
-
"@nocobase/plugin-workflow": "1.9.0-beta.
|
|
29
|
+
"@nocobase/plugin-workflow": "1.9.0-beta.6",
|
|
30
|
+
"@formily/reactive": "2.3.0",
|
|
31
31
|
"@formily/shared": "2.3.2"
|
|
32
32
|
};
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"Plain text": "纯文本",
|
|
23
23
|
"detail URL": "详情链接",
|
|
24
24
|
"Details page for desktop": "桌面端详情页",
|
|
25
|
-
"Support two types of links: internal links and external links. If using an internal link, the link starts with\"/\", for example, \"/admin\". If using an external link, the link starts with \"http\", for example, \"https://example.com\".": "支持两种链接类型:内部链接和外部链接。如果使用内部链接,链接以“/”开头,例如“/admin”。如果使用外部链接,链接以“http”开头,例如“https://example.com”。",
|
|
25
|
+
"Support two types of links: internal links and external links. If using an internal link, the link starts with \"/\", for example, \"/admin\". If using an external link, the link starts with \"http\", for example, \"https://example.com\".": "支持两种链接类型:内部链接和外部链接。如果使用内部链接,链接以“/”开头,例如“/admin”。如果使用外部链接,链接以“http”开头,例如“https://example.com”。",
|
|
26
26
|
"Mark as read": "标为已读",
|
|
27
27
|
"Mark as unread": "标为未读",
|
|
28
28
|
"Mark all as read": "全部标为已读",
|
|
29
|
-
"Support two types of links: internal links and external links. If using an internal link, the link starts with\"/\", for example, \"/m\". If using an external link, the link starts with \"http\", for example, \"https://example.com\".": "支持两种链接类型:内部链接和外部链接。如果使用内部链接,链接以“/”开头,例如“/m”。如果使用外部链接,链接以“http”开头,例如“https://example.com”。",
|
|
29
|
+
"Support two types of links: internal links and external links. If using an internal link, the link starts with \"/\", for example, \"/m\". If using an external link, the link starts with \"http\", for example, \"https://example.com\".": "支持两种链接类型:内部链接和外部链接。如果使用内部链接,链接以“/”开头,例如“/m”。如果使用外部链接,链接以“http”开头,例如“https://example.com”。",
|
|
30
30
|
"Details page for mobile": "移动端详情页",
|
|
31
31
|
"The message page has already been created.": "站内信页面已创建。",
|
|
32
32
|
"When select receivers from node result, only support ID of user (or IDs array of users). Others will not match any user.": "从节点结果中选择接收者时,仅支持用户ID(或用户ID数组)。其他将不匹配任何用户。"
|
|
@@ -6,26 +6,12 @@
|
|
|
6
6
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
|
-
/// <reference types="node" />
|
|
10
|
-
import { Application } from '@nocobase/server';
|
|
11
9
|
import { SendFnType, BaseNotificationChannel } from '@nocobase/plugin-notification-manager';
|
|
12
10
|
import { InAppMessageFormValues } from '../types';
|
|
13
|
-
import { PassThrough } from 'stream';
|
|
14
|
-
type UserID = string;
|
|
15
|
-
type ClientID = string;
|
|
16
11
|
export default class InAppNotificationChannel extends BaseNotificationChannel {
|
|
17
|
-
protected app: Application;
|
|
18
|
-
userClientsMap: Record<UserID, Record<ClientID, PassThrough>>;
|
|
19
|
-
constructor(app: Application);
|
|
20
12
|
load(): Promise<void>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
getClient: (userId: UserID, clientId: ClientID) => PassThrough;
|
|
24
|
-
removeClient: (userId: UserID, clientId: ClientID) => void;
|
|
25
|
-
sendDataToUser(userId: UserID, message: {
|
|
26
|
-
type: string;
|
|
27
|
-
data: any;
|
|
28
|
-
}): void;
|
|
13
|
+
onMessageCreated: (model: any, options: any) => Promise<void>;
|
|
14
|
+
onMessageUpdated: (model: any, options: any) => Promise<void>;
|
|
29
15
|
saveMessageToDB: ({ content, status, userId, title, channelName, receiveTimestamp, options, }: {
|
|
30
16
|
content: string;
|
|
31
17
|
userId: number;
|
|
@@ -38,4 +24,3 @@ export default class InAppNotificationChannel extends BaseNotificationChannel {
|
|
|
38
24
|
send: SendFnType<InAppMessageFormValues>;
|
|
39
25
|
defineActions(): void;
|
|
40
26
|
}
|
|
41
|
-
export {};
|
|
@@ -45,61 +45,38 @@ var import_parseUserSelectionConf = require("./parseUserSelectionConf");
|
|
|
45
45
|
var import_defineMyInAppMessages = __toESM(require("./defineMyInAppMessages"));
|
|
46
46
|
var import_defineMyInAppChannels = __toESM(require("./defineMyInAppChannels"));
|
|
47
47
|
class InAppNotificationChannel extends import_plugin_notification_manager.BaseNotificationChannel {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
userClientsMap;
|
|
48
|
+
// userClientsMap: Record<UserID, Record<ClientID, PassThrough>>;
|
|
49
|
+
// constructor(protected app: Application) {
|
|
50
|
+
// super(app);
|
|
51
|
+
// this.userClientsMap = {};
|
|
52
|
+
// }
|
|
54
53
|
async load() {
|
|
55
|
-
this.
|
|
54
|
+
this.app.db.on(`${import_types2.InAppMessagesDefinition.name}.afterCreate`, this.onMessageCreated);
|
|
55
|
+
this.app.db.on(`${import_types2.InAppMessagesDefinition.name}.afterUpdate`, this.onMessageUpdated);
|
|
56
56
|
this.defineActions();
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
onMessageCreated = async (model, options) => {
|
|
59
|
+
const userId = model.userId;
|
|
60
|
+
this.app.emit("ws:sendToTag", {
|
|
61
|
+
tagKey: "userId",
|
|
62
|
+
tagValue: userId,
|
|
63
|
+
message: {
|
|
64
|
+
type: "in-app-message:created",
|
|
65
|
+
payload: model.toJSON()
|
|
66
|
+
}
|
|
66
67
|
});
|
|
67
68
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return (_a = this.userClientsMap[userId]) == null ? void 0 : _a[clientId];
|
|
77
|
-
};
|
|
78
|
-
removeClient = (userId, clientId) => {
|
|
79
|
-
if (this.userClientsMap[userId]) {
|
|
80
|
-
delete this.userClientsMap[userId][clientId];
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
sendDataToUser(userId, message) {
|
|
84
|
-
const clients = this.userClientsMap[userId];
|
|
85
|
-
if (clients) {
|
|
86
|
-
for (const clientId in clients) {
|
|
87
|
-
const stream = clients[clientId];
|
|
88
|
-
stream.write(
|
|
89
|
-
`data: ${JSON.stringify({
|
|
90
|
-
type: message.type,
|
|
91
|
-
data: {
|
|
92
|
-
...message.data,
|
|
93
|
-
title: message.data.title || "",
|
|
94
|
-
content: message.data.content || ""
|
|
95
|
-
}
|
|
96
|
-
})}
|
|
97
|
-
|
|
98
|
-
`
|
|
99
|
-
);
|
|
69
|
+
onMessageUpdated = async (model, options) => {
|
|
70
|
+
const userId = model.userId;
|
|
71
|
+
this.app.emit("ws:sendToTag", {
|
|
72
|
+
tagKey: "userId",
|
|
73
|
+
tagValue: userId,
|
|
74
|
+
message: {
|
|
75
|
+
type: "in-app-message:updated",
|
|
76
|
+
payload: model.toJSON()
|
|
100
77
|
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
103
80
|
saveMessageToDB = async ({
|
|
104
81
|
content,
|
|
105
82
|
status,
|
|
@@ -148,13 +125,8 @@ class InAppNotificationChannel extends import_plugin_notification_manager.BaseNo
|
|
|
148
125
|
return { status: "success", message };
|
|
149
126
|
};
|
|
150
127
|
defineActions() {
|
|
151
|
-
(0, import_defineMyInAppMessages.default)(
|
|
152
|
-
|
|
153
|
-
addClient: this.addClient,
|
|
154
|
-
removeClient: this.removeClient,
|
|
155
|
-
getClient: this.getClient
|
|
156
|
-
});
|
|
157
|
-
(0, import_defineMyInAppChannels.default)({ app: this.app });
|
|
128
|
+
(0, import_defineMyInAppMessages.default)(this.app);
|
|
129
|
+
(0, import_defineMyInAppChannels.default)(this.app);
|
|
158
130
|
this.app.acl.allow("myInAppMessages", "*", "loggedIn");
|
|
159
131
|
this.app.acl.allow("myInAppChannels", "*", "loggedIn");
|
|
160
132
|
this.app.acl.allow("notificationInAppMessages", "*", "loggedIn");
|
|
@@ -7,6 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Application } from '@nocobase/server';
|
|
10
|
-
export default function defineMyInAppChannels(
|
|
11
|
-
app: Application;
|
|
12
|
-
}): void;
|
|
10
|
+
export default function defineMyInAppChannels(app: Application): void;
|
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(defineMyInAppChannels_exports);
|
|
|
32
32
|
var import_sequelize = require("sequelize");
|
|
33
33
|
var import_plugin_notification_manager = require("@nocobase/plugin-notification-manager");
|
|
34
34
|
var import_types = require("../types");
|
|
35
|
-
function defineMyInAppChannels(
|
|
35
|
+
function defineMyInAppChannels(app) {
|
|
36
36
|
app.resourceManager.define({
|
|
37
37
|
name: "myInAppChannels",
|
|
38
38
|
actions: {
|
|
@@ -97,7 +97,6 @@ function defineMyInAppChannels({ app }) {
|
|
|
97
97
|
const channelsRepo = app.db.getRepository(import_plugin_notification_manager.ChannelsCollectionDefinition.name);
|
|
98
98
|
try {
|
|
99
99
|
const channelsRes = channelsRepo.find({
|
|
100
|
-
logging: console.log,
|
|
101
100
|
limit,
|
|
102
101
|
attributes: {
|
|
103
102
|
include: [
|
|
@@ -7,9 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Application } from '@nocobase/server';
|
|
10
|
-
export default function defineMyInAppMessages(
|
|
11
|
-
app: Application;
|
|
12
|
-
addClient: any;
|
|
13
|
-
removeClient: any;
|
|
14
|
-
getClient?: any;
|
|
15
|
-
}): void;
|
|
10
|
+
export default function defineMyInAppMessages(app: Application): void;
|
|
@@ -42,14 +42,8 @@ module.exports = __toCommonJS(defineMyInAppMessages_exports);
|
|
|
42
42
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
43
43
|
var import_plugin_notification_manager = require("@nocobase/plugin-notification-manager");
|
|
44
44
|
var import_sequelize = require("sequelize");
|
|
45
|
-
var import_stream = require("stream");
|
|
46
45
|
var import_types = require("../types");
|
|
47
|
-
function defineMyInAppMessages({
|
|
48
|
-
app,
|
|
49
|
-
addClient,
|
|
50
|
-
removeClient,
|
|
51
|
-
getClient
|
|
52
|
-
}) {
|
|
46
|
+
function defineMyInAppMessages(app) {
|
|
53
47
|
const countTotalUnreadMessages = async (userId) => {
|
|
54
48
|
const messagesRepo = app.db.getRepository(import_types.InAppMessagesDefinition.name);
|
|
55
49
|
const channelsCollection = app.db.getCollection(import_plugin_notification_manager.ChannelsCollectionDefinition.name);
|
|
@@ -58,7 +52,6 @@ function defineMyInAppMessages({
|
|
|
58
52
|
name: channelsCollection.getRealFieldName(import_plugin_notification_manager.ChannelsCollectionDefinition.fieldNameMap.name, true)
|
|
59
53
|
};
|
|
60
54
|
const count = await messagesRepo.count({
|
|
61
|
-
logging: console.log,
|
|
62
55
|
// @ts-ignore
|
|
63
56
|
where: {
|
|
64
57
|
userId,
|
|
@@ -73,33 +66,32 @@ function defineMyInAppMessages({
|
|
|
73
66
|
app.resourceManager.define({
|
|
74
67
|
name: "myInAppMessages",
|
|
75
68
|
actions: {
|
|
76
|
-
sse: {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
69
|
+
// sse: {
|
|
70
|
+
// handler: async (ctx, next) => {
|
|
71
|
+
// const userId = ctx.state.currentUser.id;
|
|
72
|
+
// const clientId = ctx.action?.params?.id;
|
|
73
|
+
// if (!clientId) return;
|
|
74
|
+
// ctx.request.socket.setTimeout(0);
|
|
75
|
+
// ctx.req.socket.setNoDelay(true);
|
|
76
|
+
// ctx.req.socket.setKeepAlive(true);
|
|
77
|
+
// ctx.set({
|
|
78
|
+
// 'Content-Type': 'text/event-stream',
|
|
79
|
+
// 'Cache-Control': 'no-cache',
|
|
80
|
+
// Connection: 'keep-alive',
|
|
81
|
+
// });
|
|
82
|
+
// const stream = new PassThrough();
|
|
83
|
+
// ctx.status = 200;
|
|
84
|
+
// ctx.body = stream;
|
|
85
|
+
// addClient(userId, clientId, stream);
|
|
86
|
+
// stream.on('close', () => {
|
|
87
|
+
// removeClient(userId, clientId);
|
|
88
|
+
// });
|
|
89
|
+
// stream.on('error', () => {
|
|
90
|
+
// removeClient(userId, clientId);
|
|
91
|
+
// });
|
|
92
|
+
// await next();
|
|
93
|
+
// },
|
|
94
|
+
// },
|
|
103
95
|
count: {
|
|
104
96
|
handler: async (ctx) => {
|
|
105
97
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-notification-in-app-message",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.6",
|
|
4
4
|
"displayName": "Notification: In-app message",
|
|
5
5
|
"displayName.zh-CN": "通知:站内信",
|
|
6
6
|
"description": "It supports users in receiving real-time message notifications within the NocoBase application.",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@nocobase/test": "1.x",
|
|
27
27
|
"react-router-dom": "^6.x"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "ada5e359a91135cb9baf605c04c5c380f067a046"
|
|
30
30
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { SSEData } from '../../types';
|
|
10
|
-
export declare const liveSSEObs: {
|
|
11
|
-
value: SSEData | null;
|
|
12
|
-
};
|
|
13
|
-
export declare const startMsgSSEStreamWithRetry: () => () => void;
|