@nocobase/plugin-notification-in-app-message 2.1.0-beta.8 → 2.2.0-alpha.1
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/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/dist/client/index.js +1 -1
- package/dist/client/observables/channel.d.ts +0 -1
- package/dist/client-v2/297.503d86e234fdb749.js +10 -0
- package/dist/client-v2/apiClient.d.ts +12 -0
- package/dist/client-v2/components/FilterTab.d.ts +11 -0
- package/dist/client-v2/components/InboxContent.d.ts +11 -0
- package/dist/client-v2/components/MessageList.d.ts +11 -0
- package/dist/{client/components/UsersAddition.d.ts → client-v2/index.d.ts} +2 -2
- package/dist/client-v2/index.js +10 -0
- package/dist/client-v2/locale.d.ts +12 -0
- package/dist/client-v2/models/InboxTopbarActionModel.d.ts +18 -0
- package/dist/client-v2/plugin.d.ts +27 -0
- package/dist/client-v2/state.d.ts +72 -0
- package/dist/externalVersion.js +13 -11
- package/dist/node_modules/uuid/dist/bin/uuid +2 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/index.js +104 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/max.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/md5.js +200 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/native.js +10 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/nil.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/parse.js +44 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/regex.js +7 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/rng.js +23 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/sha1.js +82 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/stringify.js +38 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v1.js +131 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v1ToV6.js +26 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v3.js +11 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v35.js +63 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v4.js +32 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v5.js +11 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v6.js +42 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v6ToV1.js +26 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/v7.js +152 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/validate.js +12 -0
- package/dist/node_modules/uuid/dist/commonjs-browser/version.js +15 -0
- package/dist/node_modules/uuid/dist/esm-browser/index.js +14 -0
- package/dist/node_modules/uuid/dist/esm-browser/max.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/md5.js +194 -0
- package/dist/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/nil.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/parse.js +37 -0
- package/dist/node_modules/uuid/dist/esm-browser/regex.js +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +17 -0
- package/dist/node_modules/uuid/dist/esm-browser/sha1.js +76 -0
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/dist/node_modules/uuid/dist/esm-browser/v1.js +125 -0
- package/dist/node_modules/uuid/dist/esm-browser/v1ToV6.js +20 -0
- package/dist/node_modules/uuid/dist/esm-browser/v3.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/v35.js +55 -0
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +25 -0
- package/dist/node_modules/uuid/dist/esm-browser/v5.js +4 -0
- package/dist/node_modules/uuid/dist/esm-browser/v6.js +36 -0
- package/dist/node_modules/uuid/dist/esm-browser/v6ToV1.js +20 -0
- package/dist/node_modules/uuid/dist/esm-browser/v7.js +146 -0
- package/dist/node_modules/uuid/dist/esm-browser/validate.js +5 -0
- package/dist/node_modules/uuid/dist/esm-browser/version.js +8 -0
- package/dist/node_modules/uuid/dist/esm-node/index.js +14 -0
- package/dist/node_modules/uuid/dist/esm-node/max.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/md5.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/native.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/nil.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/parse.js +37 -0
- package/dist/node_modules/uuid/dist/esm-node/regex.js +1 -0
- package/dist/node_modules/uuid/dist/esm-node/rng.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/sha1.js +10 -0
- package/dist/node_modules/uuid/dist/esm-node/stringify.js +31 -0
- package/dist/node_modules/uuid/dist/esm-node/v1.js +125 -0
- package/dist/node_modules/uuid/dist/esm-node/v1ToV6.js +20 -0
- package/dist/node_modules/uuid/dist/esm-node/v3.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/v35.js +55 -0
- package/dist/node_modules/uuid/dist/esm-node/v4.js +25 -0
- package/dist/node_modules/uuid/dist/esm-node/v5.js +4 -0
- package/dist/node_modules/uuid/dist/esm-node/v6.js +32 -0
- package/dist/node_modules/uuid/dist/esm-node/v6ToV1.js +20 -0
- package/dist/node_modules/uuid/dist/esm-node/v7.js +146 -0
- package/dist/node_modules/uuid/dist/esm-node/validate.js +5 -0
- package/dist/node_modules/uuid/dist/esm-node/version.js +8 -0
- package/dist/node_modules/uuid/dist/index.js +1 -0
- package/dist/node_modules/uuid/dist/max.js +7 -0
- package/dist/node_modules/uuid/dist/md5-browser.js +200 -0
- package/dist/node_modules/uuid/dist/md5.js +17 -0
- package/dist/node_modules/uuid/dist/native-browser.js +10 -0
- package/dist/node_modules/uuid/dist/native.js +11 -0
- package/dist/node_modules/uuid/dist/nil.js +7 -0
- package/dist/node_modules/uuid/dist/parse.js +44 -0
- package/dist/node_modules/uuid/dist/regex.js +7 -0
- package/dist/node_modules/uuid/dist/rng-browser.js +23 -0
- package/dist/node_modules/uuid/dist/rng.js +17 -0
- package/dist/node_modules/uuid/dist/sha1-browser.js +82 -0
- package/dist/node_modules/uuid/dist/sha1.js +17 -0
- package/dist/node_modules/uuid/dist/stringify.js +38 -0
- package/dist/node_modules/uuid/dist/uuid-bin.js +75 -0
- package/dist/node_modules/uuid/dist/v1.js +131 -0
- package/dist/node_modules/uuid/dist/v1ToV6.js +26 -0
- package/dist/node_modules/uuid/dist/v3.js +11 -0
- package/dist/node_modules/uuid/dist/v35.js +63 -0
- package/dist/node_modules/uuid/dist/v4.js +32 -0
- package/dist/node_modules/uuid/dist/v5.js +11 -0
- package/dist/node_modules/uuid/dist/v6.js +38 -0
- package/dist/node_modules/uuid/dist/v6ToV1.js +26 -0
- package/dist/node_modules/uuid/dist/v7.js +152 -0
- package/dist/node_modules/uuid/dist/validate.js +12 -0
- package/dist/node_modules/uuid/dist/version.js +15 -0
- package/dist/node_modules/uuid/package.json +1 -0
- package/dist/server/InAppNotificationChannel.d.ts +7 -0
- package/dist/server/InAppNotificationChannel.js +128 -36
- package/dist/server/defineMyInAppChannels.js +52 -21
- package/dist/server/defineMyInAppMessages.js +2 -1
- package/dist/server/parseUserSelectionConf.d.ts +2 -1
- package/dist/server/parseUserSelectionConf.js +3 -2
- package/dist/server/plugin.js +1 -1
- package/dist/types/messages.js +1 -0
- package/package.json +5 -2
- package/dist/client/components/UsersSelect.d.ts +0 -18
|
@@ -40,11 +40,103 @@ __export(InAppNotificationChannel_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(InAppNotificationChannel_exports);
|
|
42
42
|
var import_plugin_notification_manager = require("@nocobase/plugin-notification-manager");
|
|
43
|
+
var import_uuid = require("uuid");
|
|
43
44
|
var import_types2 = require("../types");
|
|
44
45
|
var import_parseUserSelectionConf = require("./parseUserSelectionConf");
|
|
45
46
|
var import_defineMyInAppMessages = __toESM(require("./defineMyInAppMessages"));
|
|
46
47
|
var import_defineMyInAppChannels = __toESM(require("./defineMyInAppChannels"));
|
|
47
48
|
class InAppNotificationChannel extends import_plugin_notification_manager.BaseNotificationChannel {
|
|
49
|
+
static SLOW_SEND_THRESHOLD_MS = 200;
|
|
50
|
+
static MESSAGE_BATCH_SIZE = 100;
|
|
51
|
+
getMessagePayload(message) {
|
|
52
|
+
return typeof (message == null ? void 0 : message.toJSON) === "function" ? message.toJSON() : message;
|
|
53
|
+
}
|
|
54
|
+
emitMessageEventsAsync(type, messages) {
|
|
55
|
+
setImmediate(() => {
|
|
56
|
+
try {
|
|
57
|
+
const startedAt = Date.now();
|
|
58
|
+
this.emitMessageEvents(type, messages);
|
|
59
|
+
const elapsed = Date.now() - startedAt;
|
|
60
|
+
if (elapsed >= InAppNotificationChannel.SLOW_SEND_THRESHOLD_MS) {
|
|
61
|
+
this.app.logger.warn("in-app notification websocket dispatch is slow", {
|
|
62
|
+
type,
|
|
63
|
+
count: messages.length,
|
|
64
|
+
elapsed
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
this.app.logger.error(`failed to emit in-app message events: ${error.message}`, {
|
|
69
|
+
error,
|
|
70
|
+
type,
|
|
71
|
+
count: messages.length
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
scheduleMessageEvents(type, messages, transaction) {
|
|
77
|
+
if (!messages.length) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (transaction == null ? void 0 : transaction.afterCommit) {
|
|
81
|
+
transaction.afterCommit(() => {
|
|
82
|
+
this.emitMessageEventsAsync(type, messages);
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.emitMessageEventsAsync(type, messages);
|
|
87
|
+
}
|
|
88
|
+
emitMessageEvents(type, messages) {
|
|
89
|
+
for (const message of messages) {
|
|
90
|
+
this.app.emit("ws:sendToUser", {
|
|
91
|
+
userId: message.userId,
|
|
92
|
+
message: {
|
|
93
|
+
type: `in-app-message:${type}`,
|
|
94
|
+
payload: message
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async persistMessagesInBatches(options) {
|
|
100
|
+
const { userIds, title, content, channelName, receiveTimestamp, messageOptions, transaction } = options;
|
|
101
|
+
const MessageModel = this.app.db.getModel(import_types2.InAppMessagesDefinition.name);
|
|
102
|
+
const persist = async (activeTransaction) => {
|
|
103
|
+
let persistedCount = 0;
|
|
104
|
+
for (let index = 0; index < userIds.length; index += InAppNotificationChannel.MESSAGE_BATCH_SIZE) {
|
|
105
|
+
const batchUserIds = userIds.slice(index, index + InAppNotificationChannel.MESSAGE_BATCH_SIZE);
|
|
106
|
+
const messageBatch = batchUserIds.map((userId) => ({
|
|
107
|
+
id: (0, import_uuid.v4)(),
|
|
108
|
+
title,
|
|
109
|
+
content,
|
|
110
|
+
status: "unread",
|
|
111
|
+
userId,
|
|
112
|
+
channelName,
|
|
113
|
+
receiveTimestamp,
|
|
114
|
+
options: messageOptions
|
|
115
|
+
}));
|
|
116
|
+
await MessageModel.bulkCreate(messageBatch, {
|
|
117
|
+
hooks: false,
|
|
118
|
+
transaction: activeTransaction,
|
|
119
|
+
validate: false,
|
|
120
|
+
returning: false
|
|
121
|
+
});
|
|
122
|
+
persistedCount += messageBatch.length;
|
|
123
|
+
this.scheduleMessageEvents("created", messageBatch, activeTransaction);
|
|
124
|
+
}
|
|
125
|
+
return persistedCount;
|
|
126
|
+
};
|
|
127
|
+
if (transaction) {
|
|
128
|
+
return persist(transaction);
|
|
129
|
+
}
|
|
130
|
+
const internalTransaction = await this.app.db.sequelize.transaction();
|
|
131
|
+
try {
|
|
132
|
+
const persistedCount = await persist(internalTransaction);
|
|
133
|
+
await internalTransaction.commit();
|
|
134
|
+
return persistedCount;
|
|
135
|
+
} catch (error) {
|
|
136
|
+
await internalTransaction.rollback();
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
48
140
|
async load() {
|
|
49
141
|
this.app.db.on(`${import_types2.InAppMessagesDefinition.name}.afterCreate`, this.onMessageCreated);
|
|
50
142
|
this.app.db.on(`${import_types2.InAppMessagesDefinition.name}.afterBulkCreate`, this.onMessageCreated);
|
|
@@ -53,53 +145,53 @@ class InAppNotificationChannel extends import_plugin_notification_manager.BaseNo
|
|
|
53
145
|
this.defineActions();
|
|
54
146
|
}
|
|
55
147
|
onMessageCreated = async (model, options) => {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const userId = m.userId;
|
|
59
|
-
this.app.emit("ws:sendToUser", {
|
|
60
|
-
userId,
|
|
61
|
-
message: {
|
|
62
|
-
type: "in-app-message:created",
|
|
63
|
-
payload: m.toJSON()
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
148
|
+
const messages = (Array.isArray(model) ? model : [model]).map((item) => this.getMessagePayload(item));
|
|
149
|
+
this.scheduleMessageEvents("created", messages, options == null ? void 0 : options.transaction);
|
|
67
150
|
};
|
|
68
151
|
onMessageUpdated = async (model, options) => {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const userId = m.userId;
|
|
72
|
-
this.app.emit("ws:sendToUser", {
|
|
73
|
-
userId,
|
|
74
|
-
message: {
|
|
75
|
-
type: "in-app-message:updated",
|
|
76
|
-
payload: m.toJSON()
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
152
|
+
const messages = (Array.isArray(model) ? model : [model]).map((item) => this.getMessagePayload(item));
|
|
153
|
+
this.scheduleMessageEvents("updated", messages, options == null ? void 0 : options.transaction);
|
|
80
154
|
};
|
|
81
155
|
send = async (params) => {
|
|
82
|
-
const
|
|
156
|
+
const startedAt = Date.now();
|
|
157
|
+
const { channel, message, receivers, transaction } = params;
|
|
83
158
|
let userIds;
|
|
84
159
|
const { content, title, options = {} } = message;
|
|
85
160
|
const userRepo = this.app.db.getRepository("users");
|
|
161
|
+
const resolveReceiversStartedAt = Date.now();
|
|
86
162
|
if ((receivers == null ? void 0 : receivers.type) === "userId") {
|
|
87
163
|
userIds = receivers.value;
|
|
88
164
|
} else {
|
|
89
|
-
userIds = (await (0, import_parseUserSelectionConf.parseUserSelectionConf)(message.receivers, userRepo)).map((i) => parseInt(i));
|
|
165
|
+
userIds = (await (0, import_parseUserSelectionConf.parseUserSelectionConf)(message.receivers, userRepo, { transaction })).map((i) => parseInt(i));
|
|
90
166
|
}
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
167
|
+
const resolveReceiversMs = Date.now() - resolveReceiversStartedAt;
|
|
168
|
+
const uniqueUserIds = [...new Set(userIds)];
|
|
169
|
+
if (!uniqueUserIds.length) {
|
|
170
|
+
return { status: "success", message };
|
|
171
|
+
}
|
|
172
|
+
const receiveTimestamp = Date.now();
|
|
173
|
+
const persistStartedAt = Date.now();
|
|
174
|
+
const persistedCount = await this.persistMessagesInBatches({
|
|
175
|
+
userIds: uniqueUserIds,
|
|
176
|
+
title,
|
|
177
|
+
content,
|
|
178
|
+
channelName: channel.name,
|
|
179
|
+
receiveTimestamp,
|
|
180
|
+
messageOptions: options,
|
|
181
|
+
transaction
|
|
182
|
+
});
|
|
183
|
+
const persistMs = Date.now() - persistStartedAt;
|
|
184
|
+
const totalMs = Date.now() - startedAt;
|
|
185
|
+
if (totalMs >= InAppNotificationChannel.SLOW_SEND_THRESHOLD_MS) {
|
|
186
|
+
this.app.logger.warn("in-app notification send is slow", {
|
|
98
187
|
channelName: channel.name,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
188
|
+
userCount: persistedCount,
|
|
189
|
+
batchSize: InAppNotificationChannel.MESSAGE_BATCH_SIZE,
|
|
190
|
+
resolveReceiversMs,
|
|
191
|
+
persistMs,
|
|
192
|
+
totalMs
|
|
193
|
+
});
|
|
194
|
+
}
|
|
103
195
|
return { status: "success", message };
|
|
104
196
|
};
|
|
105
197
|
defineActions() {
|
|
@@ -107,6 +199,6 @@ class InAppNotificationChannel extends import_plugin_notification_manager.BaseNo
|
|
|
107
199
|
(0, import_defineMyInAppChannels.default)(this.app);
|
|
108
200
|
this.app.acl.allow("myInAppMessages", "*", "loggedIn");
|
|
109
201
|
this.app.acl.allow("myInAppChannels", "*", "loggedIn");
|
|
110
|
-
this.app.acl.allow("notificationInAppMessages", "
|
|
202
|
+
this.app.acl.allow("notificationInAppMessages", "updateMyOwn", "loggedIn");
|
|
111
203
|
}
|
|
112
204
|
}
|
|
@@ -32,14 +32,38 @@ 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 parseLatestMsgReceiveTimestampLt(filter) {
|
|
36
|
+
const latestMsgReceiveTimestamp = typeof filter === "object" && filter !== null ? filter.latestMsgReceiveTimestamp : null;
|
|
37
|
+
if (typeof latestMsgReceiveTimestamp !== "object" || latestMsgReceiveTimestamp === null || !Object.prototype.hasOwnProperty.call(latestMsgReceiveTimestamp, "$lt")) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const value = latestMsgReceiveTimestamp.$lt;
|
|
41
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
42
|
+
throw new Error("Invalid latest message receive timestamp filter");
|
|
43
|
+
}
|
|
44
|
+
if (typeof value !== "number" && typeof value !== "string") {
|
|
45
|
+
throw new Error("Invalid latest message receive timestamp filter");
|
|
46
|
+
}
|
|
47
|
+
const timestamp = Number(value);
|
|
48
|
+
if (!Number.isFinite(timestamp)) {
|
|
49
|
+
throw new Error("Invalid latest message receive timestamp filter");
|
|
50
|
+
}
|
|
51
|
+
return timestamp;
|
|
52
|
+
}
|
|
35
53
|
function defineMyInAppChannels(app) {
|
|
36
54
|
app.resourceManager.define({
|
|
37
55
|
name: "myInAppChannels",
|
|
38
56
|
actions: {
|
|
39
57
|
list: {
|
|
40
58
|
handler: async (ctx) => {
|
|
41
|
-
var _a
|
|
59
|
+
var _a;
|
|
42
60
|
const { filter = {}, limit = 30 } = ((_a = ctx.action) == null ? void 0 : _a.params) ?? {};
|
|
61
|
+
let latestMsgReceiveTimestampLt;
|
|
62
|
+
try {
|
|
63
|
+
latestMsgReceiveTimestampLt = parseLatestMsgReceiveTimestampLt(filter);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return ctx.throw(400, error.message);
|
|
66
|
+
}
|
|
43
67
|
const messagesCollection = app.db.getCollection(import_types.InAppMessagesDefinition.name);
|
|
44
68
|
const messagesTableName = messagesCollection.getRealTableName(true);
|
|
45
69
|
const channelsCollection = app.db.getCollection(import_plugin_notification_manager.ChannelsCollectionDefinition.name);
|
|
@@ -77,8 +101,9 @@ function defineMyInAppChannels(app) {
|
|
|
77
101
|
ORDER BY messages.${messagesFieldName.receiveTimestamp} DESC
|
|
78
102
|
LIMIT 1
|
|
79
103
|
)`;
|
|
80
|
-
const latestMsgReceiveTSFilter =
|
|
104
|
+
const latestMsgReceiveTSFilter = latestMsgReceiveTimestampLt !== null ? import_sequelize.Sequelize.where(import_sequelize.Sequelize.literal(latestMsgReceiveTimestampSQL), import_sequelize.Op.lt, latestMsgReceiveTimestampLt) : null;
|
|
81
105
|
const channelIdFilter = (filter == null ? void 0 : filter.id) ? { id: filter.id } : null;
|
|
106
|
+
const channelNameFilter = (filter == null ? void 0 : filter.name) ? { name: filter.name } : null;
|
|
82
107
|
const statusMap = {
|
|
83
108
|
all: "read|unread",
|
|
84
109
|
unread: "unread",
|
|
@@ -98,21 +123,22 @@ function defineMyInAppChannels(app) {
|
|
|
98
123
|
try {
|
|
99
124
|
const channelsRes = channelsRepo.find({
|
|
100
125
|
limit,
|
|
101
|
-
attributes:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
attributes: [
|
|
127
|
+
"name",
|
|
128
|
+
"title",
|
|
129
|
+
[
|
|
130
|
+
import_sequelize.Sequelize.literal(`(
|
|
105
131
|
SELECT COUNT(*)
|
|
106
132
|
FROM ${messagesTableName} AS messages
|
|
107
133
|
WHERE
|
|
108
134
|
messages.${messagesFieldName.channelName} = ${channelsTableAliasName}.${channelsFieldName.name}
|
|
109
135
|
AND messages.${messagesFieldName.userId} = ${userId}
|
|
110
136
|
)`),
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
137
|
+
"totalMsgCnt"
|
|
138
|
+
],
|
|
139
|
+
[import_sequelize.Sequelize.literal(`'${userId}'`), "userId"],
|
|
140
|
+
[
|
|
141
|
+
import_sequelize.Sequelize.literal(`(
|
|
116
142
|
SELECT COUNT(*)
|
|
117
143
|
FROM ${messagesTableName} AS messages
|
|
118
144
|
WHERE
|
|
@@ -120,11 +146,11 @@ function defineMyInAppChannels(app) {
|
|
|
120
146
|
AND messages.${messagesFieldName.status} = 'unread'
|
|
121
147
|
AND messages.${messagesFieldName.userId} = ${userId}
|
|
122
148
|
)`),
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
149
|
+
"unreadMsgCnt"
|
|
150
|
+
],
|
|
151
|
+
[import_sequelize.Sequelize.literal(latestMsgReceiveTimestampSQL), "latestMsgReceiveTimestamp"],
|
|
152
|
+
[
|
|
153
|
+
import_sequelize.Sequelize.literal(`(
|
|
128
154
|
SELECT messages.${messagesFieldName.title}
|
|
129
155
|
FROM ${messagesTableName} AS messages
|
|
130
156
|
WHERE
|
|
@@ -133,20 +159,25 @@ function defineMyInAppChannels(app) {
|
|
|
133
159
|
ORDER BY messages.${messagesFieldName.receiveTimestamp} DESC
|
|
134
160
|
LIMIT 1
|
|
135
161
|
)`),
|
|
136
|
-
|
|
137
|
-
]
|
|
162
|
+
"latestMsgTitle"
|
|
138
163
|
]
|
|
139
|
-
|
|
164
|
+
],
|
|
140
165
|
//@ts-ignore
|
|
141
166
|
where: {
|
|
142
|
-
[import_sequelize.Op.and]: [
|
|
167
|
+
[import_sequelize.Op.and]: [
|
|
168
|
+
userFilter,
|
|
169
|
+
latestMsgReceiveTSFilter,
|
|
170
|
+
channelIdFilter,
|
|
171
|
+
channelNameFilter,
|
|
172
|
+
channelStatusFilter
|
|
173
|
+
].filter(Boolean)
|
|
143
174
|
},
|
|
144
175
|
sort: ["-latestMsgReceiveTimestamp"]
|
|
145
176
|
});
|
|
146
177
|
const countRes = channelsRepo.count({
|
|
147
178
|
//@ts-ignore
|
|
148
179
|
where: {
|
|
149
|
-
[import_sequelize.Op.and]: [userFilter, channelStatusFilter].filter(Boolean)
|
|
180
|
+
[import_sequelize.Op.and]: [userFilter, channelNameFilter, channelStatusFilter].filter(Boolean)
|
|
150
181
|
}
|
|
151
182
|
});
|
|
152
183
|
const [channels, count] = await Promise.all([channelsRes, countRes]);
|
|
@@ -6,5 +6,6 @@
|
|
|
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
|
+
import { Transactionable } from '@nocobase/database';
|
|
9
10
|
import { Repository } from '@nocobase/database';
|
|
10
|
-
export declare function parseUserSelectionConf(userSelectionConfig: Array<Record<any, any> | string>, UserRepo: Repository): Promise<string[]>;
|
|
11
|
+
export declare function parseUserSelectionConf(userSelectionConfig: Array<Record<any, any> | string>, UserRepo: Repository, options?: Transactionable): Promise<string[]>;
|
|
@@ -30,7 +30,7 @@ __export(parseUserSelectionConf_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(parseUserSelectionConf_exports);
|
|
32
32
|
var import_utils = require("@nocobase/utils");
|
|
33
|
-
async function parseUserSelectionConf(userSelectionConfig, UserRepo) {
|
|
33
|
+
async function parseUserSelectionConf(userSelectionConfig, UserRepo, options = {}) {
|
|
34
34
|
const SelectionConfigs = userSelectionConfig.flat().filter(Boolean);
|
|
35
35
|
const users = /* @__PURE__ */ new Set();
|
|
36
36
|
for (const item of SelectionConfigs) {
|
|
@@ -40,7 +40,8 @@ async function parseUserSelectionConf(userSelectionConfig, UserRepo) {
|
|
|
40
40
|
}
|
|
41
41
|
const result = await UserRepo.find({
|
|
42
42
|
...item,
|
|
43
|
-
fields: ["id"]
|
|
43
|
+
fields: ["id"],
|
|
44
|
+
transaction: options.transaction
|
|
44
45
|
});
|
|
45
46
|
result.forEach((item2) => users.add(item2.id));
|
|
46
47
|
} else {
|
package/dist/server/plugin.js
CHANGED
|
@@ -54,7 +54,7 @@ class PluginNotificationInAppServer extends import_server.Plugin {
|
|
|
54
54
|
const notificationServer = this.pm.get(import_plugin_notification_manager.default);
|
|
55
55
|
const instance = new import_InAppNotificationChannel.default(this.app);
|
|
56
56
|
instance.load();
|
|
57
|
-
notificationServer.registerChannelType({ type: import_types.inAppTypeName, Channel: import_InAppNotificationChannel.default });
|
|
57
|
+
notificationServer.registerChannelType({ type: import_types.inAppTypeName, Channel: import_InAppNotificationChannel.default, useQueue: false });
|
|
58
58
|
}
|
|
59
59
|
async install() {
|
|
60
60
|
}
|
package/dist/types/messages.js
CHANGED
|
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(messages_exports);
|
|
|
32
32
|
var import_index = require("./index");
|
|
33
33
|
const messageCollection = {
|
|
34
34
|
name: import_index.InAppMessagesDefinition.name,
|
|
35
|
+
dataCategory: "business",
|
|
35
36
|
title: "in-app messages",
|
|
36
37
|
migrationRules: ["schema-only"],
|
|
37
38
|
fields: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-notification-in-app-message",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0-alpha.1",
|
|
4
4
|
"displayName": "Notification: In-app message",
|
|
5
5
|
"displayName.ru-RU": "Уведомления: Всплывающие сообщения внутри приложения",
|
|
6
6
|
"displayName.zh-CN": "通知:站内信",
|
|
@@ -24,11 +24,14 @@
|
|
|
24
24
|
"@formily/reactive": "2.x",
|
|
25
25
|
"@formily/reactive-react": "^2",
|
|
26
26
|
"@nocobase/client": "2.x",
|
|
27
|
+
"@nocobase/client-v2": "2.x",
|
|
28
|
+
"@nocobase/plugin-mobile": "2.x",
|
|
27
29
|
"@nocobase/plugin-notification-manager": "2.x",
|
|
30
|
+
"@nocobase/plugin-workflow": "2.x",
|
|
28
31
|
"@nocobase/server": "2.x",
|
|
29
32
|
"@nocobase/test": "2.x",
|
|
30
33
|
"react-router-dom": "^6.x"
|
|
31
34
|
},
|
|
32
35
|
"license": "Apache-2.0",
|
|
33
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "303663aba6c6eefa27e6a6435b4c0352074ec40f"
|
|
34
37
|
}
|
|
@@ -1,18 +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
|
-
/**
|
|
10
|
-
* This file is part of the NocoBase (R) project.
|
|
11
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
12
|
-
* Authors: NocoBase Team.
|
|
13
|
-
*
|
|
14
|
-
* This program is offered under a commercial license.
|
|
15
|
-
* For more information, see <https://www.nocobase.com/agreement>
|
|
16
|
-
*/
|
|
17
|
-
import React from 'react';
|
|
18
|
-
export declare function UsersSelect(props: any): React.JSX.Element;
|