@nocobase/plugin-notification-in-app-message 1.9.0-alpha.3 → 1.9.0-alpha.5
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 +1 -17
- package/dist/server/InAppNotificationChannel.js +17 -57
- 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/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.5",
|
|
13
|
+
"@nocobase/plugin-notification-manager": "1.9.0-alpha.5",
|
|
14
|
+
"@nocobase/plugin-mobile": "1.9.0-alpha.5",
|
|
15
|
+
"@nocobase/utils": "1.9.0-alpha.5",
|
|
16
16
|
"react-i18next": "11.18.6",
|
|
17
|
-
"@nocobase/server": "1.9.0-alpha.
|
|
17
|
+
"@nocobase/server": "1.9.0-alpha.5",
|
|
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.5",
|
|
20
|
+
"@nocobase/database": "1.9.0-alpha.5",
|
|
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.5",
|
|
30
|
+
"@formily/reactive": "2.3.0",
|
|
31
31
|
"@formily/shared": "2.3.2"
|
|
32
32
|
};
|
|
@@ -6,26 +6,11 @@
|
|
|
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
|
-
onMessageCreatedOrUpdated: () => Promise<void>;
|
|
22
|
-
addClient: (userId: UserID, clientId: ClientID, stream: PassThrough) => void;
|
|
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
|
+
onMessageCreatedOrUpdated: (model: any, options: any) => Promise<void>;
|
|
29
14
|
saveMessageToDB: ({ content, status, userId, title, channelName, receiveTimestamp, options, }: {
|
|
30
15
|
content: string;
|
|
31
16
|
userId: number;
|
|
@@ -38,4 +23,3 @@ export default class InAppNotificationChannel extends BaseNotificationChannel {
|
|
|
38
23
|
send: SendFnType<InAppMessageFormValues>;
|
|
39
24
|
defineActions(): void;
|
|
40
25
|
}
|
|
41
|
-
export {};
|
|
@@ -45,61 +45,26 @@ 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.onMessageCreatedOrUpdated
|
|
54
|
+
this.app.db.on(`${import_types2.InAppMessagesDefinition.name}.afterSave`, this.onMessageCreatedOrUpdated);
|
|
56
55
|
this.defineActions();
|
|
57
56
|
}
|
|
58
|
-
onMessageCreatedOrUpdated = async () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
onMessageCreatedOrUpdated = async (model, options) => {
|
|
58
|
+
const userId = model.userId;
|
|
59
|
+
this.app.emit("ws:sendToTag", {
|
|
60
|
+
tagKey: "userId",
|
|
61
|
+
tagValue: userId,
|
|
62
|
+
message: {
|
|
63
|
+
type: "in-app-message:updated",
|
|
64
|
+
payload: model.toJSON()
|
|
65
|
+
}
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
|
-
addClient = (userId, clientId, stream) => {
|
|
69
|
-
if (!this.userClientsMap[userId]) {
|
|
70
|
-
this.userClientsMap[userId] = {};
|
|
71
|
-
}
|
|
72
|
-
this.userClientsMap[userId][clientId] = stream;
|
|
73
|
-
};
|
|
74
|
-
getClient = (userId, clientId) => {
|
|
75
|
-
var _a;
|
|
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
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
68
|
saveMessageToDB = async ({
|
|
104
69
|
content,
|
|
105
70
|
status,
|
|
@@ -148,13 +113,8 @@ class InAppNotificationChannel extends import_plugin_notification_manager.BaseNo
|
|
|
148
113
|
return { status: "success", message };
|
|
149
114
|
};
|
|
150
115
|
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 });
|
|
116
|
+
(0, import_defineMyInAppMessages.default)(this.app);
|
|
117
|
+
(0, import_defineMyInAppChannels.default)(this.app);
|
|
158
118
|
this.app.acl.allow("myInAppMessages", "*", "loggedIn");
|
|
159
119
|
this.app.acl.allow("myInAppChannels", "*", "loggedIn");
|
|
160
120
|
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/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.5",
|
|
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": "761cdf1005e23f6dfdff314b285227400351c6ff"
|
|
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;
|