@@ -6,24 +6,57 @@ import { GitHub } from '@github-manager/client';
66import { NotificationProvider } from './NotificationProvider' ;
77
88export class DefaultNotificationProvider implements NotificationProvider {
9+ private readonly projectSourceMap : Map < string , MessageTray . Source > ;
10+
11+ private digestSource : MessageTray . Source | undefined ;
12+
13+ public constructor ( ) {
14+ this . projectSourceMap = new Map ( ) ;
15+ this . digestSource = undefined ;
16+ }
17+
918 public newProjectNotification ( data : GitHub . Thread ) : MessageTray . Notification {
1019 const repositoryName = data . repository . name ;
1120 const repositoryIcon = Gio . icon_new_for_string ( data . repository . owner . avatar_url ) ;
21+ const projectSource = this . getOrCreateProjectSource ( repositoryName , repositoryIcon ) ;
1222
1323 return new MessageTray . Notification ( {
14- source : new MessageTray . Source ( { title : repositoryName , icon : repositoryIcon } ) ,
24+ source : projectSource ,
1525 title : repositoryName ,
1626 body : data . subject . title ,
1727 isTransient : false ,
1828 } ) ;
1929 }
2030
2131 public newDigestNotification ( digestIcon : Gio . Icon , title : string , body : string ) : MessageTray . Notification {
32+ if ( this . digestSource === undefined ) {
33+ this . digestSource = new MessageTray . Source ( { title : 'Github Notification' , icon : digestIcon } ) ;
34+ this . digestSource . connect ( 'destroy' , ( _source ) => {
35+ this . digestSource = undefined ;
36+ } ) ;
37+ }
38+
2239 return new MessageTray . Notification ( {
23- source : new MessageTray . Source ( { title : 'Github Notification' , icon : digestIcon } ) ,
40+ source : this . digestSource ,
2441 title : title ,
2542 body : body ,
2643 isTransient : false ,
2744 } ) ;
2845 }
46+
47+ private getOrCreateProjectSource ( repositoryName : string , repositoryIcon : Gio . Icon ) : MessageTray . Source {
48+ let source : MessageTray . Source | undefined = this . projectSourceMap . get ( repositoryName ) ;
49+ if ( source !== undefined ) {
50+ return source ;
51+ }
52+
53+ source = new MessageTray . Source ( { title : repositoryName , icon : repositoryIcon } ) ;
54+ source . connect ( 'destroy' , ( _source ) => {
55+ this . projectSourceMap . delete ( repositoryName ) ;
56+ source = undefined ;
57+ } ) ;
58+
59+ this . projectSourceMap . set ( repositoryName , source ) ;
60+ return source ;
61+ }
2962}
0 commit comments