@@ -99,6 +99,7 @@ interface LastRead {
9999 readonly watches : ReadonlySet < string > ;
100100 readonly status : string | null ;
101101 readonly remarks : string | null ;
102+ readonly foreignRemarkAt : number | null ;
102103 readonly detail : PullRequestDetail ;
103104}
104105
@@ -186,6 +187,24 @@ function planRead(
186187 } ;
187188}
188189
190+ const viewerAuthored = ( detail : PullRequestDetail ) =>
191+ detail . viewer !== undefined && detail . viewer . toLowerCase ( ) === detail . author ?. login . toLowerCase ( ) ;
192+
193+ const newestForeignRemark = (
194+ detail : PullRequestDetail ,
195+ fingerprint : ProviderChangeRequestWatchFingerprint | null ,
196+ remarks : ReadonlyArray < PullRequestComment > ,
197+ ) => {
198+ if ( fingerprint ?. viewerSubscription !== "SUBSCRIBED" || ! viewerAuthored ( detail ) ) return null ;
199+ const viewer = detail . viewer ! . toLowerCase ( ) ;
200+ const times = remarks . flatMap ( ( remark ) =>
201+ remark . author === null || remark . author . login . toLowerCase ( ) === viewer
202+ ? [ ]
203+ : [ Date . parse ( remark . createdAt ) ] ,
204+ ) ;
205+ return times . length === 0 ? null : Math . max ( ...times ) ;
206+ } ;
207+
189208const notificationsCanGate = ( last : LastRead , now : number ) =>
190209 now - last . checkedAt >= FINGERPRINT_REREAD_MS &&
191210 now - Math . min ( last . at , last . detailAt ) < NOTIFIED_REREAD_CEILING_MS ;
@@ -202,8 +221,7 @@ const gatesReread = (
202221 last . remarks === fingerprint . remarks &&
203222 last . remarksComplete &&
204223 notificationsCanGate ( last , now ) &&
205- last . detail . viewer !== undefined &&
206- last . detail . viewer . toLowerCase ( ) === last . detail . author ?. login . toLowerCase ( ) ;
224+ viewerAuthored ( last . detail ) ;
207225
208226function watchesEqual ( left : ThreadPullRequestWatch , right : ThreadPullRequestWatch ) : boolean {
209227 return (
@@ -606,6 +624,9 @@ export const make = Effect.gen(function* () {
606624 watches : new Set ( group . targets . map ( watchKey ) ) ,
607625 status : fingerprint ?. status ?? null ,
608626 remarks : fingerprint ?. remarks ?? null ,
627+ foreignRemarkAt : Option . isSome ( activity )
628+ ? newestForeignRemark ( detail , fingerprint , remarks ?? activity . value . comments )
629+ : ( last ?. foreignRemarkAt ?? null ) ,
609630 detail,
610631 } ) ;
611632 yield * eachTarget ( group , ( target ) => {
@@ -633,6 +654,7 @@ export const make = Effect.gen(function* () {
633654 } ) ;
634655
635656 const notificationsUnreadableAt = new Map < string , number > ( ) ;
657+ const notificationsLiveThrough = new Map < string , number > ( ) ;
636658
637659 const repositoryOf = ( group : WatchGroup ) => {
638660 const { projectId, host, repository } = referenceOf ( group ) ;
@@ -644,7 +666,10 @@ export const make = Effect.gen(function* () {
644666 groups : ReadonlyArray < WatchGroup > ,
645667 ) {
646668 const now = yield * Clock . currentTimeMillis ;
647- const due = new Map < string , { readonly group : WatchGroup ; readonly since : number } > ( ) ;
669+ const due = new Map <
670+ string ,
671+ { readonly group : WatchGroup ; readonly since : number ; readonly evidence : number }
672+ > ( ) ;
648673 for ( const group of groups ) {
649674 const last = lastReads . get ( group . key ) ;
650675 const repository = repositoryOf ( group ) ;
@@ -655,21 +680,40 @@ export const make = Effect.gen(function* () {
655680 ) {
656681 continue ;
657682 }
658- const since = Math . min ( due . get ( repository ) ?. since ?? last . at , last . at ) ;
659- due . set ( repository , { group : due . get ( repository ) ?. group ?? group , since } ) ;
683+ const prior = due . get ( repository ) ;
684+ due . set ( repository , {
685+ group : prior ?. group ?? group ,
686+ since : Math . min ( prior ?. since ?? last . at , last . at ) ,
687+ evidence : Math . max ( prior ?. evidence ?? - Infinity , last . foreignRemarkAt ?? - Infinity ) ,
688+ } ) ;
660689 }
661690 const checks = new Map <
662691 string ,
663692 Effect . Effect < ProviderChangeRequestNotifications | null | undefined >
664693 > ( ) ;
665- for ( const [ repository , { group, since } ] of due ) {
694+ for ( const [ repository , { group, since, evidence } ] of due ) {
695+ // With "On GitHub" notifications off the inbox never moves, so its silence counts only
696+ // once it has shown a remark someone else made on the viewer's own pull request.
697+ const unproven = evidence > ( notificationsLiveThrough . get ( repository ) ?? - Infinity ) ;
666698 const check = pullRequests
667- . notifications ( { ...referenceOf ( group ) , since : since - NOTIFICATION_LAG_MS } )
699+ . notifications ( {
700+ ...referenceOf ( group ) ,
701+ since : ( unproven ? Math . min ( since , evidence ) : since ) - NOTIFICATION_LAG_MS ,
702+ } )
668703 . pipe (
704+ Effect . map ( ( notifications ) =>
705+ unproven && notifications ?. threads . length === 0 && ! notifications . truncated
706+ ? null
707+ : notifications ,
708+ ) ,
669709 Effect . tap ( ( notifications ) =>
670710 Effect . sync ( ( ) => {
671- if ( notifications === null ) notificationsUnreadableAt . set ( repository , now ) ;
672- else notificationsUnreadableAt . delete ( repository ) ;
711+ if ( notifications === null ) {
712+ notificationsUnreadableAt . set ( repository , now ) ;
713+ return ;
714+ }
715+ notificationsUnreadableAt . delete ( repository ) ;
716+ if ( unproven ) notificationsLiveThrough . set ( repository , evidence ) ;
673717 } ) ,
674718 ) ,
675719 Effect . catchCause ( ( cause ) =>
0 commit comments