feat(mobile): route notification taps through mobile screen stack
This commit is contained in:
@@ -61,7 +61,10 @@ export function NotificationController() {
|
|||||||
const body = message.content
|
const body = message.content
|
||||||
? message.content.replace(/[*_~`>#\-\[\]]/g, '').slice(0, 100)
|
? message.content.replace(/[*_~`>#\-\[\]]/g, '').slice(0, 100)
|
||||||
: 'Sent an attachment';
|
: 'Sent an attachment';
|
||||||
sendNotification(displayName, body);
|
sendNotification(displayName, body, {
|
||||||
|
channelId: message.channelId ?? message.dmChannelId,
|
||||||
|
spaceId: message.dmChannelId ? '@me' : undefined,
|
||||||
|
});
|
||||||
break; // one notification per batch
|
break; // one notification per batch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
import { isElectron } from './platform';
|
import { isElectron } from './platform';
|
||||||
|
import { useUIStore } from '../stores/uiStore';
|
||||||
|
|
||||||
export function sendNotification(title: string, body: string): void {
|
interface NotificationOptions {
|
||||||
|
channelId?: string;
|
||||||
|
spaceId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendNotification(title: string, body: string, options?: NotificationOptions): void {
|
||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
window.backspace!.showNotification(title, body);
|
window.backspace!.showNotification(title, body);
|
||||||
} else if ('Notification' in window && Notification.permission === 'granted') {
|
} else if ('Notification' in window && Notification.permission === 'granted') {
|
||||||
new Notification(title, { body, icon: '/icons/icon-192.png' });
|
const notification = new Notification(title, { body, icon: '/icons/icon-192.png' });
|
||||||
|
notification.onclick = () => {
|
||||||
|
window.focus();
|
||||||
|
const { channelId, spaceId } = options ?? {};
|
||||||
|
if (channelId) {
|
||||||
|
const isMobile = useUIStore.getState().isMobile;
|
||||||
|
if (isMobile) {
|
||||||
|
useUIStore.getState().pushMobileScreen('channel-chat', {
|
||||||
|
channelId,
|
||||||
|
spaceId: spaceId || '@me',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user