@nocobase/plugin-notification-in-app-message 1.9.0-alpha.1 → 1.9.0-alpha.11
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/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 -1
- package/dist/server/defineMyInAppMessages.d.ts +1 -6
- package/dist/server/defineMyInAppMessages.js +27 -34
- package/dist/types/index.d.ts +2 -2
- 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-alpha.
|
|
13
|
-
"@nocobase/plugin-notification-manager": "1.9.0-alpha.
|
|
14
|
-
"@nocobase/plugin-mobile": "1.9.0-alpha.
|
|
15
|
-
"@nocobase/utils": "1.9.0-alpha.
|
|
12
|
+
"@nocobase/client": "1.9.0-alpha.11",
|
|
13
|
+
"@nocobase/plugin-notification-manager": "1.9.0-alpha.11",
|
|
14
|
+
"@nocobase/plugin-mobile": "1.9.0-alpha.11",
|
|
15
|
+
"@nocobase/utils": "1.9.0-alpha.11",
|
|
16
16
|
"react-i18next": "11.18.6",
|
|
17
|
-
"@nocobase/server": "1.9.0-alpha.
|
|
17
|
+
"@nocobase/server": "1.9.0-alpha.11",
|
|
18
18
|
"sequelize": "6.35.2",
|
|
19
|
-
"@nocobase/actions": "1.9.0-alpha.
|
|
20
|
-
"@nocobase/database": "1.9.0-alpha.
|
|
19
|
+
"@nocobase/actions": "1.9.0-alpha.11",
|
|
20
|
+
"@nocobase/database": "1.9.0-alpha.11",
|
|
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-alpha.
|
|
29
|
+
"@nocobase/plugin-workflow": "1.9.0-alpha.11",
|
|
30
|
+
"@formily/reactive": "2.3.0",
|
|
31
31
|
"@formily/shared": "2.3.2"
|
|
32
32
|
};
|
|
@@ -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: {
|
|
@@ -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);
|
|
@@ -73,33 +67,32 @@ function defineMyInAppMessages({
|
|
|
73
67
|
app.resourceManager.define({
|
|
74
68
|
name: "myInAppMessages",
|
|
75
69
|
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
|
-
},
|
|
70
|
+
// sse: {
|
|
71
|
+
// handler: async (ctx, next) => {
|
|
72
|
+
// const userId = ctx.state.currentUser.id;
|
|
73
|
+
// const clientId = ctx.action?.params?.id;
|
|
74
|
+
// if (!clientId) return;
|
|
75
|
+
// ctx.request.socket.setTimeout(0);
|
|
76
|
+
// ctx.req.socket.setNoDelay(true);
|
|
77
|
+
// ctx.req.socket.setKeepAlive(true);
|
|
78
|
+
// ctx.set({
|
|
79
|
+
// 'Content-Type': 'text/event-stream',
|
|
80
|
+
// 'Cache-Control': 'no-cache',
|
|
81
|
+
// Connection: 'keep-alive',
|
|
82
|
+
// });
|
|
83
|
+
// const stream = new PassThrough();
|
|
84
|
+
// ctx.status = 200;
|
|
85
|
+
// ctx.body = stream;
|
|
86
|
+
// addClient(userId, clientId, stream);
|
|
87
|
+
// stream.on('close', () => {
|
|
88
|
+
// removeClient(userId, clientId);
|
|
89
|
+
// });
|
|
90
|
+
// stream.on('error', () => {
|
|
91
|
+
// removeClient(userId, clientId);
|
|
92
|
+
// });
|
|
93
|
+
// await next();
|
|
94
|
+
// },
|
|
95
|
+
// },
|
|
103
96
|
count: {
|
|
104
97
|
handler: async (ctx) => {
|
|
105
98
|
try {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface Channel {
|
|
|
12
12
|
userId: string;
|
|
13
13
|
unreadMsgCnt: number;
|
|
14
14
|
totalMsgCnt: number;
|
|
15
|
-
latestMsgReceiveTimestamp: number;
|
|
15
|
+
latestMsgReceiveTimestamp: number | string;
|
|
16
16
|
latestMsgTitle: string;
|
|
17
17
|
}
|
|
18
18
|
export interface Message {
|
|
@@ -21,7 +21,7 @@ export interface Message {
|
|
|
21
21
|
userId: string;
|
|
22
22
|
channelName: string;
|
|
23
23
|
content: string;
|
|
24
|
-
receiveTimestamp: number;
|
|
24
|
+
receiveTimestamp: number | string;
|
|
25
25
|
status: 'read' | 'unread';
|
|
26
26
|
url: string;
|
|
27
27
|
options: Record<string, any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-notification-in-app-message",
|
|
3
|
-
"version": "1.9.0-alpha.
|
|
3
|
+
"version": "1.9.0-alpha.11",
|
|
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": "2dbef60d43720e92b483fc07d8ef1fd013083c88"
|
|
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;
|