1
- const { remote } = require ( 'electron' ) ;
1
+ const { remote, shell } = require ( 'electron' ) ;
2
2
3
- import { generateGitHubWebUrl } from './helpers' ;
3
+ import { generateGitHubWebUrl , getDiscussionUrl } from './helpers' ;
4
4
import { reOpenWindow , openExternalLink , updateTrayIcon } from './comms' ;
5
- import { Notification , User } from '../typesGithub' ;
5
+ import { Notification } from '../typesGithub' ;
6
6
7
- import { AccountNotifications , SettingsState } from '../types' ;
7
+ import { AccountNotifications , SettingsState , AuthState } from '../types' ;
8
8
9
9
export const setTrayIconColor = ( notifications : AccountNotifications [ ] ) => {
10
10
const allNotificationsCount = notifications . reduce (
@@ -19,7 +19,7 @@ export const triggerNativeNotifications = (
19
19
previousNotifications : AccountNotifications [ ] ,
20
20
newNotifications : AccountNotifications [ ] ,
21
21
settings : SettingsState ,
22
- user : User
22
+ accounts : AuthState
23
23
) => {
24
24
const diffNotifications = newNotifications
25
25
. map ( ( account ) => {
@@ -55,13 +55,13 @@ export const triggerNativeNotifications = (
55
55
}
56
56
57
57
if ( settings . showNotifications ) {
58
- raiseNativeNotification ( diffNotifications , user ?. id ) ;
58
+ raiseNativeNotification ( diffNotifications , accounts ) ;
59
59
}
60
60
} ;
61
61
62
62
export const raiseNativeNotification = (
63
63
notifications : Notification [ ] ,
64
- userId ?: number
64
+ accounts : AuthState
65
65
) => {
66
66
let title : string ;
67
67
let body : string ;
@@ -87,11 +87,22 @@ export const raiseNativeNotification = (
87
87
const appWindow = remote . getCurrentWindow ( ) ;
88
88
appWindow . hide ( ) ;
89
89
90
+ const { subject, id, repository } = notifications [ 0 ] ;
91
+
90
92
// Some Notification types from GitHub are missing urls in their subjects.
91
93
if ( notificationUrl ) {
92
- const { subject, id } = notifications [ 0 ] ;
93
- const url = generateGitHubWebUrl ( subject . url , id , userId ) ;
94
+ const url = generateGitHubWebUrl ( subject . url , id , accounts . user ?. id ) ;
94
95
openExternalLink ( url ) ;
96
+ } else if ( notifications [ 0 ] . subject . type === 'Discussion' ) {
97
+ getDiscussionUrl ( notifications [ 0 ] , accounts . token ) . then ( url =>
98
+ shell . openExternal (
99
+ generateGitHubWebUrl (
100
+ url || `${ repository . url } /discussions` ,
101
+ id ,
102
+ accounts . user ?. id
103
+ )
104
+ )
105
+ ) ;
95
106
}
96
107
} else {
97
108
reOpenWindow ( ) ;
0 commit comments