@@ -353,20 +353,72 @@ async function feedMenu(ui, client, own = false) {
353353 }
354354}
355355
356- async function showAnnouncements ( ui , client , automatic = false ) {
356+ export function announcementMenuLabel ( item ) {
357+ const readState = item . readAt === null ? '● Okunmadı' : '✓ Okundu' ;
358+ return `${ readState } · ${ item . severity } · ${ item . title } ` ;
359+ }
360+
361+ export function announcementActions ( item , automatic ) {
362+ if ( automatic ) {
363+ return item . severity === 'critical'
364+ ? [
365+ { label : 'Okudum' , value : 'read' } ,
366+ { label : 'CLI’dan çık' , value : 'exit' } ,
367+ ]
368+ : [
369+ { label : 'Okudum' , value : 'read' } ,
370+ { label : 'Şimdilik geç' , value : 'skip' } ,
371+ ] ;
372+ }
373+ return item . readAt === null
374+ ? [
375+ { label : 'Okudum' , value : 'read' } ,
376+ { label : 'Geri' , value : 'back' } ,
377+ ]
378+ : [ { label : 'Geri' , value : 'back' } ] ;
379+ }
380+
381+ function printAnnouncement ( ui , item ) {
382+ ui . clear ( ) ;
383+ ui . header ( `Sistem duyurusu · ${ item . severity } ` ) ;
384+ process . stdout . write ( `${ item . title } \n\n${ item . bodyMarkdown } \n` ) ;
385+ }
386+
387+ export async function showAnnouncements ( ui , client , automatic = false ) {
357388 try {
358389 const { body } = await client . announcements ( ) ;
359- const unread = body . announcements . filter ( ( item ) => item . readAt === null ) ;
360- if ( ! unread . length ) return ;
361- for ( const item of unread ) {
362- ui . clear ( ) ; ui . header ( `Sistem duyurusu · ${ item . severity } ` ) ;
363- process . stdout . write ( `${ item . title } \n\n${ item . bodyMarkdown } \n` ) ;
364- const action = await ui . select ( 'Duyuru' , [
365- { label : 'Okudum' , value : 'read' } ,
366- { label : automatic ? 'Şimdilik geç' : 'Geri' , value : 'skip' } ,
390+ const announcements = body . announcements ;
391+ if ( automatic ) {
392+ const unread = announcements . filter ( ( item ) => item . readAt === null ) ;
393+ for ( const item of unread ) {
394+ printAnnouncement ( ui , item ) ;
395+ const action = await ui . select ( 'Duyuru' , announcementActions ( item , true ) ) ;
396+ if ( action === 'read' ) await client . markAnnouncementRead ( item . id ) ;
397+ if ( action === 'skip' || action === 'exit' ) return action ;
398+ }
399+ return ;
400+ }
401+ if ( ! announcements . length ) {
402+ ui . clear ( ) ;
403+ ui . header ( 'Sistem duyuruları' ) ;
404+ process . stdout . write ( 'Aktif sistem duyurusu yok.\n' ) ;
405+ await ui . pause ( ) ;
406+ return ;
407+ }
408+ while ( true ) {
409+ const id = await ui . select ( 'Sistem duyuruları' , [
410+ ...announcements . map ( ( item ) => ( { label : announcementMenuLabel ( item ) , value : item . id } ) ) ,
411+ { label : 'Geri' , value : null } ,
367412 ] ) ;
368- if ( action === 'read' ) await client . markAnnouncementRead ( item . id ) ;
369- if ( action === 'skip' && automatic ) return ;
413+ if ( ! id ) return ;
414+ const item = announcements . find ( ( candidate ) => candidate . id === id ) ;
415+ if ( ! item ) continue ;
416+ printAnnouncement ( ui , item ) ;
417+ const action = await ui . select ( 'Duyuru' , announcementActions ( item , false ) ) ;
418+ if ( action === 'read' ) {
419+ await client . markAnnouncementRead ( item . id ) ;
420+ item . readAt = Date . now ( ) ;
421+ }
370422 }
371423 } catch ( error ) {
372424 if ( ! automatic ) { process . stdout . write ( `Duyurular alınamadı: ${ explainError ( error ) } \n` ) ; await ui . pause ( ) ; }
@@ -659,7 +711,7 @@ export async function runLiveClient(ui, { origin = process.env.ORBIT_API_ORIGIN
659711 return ;
660712 }
661713 const client = new OrbitApiClient ( { origin, agent : ui . agent , credential } ) ;
662- await showAnnouncements ( ui , client , true ) ;
714+ if ( await showAnnouncements ( ui , client , true ) === 'exit' ) return 'exit' ;
663715 while ( true ) {
664716 const [ dmState , announcementState ] = await Promise . all ( [
665717 mainMenuDirectMessageState ( client ) ,
0 commit comments