@@ -58,6 +58,7 @@ afterEach(() => {
5858function fixture (
5959 options : {
6060 failRoster ?: boolean ;
61+ archivedChannel ?: boolean ;
6162 withDm ?: boolean ;
6263 withSenders ?: boolean ;
6364 holdProfiles ?: boolean ;
@@ -84,6 +85,8 @@ function fixture(
8485 let rosterGate : Promise < void > | undefined ;
8586 let rosterStarted = false ;
8687 let evidenceReads = 0 ;
88+ let unreadGate : Promise < void > | undefined ;
89+ let unreadStarted = false ;
8790 const historyRequests : string [ ] = [ ] ;
8891 const threadRequests : string [ ] = [ ] ;
8992 const exactRequests : string [ ] = [ ] ;
@@ -179,7 +182,10 @@ function fixture(
179182 [ "private" ] ,
180183 [ "about" , "Buzz session (buzz.sessions/v1)" ] ,
181184 ]
182- : [ [ "t" , "stream" ] ] ,
185+ : [
186+ [ "t" , "stream" ] ,
187+ ...( options . archivedChannel ? [ [ "archived" , "true" ] ] : [ ] ) ,
188+ ] ,
183189 ) ,
184190 profile ( alice , { name : "Alice" } ) ,
185191 ...roots ,
@@ -234,6 +240,15 @@ function fixture(
234240 viewer : viewer . pubkey ,
235241 relayAuthor : relayKey . pubkey ,
236242 query : async ( filters ) => {
243+ if (
244+ filters . some (
245+ ( filter ) =>
246+ filter . include_aux && ! ! filter [ "#h" ] && filter . kinds ?. includes ( 9 ) ,
247+ )
248+ ) {
249+ unreadStarted = true ;
250+ await unreadGate ;
251+ }
237252 if (
238253 filters . some ( ( filter ) => ! ! filter [ "#p" ] && filter . kinds ?. includes ( 9 ) )
239254 )
@@ -409,6 +424,18 @@ function fixture(
409424 readSteps,
410425 evidenceReads : ( ) => evidenceReads ,
411426 historyRequests,
427+ unreadStarted : ( ) => unreadStarted ,
428+ holdUnread ( ) {
429+ unreadStarted = false ;
430+ let release = ( ) => { } ;
431+ unreadGate = new Promise < void > ( ( resolve ) => {
432+ release = resolve ;
433+ } ) ;
434+ return ( ) => {
435+ unreadGate = undefined ;
436+ release ( ) ;
437+ } ;
438+ } ,
412439 holdAddressed ( ) {
413440 addressedGate = new Promise < void > ( ( resolve ) => {
414441 releaseAddressed = resolve ;
@@ -563,6 +590,14 @@ function fixture(
563590 events . push ( restored ) ;
564591 emit ( [ restored , mention , reply , ...roots ] ) ;
565592 } ,
593+ archiveRoom ( archived : boolean , time : number ) {
594+ const state = metadata ( relayKey , "room" , "Design" , time , [
595+ [ "t" , "stream" ] ,
596+ [ "archived" , String ( archived ) ] ,
597+ ] ) ;
598+ events . push ( state ) ;
599+ emit ( [ state ] ) ;
600+ } ,
566601 renameRoom ( ) {
567602 const renamed = metadata ( relayKey , "room" , "Renamed" , 99 , [
568603 [ "t" , "stream" ] ,
@@ -627,6 +662,184 @@ async function openRowMenu(
627662 }
628663 return screen . findByRole ( "menuitem" , { name : "Mark unread" } ) ;
629664}
665+ it ( "excludes archived-channel mentions and threads without hiding active DMs" , async ( ) => {
666+ const h = fixture ( { archivedChannel : true , withDm : true } ) ;
667+ render ( h . view ) ;
668+ await screen . findByText ( "A direct reply" ) ;
669+ await waitFor ( ( ) =>
670+ expect (
671+ screen . queryByText ( "Checking recent activity…" ) ,
672+ ) . not . toBeInTheDocument ( ) ,
673+ ) ;
674+ expect ( rows ( ) ) . toHaveLength ( 1 ) ;
675+ expect ( rows ( ) [ 0 ] ) . toHaveTextContent ( "A direct reply" ) ;
676+ await chooseFilter ( "Mentions" ) ;
677+ expect ( rows ( ) ) . toHaveLength ( 0 ) ;
678+ await chooseFilter ( "Threads" ) ;
679+ expect ( rows ( ) ) . toHaveLength ( 0 ) ;
680+ } ) ;
681+
682+ it . each ( [ "Please review" , "A thread update" ] ) (
683+ "closes selected Inbox detail on channel archive and restores unread intent on unarchive (%s)" ,
684+ async ( preview ) => {
685+ const h = fixture ( { withWriter : true } ) ;
686+ render ( h . view ) ;
687+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 2 ) ) ;
688+ const row = rows ( ) . find ( ( item ) => item . textContent ?. includes ( preview ) ) ;
689+ if ( ! row ) throw new Error ( "Missing fixture conversation" ) ;
690+ fireEvent . click ( within ( row ) . getByRole ( "button" , { name : / ^ O p e n / } ) ) ;
691+ const detail = screen . getByRole ( "region" , { name : "Inbox detail" } ) ;
692+ await within ( detail ) . findByText (
693+ preview === "Please review" ? / P l e a s e r e v i e w / : "A thread update" ,
694+ ) ;
695+ await waitFor ( ( ) =>
696+ expect (
697+ within ( row ) . queryByRole ( "img" , { name : "Unread" } ) ,
698+ ) . not . toBeInTheDocument ( ) ,
699+ ) ;
700+ fireEvent . contextMenu ( within ( row ) . getByRole ( "button" , { name : / ^ O p e n / } ) ) ;
701+ fireEvent . click (
702+ await screen . findByRole ( "menuitem" , { name : "Mark unread" } ) ,
703+ ) ;
704+ await waitFor ( ( ) =>
705+ expect (
706+ within ( row ) . getByRole ( "img" , { name : "Unread" } ) ,
707+ ) . toBeInTheDocument ( ) ,
708+ ) ;
709+ const journal = h . journal ( ) ;
710+ act ( ( ) => h . archiveRoom ( true , 100 ) ) ;
711+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 0 ) ) ;
712+ expect (
713+ screen . queryByRole ( "region" , { name : "Inbox detail" } ) ,
714+ ) . not . toBeInTheDocument ( ) ;
715+ expect (
716+ screen . getByRole ( "combobox" , { name : "Activity type" } ) ,
717+ ) . toHaveFocus ( ) ;
718+ expect ( h . journal ( ) ) . toEqual ( journal ) ;
719+ act ( ( ) => h . archiveRoom ( false , 101 ) ) ;
720+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 2 ) ) ;
721+ const restored = rows ( ) . find ( ( item ) => item . textContent ?. includes ( preview ) ) ;
722+ if ( ! restored ) throw new Error ( "Missing restored conversation" ) ;
723+ expect (
724+ within ( restored ) . getByRole ( "img" , { name : "Unread" } ) ,
725+ ) . toBeInTheDocument ( ) ;
726+ expect (
727+ screen . queryByRole ( "region" , { name : "Inbox detail" } ) ,
728+ ) . not . toBeInTheDocument ( ) ;
729+ expect ( h . journal ( ) ) . toEqual ( journal ) ;
730+ } ,
731+ ) ;
732+
733+ it . each ( [ false , true ] ) (
734+ "retires selected visits only on explicit archive during a held unread refresh (archive=%s)" ,
735+ async ( archive ) => {
736+ const h = fixture ( ) ;
737+ render ( h . view ) ;
738+ await screen . findByText ( "Please review this" ) ;
739+ await waitFor ( ( ) =>
740+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "ready" ) ,
741+ ) ;
742+ await chooseFilter ( "Mentions" ) ;
743+ fireEvent . click (
744+ screen . getByRole ( "button" , { name : "Open Alice in #Design" } ) ,
745+ ) ;
746+ await within (
747+ screen . getByRole ( "region" , { name : "Inbox detail" } ) ,
748+ ) . findByText ( / P l e a s e r e v i e w / ) ;
749+ await waitFor ( ( ) =>
750+ expect (
751+ screen . queryByRole ( "img" , { name : "Unread" } ) ,
752+ ) . not . toBeInTheDocument ( ) ,
753+ ) ;
754+ const journal = h . journal ( ) ;
755+ const release = h . holdUnread ( ) ;
756+ let refresh : Promise < void > | undefined ;
757+ try {
758+ act ( ( ) => {
759+ refresh = h . owner . session . unread . refresh ( ) ;
760+ } ) ;
761+ await waitFor ( ( ) => expect ( h . unreadStarted ( ) ) . toBe ( true ) ) ;
762+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "loading" ) ;
763+ expect (
764+ screen . getByRole ( "region" , { name : "Inbox detail" } ) ,
765+ ) . toBeInTheDocument ( ) ;
766+ if ( archive ) {
767+ act ( ( ) => h . archiveRoom ( true , 100 ) ) ;
768+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 0 ) ) ;
769+ expect (
770+ screen . queryByRole ( "region" , { name : "Inbox detail" } ) ,
771+ ) . not . toBeInTheDocument ( ) ;
772+ act ( ( ) => h . archiveRoom ( false , 101 ) ) ;
773+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 1 ) ) ;
774+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "loading" ) ;
775+ expect (
776+ screen . queryByRole ( "region" , { name : "Inbox detail" } ) ,
777+ ) . not . toBeInTheDocument ( ) ;
778+ expect (
779+ screen . getByRole ( "combobox" , { name : "Activity type" } ) ,
780+ ) . toHaveFocus ( ) ;
781+ expect ( h . journal ( ) ) . toEqual ( journal ) ;
782+ }
783+ } finally {
784+ await act ( async ( ) => {
785+ release ( ) ;
786+ await refresh ;
787+ } ) ;
788+ }
789+ await waitFor ( ( ) =>
790+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "ready" ) ,
791+ ) ;
792+ expect ( ! ! screen . queryByRole ( "region" , { name : "Inbox detail" } ) ) . toBe (
793+ ! archive ,
794+ ) ;
795+ expect ( h . journal ( ) ) . toEqual ( journal ) ;
796+ } ,
797+ ) ;
798+
799+ it ( "retires a failed captured read on archive during a held unread refresh" , async ( ) => {
800+ const h = fixture ( ) ;
801+ render ( h . view ) ;
802+ await screen . findByText ( "Please review this" ) ;
803+ await waitFor ( ( ) =>
804+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "ready" ) ,
805+ ) ;
806+ await chooseFilter ( "Mentions" ) ;
807+ h . failSave ( ) ;
808+ fireEvent . click (
809+ screen . getByRole ( "button" , { name : "Open Alice in #Design" } ) ,
810+ ) ;
811+ expect ( await screen . findByRole ( "alert" ) ) . toHaveTextContent ( "disk full" ) ;
812+ const release = h . holdUnread ( ) ;
813+ let refresh : Promise < void > | undefined ;
814+ try {
815+ act ( ( ) => {
816+ refresh = h . owner . session . unread . refresh ( ) ;
817+ } ) ;
818+ await waitFor ( ( ) => expect ( h . unreadStarted ( ) ) . toBe ( true ) ) ;
819+ act ( ( ) => h . archiveRoom ( true , 100 ) ) ;
820+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 0 ) ) ;
821+ act ( ( ) => h . archiveRoom ( false , 101 ) ) ;
822+ await waitFor ( ( ) => expect ( rows ( ) ) . toHaveLength ( 1 ) ) ;
823+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "loading" ) ;
824+ expect (
825+ screen . queryByRole ( "button" , { name : "Retry inbox" } ) ,
826+ ) . not . toBeInTheDocument ( ) ;
827+ } finally {
828+ await act ( async ( ) => {
829+ release ( ) ;
830+ await refresh ;
831+ } ) ;
832+ }
833+ await waitFor ( ( ) =>
834+ expect ( h . owner . session . unread . inbox ( ) . status ) . toBe ( "ready" ) ,
835+ ) ;
836+ expect (
837+ screen . queryByRole ( "region" , { name : "Inbox detail" } ) ,
838+ ) . not . toBeInTheDocument ( ) ;
839+ expect ( h . journal ( ) ?. state . frontiers [ `msg:${ h . mention . id } ` ] ) . toBeUndefined ( ) ;
840+ expect ( screen . getByRole ( "img" , { name : "Unread" } ) ) . toBeInTheDocument ( ) ;
841+ } ) ;
842+
630843it ( "filters real session evidence, opens an exact message and marks it read, and shares durable local unread" , async ( ) => {
631844 const h = fixture ( ) ;
632845 render ( h . view ) ;
0 commit comments