Skip to content

Commit 129bc98

Browse files
committed
Fixes
Signed-off-by: Alexander Platov <[email protected]>
1 parent 803cd0d commit 129bc98

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

desktop/src/ui/index.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '@hcengineering/ui'
1919
import { handleDownloadItem } from '@hcengineering/desktop-downloads'
2020
import { notificationId } from '@hcengineering/notification'
21+
import { inboxId } from '@hcengineering/inbox'
2122
import { workbenchId, logOut } from '@hcengineering/workbench'
2223
import { encodeObjectURI } from '@hcengineering/view'
2324
import { resolveLocation } from '@hcengineering/notification-resources'
@@ -26,7 +27,7 @@ import { isOwnerOrMaintainer } from '@hcengineering/core'
2627
import { configurePlatform } from './platform'
2728
import { setupTitleBarMenu } from './titleBarMenu'
2829
import { defineScreenShare, defineGetDisplayMedia } from './screenShare'
29-
import { CommandLogout, CommandSelectWorkspace, CommandOpenSettings, CommandOpenInbox, CommandOpenPlanner, CommandOpenOffice } from './types'
30+
import { CommandLogout, CommandSelectWorkspace, CommandOpenSettings, CommandOpenInbox, CommandOpenPlanner, CommandOpenOffice, NotificationParams } from './types'
3031
import { ipcMainExposed } from './typesUtils'
3132
import { themeStore } from '@hcengineering/theme'
3233

@@ -116,43 +117,45 @@ window.addEventListener('DOMContentLoaded', () => {
116117
navigate(parseLocation(urlObject))
117118
})
118119

119-
ipcMain.handleNotificationNavigation((notificationParams) => {
120-
// If we have notification location data, use it for proper navigation
121-
if (notificationParams.objectId != null && notificationParams.objectClass != null && notificationParams.docNotifyContext != null) {
122-
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? window.location.origin
120+
function navigateToUrl (path: string): void {
121+
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? window.location.origin
122+
const urlObject = new URL(`${frontUrl}/${path}`)
123+
navigate(parseLocation(urlObject))
124+
}
125+
126+
function getBasicNotificationPath (notificationParams: NotificationParams): string {
127+
return `${workbenchId}/${notificationParams.application ?? notificationId}/${notificationId}`
128+
}
129+
130+
ipcMain.handleNotificationNavigation((notificationParams: NotificationParams) => {
131+
// Support for new inbox with cardId (card-based)
132+
if (notificationParams.cardId != null) {
123133
const currentLocation = getCurrentResolvedLocation()
124-
const encodedObjectURI = encodeObjectURI(notificationParams.objectId, notificationParams.objectClass as any)
134+
navigateToUrl(`${workbenchId}/${currentLocation.path[1]}/${inboxId}/${notificationParams.cardId}`)
135+
return
136+
}
125137

138+
// Support for old inbox with objectId + objectClass (legacy)
139+
if (notificationParams.objectId != null && notificationParams.objectClass != null) {
140+
const encodedObjectURI = encodeObjectURI(notificationParams.objectId, notificationParams.objectClass)
126141
const notificationLocation = {
127-
path: [workbenchId, currentLocation.path[1], notificationId, encodedObjectURI],
142+
path: [workbenchId, notificationParams.application, notificationId, encodedObjectURI],
128143
fragment: undefined,
129144
query: {}
130145
}
131146

132147
void resolveLocation(notificationLocation).then((resolvedLocation) => {
133-
if (resolvedLocation !== undefined) {
148+
if (resolvedLocation?.loc != null) {
134149
navigate(resolvedLocation.loc)
135150
} else {
136-
// Fallback navigation if resolution fails
137-
const urlString = `${frontUrl}/${workbenchId}/${currentLocation.path[1]}/${notificationId}/${encodedObjectURI}`
138-
const urlObject = new URL(urlString)
139-
navigate(parseLocation(urlObject))
151+
navigateToUrl(`${workbenchId}/${notificationParams.application}/${notificationId}/${encodedObjectURI}`)
140152
}
141153
}).catch(() => {
142-
// Fallback to basic navigation if resolution fails
143-
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? window.location.origin
144-
const location = getCurrentResolvedLocation()
145-
const urlString = `${frontUrl}/${workbenchId}/${location.path[1]}/${notificationParams.application ?? notificationId}`
146-
const urlObject = new URL(urlString)
147-
navigate(parseLocation(urlObject))
154+
navigateToUrl(getBasicNotificationPath(notificationParams))
148155
})
149156
} else {
150-
// Fallback to basic navigation for old notifications without object data
151-
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? window.location.origin
152-
const location = getCurrentResolvedLocation()
153-
const urlString = `${frontUrl}/${workbenchId}/${location.path[1]}/${notificationParams.application ?? notificationId}`
154-
const urlObject = new URL(urlString)
155-
navigate(parseLocation(urlObject))
157+
// Fallback to basic notification navigation
158+
navigateToUrl(getBasicNotificationPath(notificationParams))
156159
}
157160
})
158161

desktop/src/ui/notifications.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export function configureNotifications (): void {
169169
body: `${notification.content.senderName}: ${notification.content.shortText}`,
170170
objectId: notification.content.objectId,
171171
objectClass: notification.content.objectClass,
172-
docNotifyContext: notification.content.docNotifyContext
172+
cardId: notification.cardId
173173
})
174174
}
175175
})
@@ -219,9 +219,8 @@ export function configureNotifications (): void {
219219
electronAPI.sendNotification({
220220
silent: !preferences.playSound,
221221
application: notificationId,
222-
objectId: notification.objectId as string,
223-
objectClass: notification.objectClass as string,
224-
docNotifyContext: notification.docNotifyContext as string,
222+
objectId: notification.objectId,
223+
objectClass: notification.objectClass,
225224
...notificationData
226225
})
227226
}

desktop/src/ui/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DownloadItem } from '@hcengineering/desktop-downloads'
22
import { ScreenSource } from '@hcengineering/love'
33
import { Plugin } from '@hcengineering/platform'
4+
import { Ref, Class, Doc, Space } from '@hcengineering/core'
45
import { IpcRendererEvent } from 'electron'
56

67
export interface Config {
@@ -93,9 +94,9 @@ export interface NotificationParams {
9394
body: string
9495
silent: boolean
9596
application: Plugin
96-
objectId?: string
97-
objectClass?: string
98-
docNotifyContext?: string
97+
objectId?: Ref<Doc<Space>>
98+
objectClass?: Ref<Class<Doc>>
99+
cardId?: string
99100
}
100101

101102
export const MenuBarActions = ['settings', 'select-workspace', 'logout', 'exit', 'undo', 'redo', 'cut', 'copy', 'paste', 'delete', 'select-all', 'reload', 'force-reload', 'toggle-devtools'

0 commit comments

Comments
 (0)