Merge branch 'add-experimental-page' of github.com:Rosy-iso/sable into add-experimental-page

This commit is contained in:
Rosy.iso committed 2026-03-03 20:05:47 +01:00
commit df7d8d0f2a
14 files changed
+342 -126

No files matched your search

@@ -156,34 +156,44 @@ export function Cosmetics({ requestClose }: CosmeticsProps) {
variant="SurfaceVariant"
direction="Column"
gap="400"
style={{ padding: '16px' }}
>
<Box direction="Column" gap="200">
<Box direction="Column">
<Text size="T300">/color [hex]</Text>
<Text size="T200" priority="300">
Set room-specific name color. (e.g. /color #ff00ff)
</Text>
</Box>
<Box direction="Column">
<Text size="T300">/font [name]</Text>
<Text size="T200" priority="300">
Set room-specific name font. (e.g. /font monospace)
</Text>
</Box>
<Box direction="Column">
<Text size="T300">/pronoun [pronouns]</Text>
<Text size="T200" priority="300">
Set room-specific pronoun set. (e.g. /pronoun &quot;they\them, it\its&quot;)
</Text>
</Box>
<Box direction="Column">
<Text size="T300">/gcolor | /gfont | /gpronoun</Text>
<Text size="T200" priority="300">
Apply colors/fonts/pronouns to the entire space.
</Text>
</Box>
</Box>
<SettingTile
title="/color [hex]"
description="Set room-specific name color. (e.g. /color #ff00ff)"
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="/font [name]"
description="Set room-specific name font. (e.g. /font monospace)"
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="/pronoun [pronouns]"
description='Set room-specific pronoun set. (e.g. /pronoun "they\them, it\its")'
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="/gcolor | /gfont | /gpronoun"
description="Apply colors/fonts/pronouns to the entire space."
/>
</SequenceCard>
</Box>
</Box>
+61 -39
View File
@@ -75,6 +75,8 @@ import {
renderMatrixMention,
} from '$plugins/react-custom-html-parser';
import {
roomHaveNotification,
roomHaveUnread,
canEditEvent,
decryptAllTimelineEvent,
getEditedEvent,
@@ -259,6 +261,7 @@ type RoomTimelineProps = {
};
const PAGINATION_LIMIT = 60;
const EVENT_TIMELINE_LOAD_TIMEOUT_MS = 12000;
type Timeline = {
linkedTimelines: EventTimeline[];
@@ -273,12 +276,38 @@ const useEventTimelineLoader = (
) =>
useCallback(
async (eventId: string) => {
const withTimeout = async <T,>(promise: Promise<T>, timeoutMs: number): Promise<T> =>
new Promise<T>((resolve, reject) => {
const timeoutId = window.setTimeout(() => {
reject(new Error('Timed out loading event timeline'));
}, timeoutMs);
promise
.then((value) => {
window.clearTimeout(timeoutId);
resolve(value);
})
.catch((error) => {
window.clearTimeout(timeoutId);
reject(error);
});
});
if (!room.getUnfilteredTimelineSet().getTimelineForEvent(eventId)) {
await mx.roomInitialSync(room.roomId, PAGINATION_LIMIT);
await mx.getLatestTimeline(room.getUnfilteredTimelineSet());
await withTimeout(
mx.roomInitialSync(room.roomId, PAGINATION_LIMIT),
EVENT_TIMELINE_LOAD_TIMEOUT_MS
);
await withTimeout(
mx.getLatestTimeline(room.getUnfilteredTimelineSet()),
EVENT_TIMELINE_LOAD_TIMEOUT_MS
);
}
const [err, replyEvtTimeline] = await to(
mx.getEventTimeline(room.getUnfilteredTimelineSet(), eventId)
withTimeout(
mx.getEventTimeline(room.getUnfilteredTimelineSet(), eventId),
EVENT_TIMELINE_LOAD_TIMEOUT_MS
)
);
if (!replyEvtTimeline) {
onError(err ?? null);
@@ -359,31 +388,34 @@ const useTimelinePagination = (
}
fetching = true;
const [err] = await to(
mx.paginateEventTimeline(timelineToPaginate, {
backwards,
limit,
})
);
if (err) {
// TODO: handle pagination error.
return;
}
const fetchedTimeline =
timelineToPaginate.getNeighbouringTimeline(
backwards ? Direction.Backward : Direction.Forward
) ?? timelineToPaginate;
// Decrypt all event ahead of render cycle
const roomId = fetchedTimeline.getRoomId();
const room = roomId ? mx.getRoom(roomId) : null;
try {
const [err] = await to(
mx.paginateEventTimeline(timelineToPaginate, {
backwards,
limit,
})
);
if (err) {
// TODO: handle pagination error.
return;
}
const fetchedTimeline =
timelineToPaginate.getNeighbouringTimeline(
backwards ? Direction.Backward : Direction.Forward
) ?? timelineToPaginate;
// Decrypt all event ahead of render cycle
const roomId = fetchedTimeline.getRoomId();
const room = roomId ? mx.getRoom(roomId) : null;
if (room?.hasEncryptionStateEvent()) {
await to(decryptAllTimelineEvent(mx, fetchedTimeline));
}
if (room?.hasEncryptionStateEvent()) {
await to(decryptAllTimelineEvent(mx, fetchedTimeline));
}
fetching = false;
if (alive()) {
recalibratePagination(lTimelines, timelinesEventsCount, backwards);
if (alive()) {
recalibratePagination(lTimelines, timelinesEventsCount, backwards);
}
} finally {
fetching = false;
}
};
}, [mx, alive, setTimeline, limit]);
@@ -450,6 +482,8 @@ const getEmptyTimeline = () => ({
});
const getRoomUnreadInfo = (room: Room, scrollTo = false) => {
if (!roomHaveNotification(room) && !roomHaveUnread(room.client, room)) return undefined;
const readUptoEventId = room.getEventReadUpTo(room.client.getUserId() ?? '');
if (!readUptoEventId) return undefined;
const evtTimeline = getEventTimeline(room, readUptoEventId);
@@ -718,7 +752,6 @@ export function RoomTimeline({
highlight,
});
} else {
setTimeline(getEmptyTimeline());
loadEventTimeline(evtId);
}
},
@@ -815,20 +848,10 @@ export function RoomTimeline({
useCallback(
(inFocus) => {
if (inFocus && atBottomRef.current) {
if (unreadInfo?.inLiveTimeline) {
handleOpenEvent(unreadInfo.readUptoEventId, false, (scrolled) => {
// the unread event is already in view
// so, try mark as read;
if (!scrolled) {
tryAutoMarkAsRead();
}
});
return;
}
tryAutoMarkAsRead();
}
},
[tryAutoMarkAsRead, unreadInfo, handleOpenEvent]
[tryAutoMarkAsRead]
)
);
@@ -1000,7 +1023,6 @@ export function RoomTimeline({
const handleJumpToUnread = () => {
if (unreadInfo?.readUptoEventId) {
setTimeline(getEmptyTimeline());
loadEventTimeline(unreadInfo.readUptoEventId);
}
};
+1 -1
View File
@@ -67,7 +67,7 @@ export function About({ requestClose }: AboutProps) {
</Button>
<Button
as="a"
href="https://github.com/7w1/sable"
href="https://github.com/7w1/sable/pulls"
rel="noreferrer noopener"
target="_blank"
variant="Critical"
+17 -19
View File
@@ -100,11 +100,7 @@ function ProfileAvatar({ profile, userId }: ProfileProps) {
return (
<SettingTile
title={
<Text as="span" size="L400">
Avatar
</Text>
}
title="Avatar"
after={
<Avatar size="500" radii="300">
<UserAvatar
@@ -280,13 +276,7 @@ function ProfileBanner({ profile, userId }: ProfileProps) {
const previewUrl = isRemoving ? undefined : imageFileURL || stagedUrl || bannerUrl;
return (
<SettingTile
title={
<Text as="span" size="L400">
Profile Banner
</Text>
}
>
<SettingTile title="Banner">
<Box direction="Column" gap="300" grow="Yes">
<Box
style={{
@@ -432,13 +422,7 @@ function ProfileDisplayName({ profile, userId }: ProfileProps) {
const hasChanges = displayName !== defaultDisplayName;
return (
<SettingTile
title={
<Text as="span" size="L400">
Display Name
</Text>
}
>
<SettingTile title="Display Name">
<Box direction="Column" grow="Yes" gap="100">
<Box
as="form"
@@ -635,7 +619,21 @@ export function Profile() {
gap="400"
>
<ProfileBanner userId={userId} profile={profile} />
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<ProfileAvatar userId={userId} profile={profile} />
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<ProfileDisplayName userId={userId} profile={profile} />
</SequenceCard>
</Box>
@@ -171,6 +171,7 @@ export function SyncDiagnostics() {
size="300"
variant="Secondary"
fill="Soft"
outlined
radii="300"
before={<Icon src={expandSliding ? Icons.ChevronTop : Icons.ChevronBottom} />}
onClick={() => setExpandSliding((v) => !v)}
+30 -5
View File
@@ -804,7 +804,9 @@ export function Sync() {
return (
<Box direction="Column" gap="100">
<Text size="L400">Sync</Text>
<Text size="L400" style={{ opacity: serverSlidingEnabled ? 1 : 0.5 }}>
Sync
</Text>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
@@ -812,11 +814,34 @@ export function Sync() {
style={{ opacity: serverSlidingEnabled ? 1 : 0.5 }}
>
<SettingTile
title="Use Sliding Sync"
title="Use Sliding Sync (Experimental)"
description={
serverSlidingEnabled
? 'Enable Sliding Sync for this current login/session.'
: 'Unavailable: this server config has Sliding Sync disabled.'
serverSlidingEnabled ? (
<>
Enable Sliding Sync for this current login/session. Requires server support and
admin configuration. May cause issues, use with caution.{' '}
<a
href="https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/sss/proposals/4186-simplified-sliding-sync.md"
target="_blank"
rel="noreferrer"
>
More info
</a>
.
</>
) : (
<>
Unavailable: the server has disabled Sliding Sync in its config.{' '}
<a
href="https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/sss/proposals/4186-simplified-sliding-sync.md"
target="_blank"
rel="noreferrer"
>
More info
</a>
.
</>
)
}
after={
<Switch
@@ -112,35 +112,34 @@ export function DeregisterAllPushersSetting() {
)}
<SettingTile
title="Reset all push notifications"
title="Reset All Push Notifications"
description={
<div>
<Text>
This will remove push notifications from all your sessions/devices. You will need to
re-enable them on each device individually.
</Text>
{deregisterState.status === AsyncStatus.Error && (
<Text as="span" style={{ color: color.Critical.Main }} size="T200">
<br />
Failed to deregister devices. Please try again.
</Text>
)}
{deregisterState.status === AsyncStatus.Success && (
<Text as="span" style={{ color: color.Success.Main }} size="T200">
<br />
Successfully deregistered all devices.
</Text>
)}
</div>
<>
This will remove push notifications from all your sessions/devices.
<br />
You will need to re-enable them on each device individually.
</>
}
after={
<Button size="300" radii="300" onClick={handleOpenConfirmDialog}>
<Text size="B300" style={{ color: color.Critical.Main }}>
Reset All
</Text>
<Button size="300" radii="300" variant="Critical" onClick={handleOpenConfirmDialog}>
<Text size="B300">Reset All</Text>
</Button>
}
/>
>
{/* FIXME: these two things below, even before my changes, don't really seem to ever appear? */}
{deregisterState.status === AsyncStatus.Error && (
<Text as="span" style={{ color: color.Critical.Main }} size="T200">
<br />
Failed to deregister devices. Please try again.
</Text>
)}
{deregisterState.status === AsyncStatus.Success && (
<Text as="span" style={{ color: color.Success.Main }} size="T200">
<br />
Successfully deregistered all devices.
</Text>
)}
</SettingTile>
</>
);
}
@@ -169,6 +169,14 @@ export function SystemNotification() {
settingsAtom,
'isNotificationSounds'
);
const [showMessageContent, setShowMessageContent] = useSetting(
settingsAtom,
'showMessageContentInNotifications'
);
const [showEncryptedMessageContent, setShowEncryptedMessageContent] = useSetting(
settingsAtom,
'showMessageContentInEncryptedNotifications'
);
return (
<Box direction="Column" gap="100">
@@ -193,6 +201,36 @@ export function SystemNotification() {
after={<Switch value={showInAppNotifs} onChange={setShowInAppNotifs} />}
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="Show Message Content"
description="Include message text in notification bodies."
after={<Switch value={showMessageContent} onChange={setShowMessageContent} />}
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
direction="Column"
gap="400"
>
<SettingTile
title="Show Encrypted Message Content"
description="Allow message text from encrypted rooms in notification bodies. May not work on some platforms due to technical limitations."
after={
<Switch
value={showEncryptedMessageContent}
onChange={setShowEncryptedMessageContent}
disabled={!showMessageContent}
/>
}
/>
</SequenceCard>
<SequenceCard
className={SequenceCardStyle}
variant="SurfaceVariant"
@@ -19,13 +19,21 @@ import {
import { useSetting } from '$state/hooks/settings';
import { settingsAtom } from '$state/settings';
import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix';
import { getMemberDisplayName, getNotificationType, isNotificationEvent } from '$utils/room';
import { NotificationType } from '$types/matrix/room';
import {
getMemberDisplayName,
getNotificationType,
getStateEvent,
isNotificationEvent,
} from '$utils/room';
import { NotificationType, StateEvent } from '$types/matrix/room';
import { createLogger } from '$utils/debug';
import LogoSVG from '$public/res/svg/cinny.svg';
import { nicknamesAtom } from '$state/nicknames';
import { useMatrixClient } from '$hooks/useMatrixClient';
import { buildRoomMessageNotification } from '$utils/notificationStyle';
import {
buildRoomMessageNotification,
resolveNotificationPreviewText,
} from '$utils/notificationStyle';
import { mobileOrTablet } from '$utils/user-agent';
import { startClient, stopClient } from '$client/initMatrix';
import { useClientConfig } from '$hooks/useClientConfig';
@@ -79,6 +87,11 @@ export function BackgroundNotifications() {
const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications');
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds');
const [showMessageContent] = useSetting(settingsAtom, 'showMessageContentInNotifications');
const [showEncryptedMessageContent] = useSetting(
settingsAtom,
'showMessageContentInEncryptedNotifications'
);
const forcePushOnMobile = usePushNotifications && mobileOrTablet();
const activeMx = useMatrixClient();
const nicknames = useAtomValue(nicknamesAtom);
@@ -194,6 +207,7 @@ export function BackgroundNotifications() {
: LogoSVG;
const isHighlight = pushActions.tweaks?.highlight === true;
const isEncryptedRoom = !!getStateEvent(room, StateEvent.RoomEncryption);
notifiedEventsRef.current.add(eventId);
// Cap the set so it doesn't grow unbounded
@@ -206,7 +220,13 @@ export function BackgroundNotifications() {
roomName: room.name ?? 'Unknown',
roomAvatar,
username: senderName,
previewText: 'new message',
previewText: resolveNotificationPreviewText({
content: mEvent.getContent(),
eventType: mEvent.getType(),
isEncryptedRoom,
showMessageContent,
showEncryptedMessageContent,
}),
silent: !notificationSound || !isHighlight,
eventId,
data: {
@@ -248,6 +268,8 @@ export function BackgroundNotifications() {
forcePushOnMobile,
showNotifications,
notificationSound,
showMessageContent,
showEncryptedMessageContent,
activeMx,
activeSessionId,
setActiveSessionId,
+32 -4
View File
@@ -18,17 +18,21 @@ import { useMatrixClient } from '$hooks/useMatrixClient';
import {
getMemberDisplayName,
getNotificationType,
getStateEvent,
getUnreadInfo,
isNotificationEvent,
} from '$utils/room';
import { NotificationType, UnreadInfo } from '$types/matrix/room';
import { NotificationType, StateEvent, UnreadInfo } from '$types/matrix/room';
import { getMxIdLocalPart, mxcUrlToHttp } from '$utils/matrix';
import { useSelectedRoom } from '$hooks/router/useSelectedRoom';
import { useInboxNotificationsSelected } from '$hooks/router/useInbox';
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
import { registrationAtom } from '$state/serviceWorkerRegistration';
import { activeSessionIdAtom, pendingNotificationAtom } from '$state/sessions';
import { buildRoomMessageNotification } from '$utils/notificationStyle';
import {
buildRoomMessageNotification,
resolveNotificationPreviewText,
} from '$utils/notificationStyle';
import { mobileOrTablet } from '$utils/user-agent';
import { getInboxInvitesPath, getInboxNotificationsPath } from '../pathUtils';
import { BackgroundNotifications } from './BackgroundNotifications';
@@ -176,6 +180,11 @@ function MessageNotifications() {
const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications');
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds');
const [showMessageContent] = useSetting(settingsAtom, 'showMessageContentInNotifications');
const [showEncryptedMessageContent] = useSetting(
settingsAtom,
'showMessageContentInEncryptedNotifications'
);
const forcePushOnMobile = usePushNotifications && mobileOrTablet();
const nicknames = useAtomValue(nicknamesAtom);
const nicknamesRef = useRef(nicknames);
@@ -192,18 +201,20 @@ function MessageNotifications() {
username,
roomId,
eventId,
previewText,
}: {
roomName: string;
roomAvatar?: string;
username: string;
roomId: string;
eventId: string;
previewText: string;
}) => {
const payload = buildRoomMessageNotification({
roomName,
roomAvatar,
username,
previewText: 'new message',
previewText,
silent: true,
eventId,
});
@@ -267,6 +278,7 @@ function MessageNotifications() {
}
if (showNotifications && notificationPermission('granted')) {
const isEncryptedRoom = !!getStateEvent(room, StateEvent.RoomEncryption);
const avatarMxc =
room.getAvatarFallbackMember()?.getMxcAvatarUrl() ?? room.getMxcAvatarUrl();
notify({
@@ -280,6 +292,13 @@ function MessageNotifications() {
sender,
roomId: room.roomId,
eventId,
previewText: resolveNotificationPreviewText({
content: mEvent.getContent(),
eventType: mEvent.getType(),
isEncryptedRoom,
showMessageContent,
showEncryptedMessageContent,
}),
});
}
@@ -296,6 +315,8 @@ function MessageNotifications() {
notificationSound,
notificationSelected,
showNotifications,
showMessageContent,
showEncryptedMessageContent,
usePushNotifications,
forcePushOnMobile,
playSound,
@@ -386,6 +407,11 @@ function HandleNotificationClick() {
function SyncNotificationSettingsWithServiceWorker() {
const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds');
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
const [showMessageContent] = useSetting(settingsAtom, 'showMessageContentInNotifications');
const [showEncryptedMessageContent] = useSetting(
settingsAtom,
'showMessageContentInEncryptedNotifications'
);
useEffect(() => {
if (!('serviceWorker' in navigator)) return;
@@ -394,13 +420,15 @@ function SyncNotificationSettingsWithServiceWorker() {
type: 'setNotificationSettings' as const,
notificationSoundEnabled: notificationSound,
preferPushOnMobile,
showMessageContent,
showEncryptedMessageContent,
};
navigator.serviceWorker.controller?.postMessage(payload);
navigator.serviceWorker.ready.then((registration) => {
registration.active?.postMessage(payload);
});
}, [notificationSound, usePushNotifications]);
}, [notificationSound, usePushNotifications, showMessageContent, showEncryptedMessageContent]);
return null;
}
+4
View File
@@ -46,6 +46,8 @@ export interface Settings {
usePushNotifications: boolean;
useInAppNotifications: boolean;
isNotificationSounds: boolean;
showMessageContentInNotifications: boolean;
showMessageContentInEncryptedNotifications: boolean;
hour24Clock: boolean;
dateFormatString: string;
@@ -97,6 +99,8 @@ const defaultSettings: Settings = {
usePushNotifications: false,
useInAppNotifications: true,
isNotificationSounds: true,
showMessageContentInNotifications: false,
showMessageContentInEncryptedNotifications: false,
hour24Clock: false,
dateFormatString: 'D MMM YYYY',
+41 -1
View File
@@ -1,5 +1,7 @@
export const DEFAULT_NOTIFICATION_ICON = '/public/res/apple/apple-touch-icon-180x180.png';
export const DEFAULT_NOTIFICATION_BADGE = '/public/res/apple/apple-touch-icon-72x72.png';
export const DEFAULT_MESSAGE_PREVIEW = 'new message';
export const ENCRYPTED_MESSAGE_PREVIEW = 'Encrypted message';
type RoomMessageNotificationInput = {
roomName?: string;
@@ -16,12 +18,50 @@ type NotificationPayload = {
options: NotificationOptions;
};
type NotificationPreviewInput = {
content?: unknown;
eventType?: string;
isEncryptedRoom?: boolean;
showMessageContent: boolean;
showEncryptedMessageContent: boolean;
};
const getString = (value: unknown, fallback: string): string => {
if (typeof value !== 'string') return fallback;
const normalized = value.trim();
return normalized.length > 0 ? normalized : fallback;
};
const getBodyFromContent = (content: unknown): string | undefined => {
if (!content || typeof content !== 'object') return undefined;
const { body } = content as Record<string, unknown>;
if (typeof body !== 'string') return undefined;
const normalized = body.trim();
return normalized.length > 0 ? normalized : undefined;
};
export const resolveNotificationPreviewText = ({
content,
eventType,
isEncryptedRoom,
showMessageContent,
showEncryptedMessageContent,
}: NotificationPreviewInput): string => {
const encryptedContext = isEncryptedRoom || eventType === 'm.room.encrypted';
if (!showMessageContent) {
return encryptedContext ? ENCRYPTED_MESSAGE_PREVIEW : DEFAULT_MESSAGE_PREVIEW;
}
if (encryptedContext && !showEncryptedMessageContent) {
return ENCRYPTED_MESSAGE_PREVIEW;
}
const body = getBodyFromContent(content);
if (body) return body;
return encryptedContext ? ENCRYPTED_MESSAGE_PREVIEW : DEFAULT_MESSAGE_PREVIEW;
};
export const buildRoomMessageNotification = ({
roomName,
username,
@@ -33,7 +73,7 @@ export const buildRoomMessageNotification = ({
}: RoomMessageNotificationInput): NotificationPayload => {
const sender = getString(username, 'Someone');
const room = getString(roomName, 'Unknown');
const message = getString(previewText, 'new message');
const message = getString(previewText, DEFAULT_MESSAGE_PREVIEW);
const avatar = getString(roomAvatar, DEFAULT_NOTIFICATION_ICON);
return {
+14
View File
@@ -9,8 +9,12 @@ declare const self: ServiceWorkerGlobalScope;
let notificationSoundEnabled = true;
let preferPushOnMobile = false;
let showMessageContent = false;
let showEncryptedMessageContent = false;
const { handlePushNotificationPushData } = createPushNotifications(self, () => ({
notificationSoundEnabled,
showMessageContent,
showEncryptedMessageContent,
}));
type SessionInfo = {
@@ -124,6 +128,16 @@ self.addEventListener('message', (event: ExtendableMessageEvent) => {
if (typeof (data as { preferPushOnMobile?: unknown }).preferPushOnMobile === 'boolean') {
preferPushOnMobile = (data as { preferPushOnMobile: boolean }).preferPushOnMobile;
}
if (typeof (data as { showMessageContent?: unknown }).showMessageContent === 'boolean') {
showMessageContent = (data as { showMessageContent: boolean }).showMessageContent;
}
if (
typeof (data as { showEncryptedMessageContent?: unknown }).showEncryptedMessageContent ===
'boolean'
) {
showEncryptedMessageContent = (data as { showEncryptedMessageContent: boolean })
.showEncryptedMessageContent;
}
}
});
+17 -2
View File
@@ -3,10 +3,13 @@ import {
buildRoomMessageNotification,
DEFAULT_NOTIFICATION_ICON,
DEFAULT_NOTIFICATION_BADGE,
resolveNotificationPreviewText,
} from '../app/utils/notificationStyle';
type NotificationSettings = {
notificationSoundEnabled: boolean;
showMessageContent: boolean;
showEncryptedMessageContent: boolean;
};
export const createPushNotifications = (
@@ -49,7 +52,13 @@ export const createPushNotifications = (
roomName: pushData?.room_name,
username: pushData?.sender_display_name,
roomAvatar: pushData?.room_avatar_url,
previewText: 'new message',
previewText: resolveNotificationPreviewText({
content: pushData?.content,
eventType: pushData?.type,
isEncryptedRoom: false,
showMessageContent: getNotificationSettings().showMessageContent,
showEncryptedMessageContent: getNotificationSettings().showEncryptedMessageContent,
}),
silent: resolveSilent(pushData?.silent),
eventId: pushData?.event_id,
data,
@@ -77,7 +86,13 @@ export const createPushNotifications = (
roomName: pushData?.room_name,
username: pushData?.sender_display_name,
roomAvatar: pushData?.room_avatar_url,
previewText: 'Encrypted message',
previewText: resolveNotificationPreviewText({
content: pushData?.content,
eventType: pushData?.type,
isEncryptedRoom: true,
showMessageContent: getNotificationSettings().showMessageContent,
showEncryptedMessageContent: getNotificationSettings().showEncryptedMessageContent,
}),
silent: resolveSilent(pushData?.silent),
eventId: pushData?.event_id,
data,