feat: Rename to Toju and add translation
Some checks failed
Deploy Web Apps / deploy (push) Successful in 5m52s
Build Android APK / build-android-apk (push) Failing after 23m15s
Queue Release Build / prepare (push) Successful in 1m42s
Queue Release Build / build-linux (push) Failing after 9m33s
Queue Release Build / build-windows (push) Successful in 26m5s
Queue Release Build / finalize (push) Has been skipped
Some checks failed
Deploy Web Apps / deploy (push) Successful in 5m52s
Build Android APK / build-android-apk (push) Failing after 23m15s
Queue Release Build / prepare (push) Successful in 1m42s
Queue Release Build / build-linux (push) Failing after 9m33s
Queue Release Build / build-windows (push) Successful in 26m5s
Queue Release Build / finalize (push) Has been skipped
This commit is contained in:
@@ -10,6 +10,8 @@ export const DEFAULT_TEXT_CHANNEL_ID = 'general';
|
||||
|
||||
const MESSAGE_PREVIEW_LIMIT = 140;
|
||||
|
||||
export type AppTranslateFn = (key: string, params?: Record<string, string | number>) => string;
|
||||
|
||||
export function resolveMessageChannelId(message: Pick<Message, 'channelId'>): string {
|
||||
return message.channelId || DEFAULT_TEXT_CHANNEL_ID;
|
||||
}
|
||||
@@ -98,17 +100,18 @@ export function buildNotificationDisplayPayload(
|
||||
message: Pick<Message, 'channelId' | 'content' | 'senderName'>,
|
||||
room: Room | null,
|
||||
settings: NotificationsSettings,
|
||||
requestAttention: boolean
|
||||
requestAttention: boolean,
|
||||
translate: AppTranslateFn
|
||||
): NotificationDisplayPayload {
|
||||
const channelId = resolveMessageChannelId(message);
|
||||
const roomName = room?.name || 'Server';
|
||||
const roomName = room?.name || translate('notifications.display.defaultServerName');
|
||||
const channelLabel = getChannelLabel(room, channelId);
|
||||
|
||||
return {
|
||||
title: `${roomName} · #${channelLabel}`,
|
||||
body: settings.showPreview
|
||||
? formatMessagePreview(message.senderName, message.content)
|
||||
: `${message.senderName} sent a new message`,
|
||||
? formatMessagePreview(message.senderName, message.content, translate)
|
||||
: translate('notifications.display.newMessageHidden', { sender: message.senderName }),
|
||||
requestAttention
|
||||
};
|
||||
}
|
||||
@@ -147,16 +150,16 @@ export function calculateUnreadForRoom(
|
||||
};
|
||||
}
|
||||
|
||||
function formatMessagePreview(senderName: string, content: string): string {
|
||||
function formatMessagePreview(senderName: string, content: string, translate: AppTranslateFn): string {
|
||||
const normalisedContent = content.replace(/\s+/g, ' ').trim();
|
||||
|
||||
if (!normalisedContent) {
|
||||
return `${senderName} sent a new message`;
|
||||
return translate('notifications.display.newMessageEmpty', { sender: senderName });
|
||||
}
|
||||
|
||||
const preview = normalisedContent.length > MESSAGE_PREVIEW_LIMIT
|
||||
? `${normalisedContent.slice(0, MESSAGE_PREVIEW_LIMIT - 1)}...`
|
||||
: normalisedContent;
|
||||
|
||||
return `${senderName}: ${preview}`;
|
||||
return translate('notifications.display.preview', { sender: senderName, content: preview });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user