mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 15:39:24 +08:00
fix(plugin-notification-manager): fix template compiling (#5630)
This commit is contained in:
parent
ea63b549ff
commit
e42c480d85
@ -129,8 +129,8 @@ const MessageList = observer(() => {
|
|||||||
<Descriptions key={index} column={1}>
|
<Descriptions key={index} column={1}>
|
||||||
<Descriptions.Item label={t('Content')}>
|
<Descriptions.Item label={t('Content')}>
|
||||||
{' '}
|
{' '}
|
||||||
<Tooltip title={message.content.length > 100 ? message.content : ''} mouseEnterDelay={0.5}>
|
<Tooltip title={message.content?.length > 100 ? message.content : ''} mouseEnterDelay={0.5}>
|
||||||
{message.content.slice(0, 100) + (message.content.length > 100 ? '...' : '')}{' '}
|
{message.content?.slice(0, 100) + (message.content?.length > 100 ? '...' : '')}{' '}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label={t('Datetime')}>{dayjs(message.receiveTimestamp).fromNow()}</Descriptions.Item>
|
<Descriptions.Item label={t('Datetime')}>{dayjs(message.receiveTimestamp).fromNow()}</Descriptions.Item>
|
||||||
|
@ -65,8 +65,8 @@ export default class InAppNotificationChannel extends BaseNotificationChannel {
|
|||||||
type: message.type,
|
type: message.type,
|
||||||
data: {
|
data: {
|
||||||
...message.data,
|
...message.data,
|
||||||
title: message.data.title.slice(0, 30),
|
title: message.data.title?.slice(0, 30) || '',
|
||||||
content: message.data.content.slice(0, 105),
|
content: message.data.content?.slice(0, 105) || '',
|
||||||
},
|
},
|
||||||
})}\n\n`,
|
})}\n\n`,
|
||||||
);
|
);
|
||||||
|
@ -39,7 +39,8 @@ export class NotificationManager implements NotificationManager {
|
|||||||
async send(params: SendOptions) {
|
async send(params: SendOptions) {
|
||||||
this.plugin.logger.info('receive sending message request', params);
|
this.plugin.logger.info('receive sending message request', params);
|
||||||
const channelsRepo = this.plugin.app.db.getRepository(COLLECTION_NAME.channels);
|
const channelsRepo = this.plugin.app.db.getRepository(COLLECTION_NAME.channels);
|
||||||
const messageData = { ...(params.receivers ? { receivers: params.receivers } : {}), ...params.message };
|
const message = compile(params.message ?? {}, params.data ?? {});
|
||||||
|
const messageData = { ...(params.receivers ? { receivers: params.receivers } : {}), ...message };
|
||||||
const logData: any = {
|
const logData: any = {
|
||||||
triggerFrom: params.triggerFrom,
|
triggerFrom: params.triggerFrom,
|
||||||
channelName: params.channelName,
|
channelName: params.channelName,
|
||||||
@ -53,7 +54,7 @@ export class NotificationManager implements NotificationManager {
|
|||||||
logData.channelTitle = channel.title;
|
logData.channelTitle = channel.title;
|
||||||
logData.notificationType = channel.notificationType;
|
logData.notificationType = channel.notificationType;
|
||||||
logData.receivers = params.receivers;
|
logData.receivers = params.receivers;
|
||||||
const result = await instance.send({ message: params.message, channel, receivers: params.receivers });
|
const result = await instance.send({ message, channel, receivers: params.receivers });
|
||||||
logData.status = result.status;
|
logData.status = result.status;
|
||||||
logData.reason = result.reason;
|
logData.reason = result.reason;
|
||||||
} else {
|
} else {
|
||||||
@ -72,11 +73,16 @@ export class NotificationManager implements NotificationManager {
|
|||||||
}
|
}
|
||||||
async sendToUsers(options: SendUserOptions) {
|
async sendToUsers(options: SendUserOptions) {
|
||||||
this.plugin.logger.info(`notificationManager.sendToUsers options: ${JSON.stringify(options)}`);
|
this.plugin.logger.info(`notificationManager.sendToUsers options: ${JSON.stringify(options)}`);
|
||||||
const { userIds, channels, message: template = {}, data = {} } = options;
|
const { userIds, channels, message, data = {} } = options;
|
||||||
const message = compile(template, data);
|
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
channels.map((channelName) =>
|
channels.map((channelName) =>
|
||||||
this.send({ channelName, message, triggerFrom: 'sendToUsers', receivers: { value: userIds, type: 'userId' } }),
|
this.send({
|
||||||
|
channelName,
|
||||||
|
message,
|
||||||
|
data,
|
||||||
|
triggerFrom: 'sendToUsers',
|
||||||
|
receivers: { value: userIds, type: 'userId' },
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ export interface SendOptions {
|
|||||||
message: Record<string, any>;
|
message: Record<string, any>;
|
||||||
triggerFrom: string;
|
triggerFrom: string;
|
||||||
receivers?: ReceiversOptions;
|
receivers?: ReceiversOptions;
|
||||||
|
data?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendUserOptions {
|
export interface SendUserOptions {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user