@@ -645,3 +645,224 @@ async fn the_threads_view_lists_follows_newest_arrival_first() {
645645 . threads
646646 . is_empty( ) ) ;
647647}
648+
649+ /// Put every one of the actor's follows past the default window.
650+ async fn go_dormant ( pool : & PgPool , community : CommunityId , actor : & Keys ) {
651+ sqlx:: query (
652+ "UPDATE personal_read_frontiers SET active_at=now()-interval '31 days'
653+ WHERE community_id=$1 AND actor=$2" ,
654+ )
655+ . bind ( community. as_uuid ( ) )
656+ . bind ( actor. public_key ( ) . to_bytes ( ) . as_slice ( ) )
657+ . execute ( pool)
658+ . await
659+ . unwrap ( ) ;
660+ }
661+
662+ /// Roots of the threads listed for the actor, by the sidebar and by the
663+ /// threads view.
664+ async fn listed ( db : & Db , community : CommunityId , channel : Uuid , actor : & Keys ) -> [ Vec < String > ; 2 ] {
665+ let sidebar = row ( db, community, channel, actor)
666+ . await
667+ . threads
668+ . into_iter ( )
669+ . map ( |t| t. root_id )
670+ . collect ( ) ;
671+ let view = threads_page ( db, community, actor, MAX_THREADS , None )
672+ . await
673+ . threads
674+ . into_iter ( )
675+ . map ( |t| t. thread . root_id )
676+ . collect ( ) ;
677+ [ sidebar, view]
678+ }
679+
680+ #[ tokio:: test]
681+ #[ ignore = "requires Postgres" ]
682+ async fn a_dormant_follow_is_hidden_until_a_mention_or_post_revives_it ( ) {
683+ let ( db, pool, community, channel, actor, root) = fixture ( ) . await ;
684+ let id = root. id . to_hex ( ) ;
685+ let own = reply ( & db, community, channel, & root, & actor, vec ! [ ] ) . await ;
686+ reply ( & db, community, channel, & root, & Keys :: generate ( ) , vec ! [ ] ) . await ;
687+ assert_eq ! (
688+ listed( & db, community, channel, & actor) . await ,
689+ [ vec![ id. clone( ) ] , vec![ id. clone( ) ] ]
690+ ) ;
691+
692+ go_dormant ( & pool, community, & actor) . await ;
693+ // A reply that does not involve the actor leaves it dormant; the row and
694+ // its position stay.
695+ reply ( & db, community, channel, & root, & Keys :: generate ( ) , vec ! [ ] ) . await ;
696+ assert_eq ! (
697+ listed( & db, community, channel, & actor) . await ,
698+ [ Vec :: <String >:: new( ) , vec![ ] ]
699+ ) ;
700+ assert_eq ! (
701+ follow( & pool, community, & actor, & root) . await ,
702+ Some ( Some ( own. id. to_hex( ) ) )
703+ ) ;
704+
705+ // A mention revives it at its old position.
706+ reply (
707+ & db,
708+ community,
709+ channel,
710+ & root,
711+ & Keys :: generate ( ) ,
712+ mention ( & actor) ,
713+ )
714+ . await ;
715+ let summary = row ( & db, community, channel, & actor) . await ;
716+ assert_eq ! ( threads( & summary) , [ ( id. clone( ) , 1 ) ] ) ;
717+ assert_eq ! ( summary. threads[ 0 ] . read_through_id, Some ( own. id. to_hex( ) ) ) ;
718+
719+ // So does posting, which reads through the post.
720+ go_dormant ( & pool, community, & actor) . await ;
721+ assert ! ( row( & db, community, channel, & actor)
722+ . await
723+ . threads
724+ . is_empty( ) ) ;
725+ let again = reply ( & db, community, channel, & root, & actor, vec ! [ ] ) . await ;
726+ reply ( & db, community, channel, & root, & Keys :: generate ( ) , vec ! [ ] ) . await ;
727+ let summary = row ( & db, community, channel, & actor) . await ;
728+ assert_eq ! ( threads( & summary) , [ ( id. clone( ) , 0 ) ] ) ;
729+ assert_eq ! ( summary. threads[ 0 ] . read_through_id, Some ( again. id. to_hex( ) ) ) ;
730+
731+ // And reading it.
732+ go_dormant ( & pool, community, & actor) . await ;
733+ let last = reply ( & db, community, channel, & root, & Keys :: generate ( ) , vec ! [ ] ) . await ;
734+ assert ! ( row( & db, community, channel, & actor)
735+ . await
736+ . threads
737+ . is_empty( ) ) ;
738+ assert_eq ! (
739+ intent(
740+ & db,
741+ community,
742+ & actor,
743+ mark_thread( channel, & root, & last. id. to_hex( ) )
744+ )
745+ . await ,
746+ IntentOutcome :: Applied
747+ ) ;
748+ reply ( & db, community, channel, & root, & Keys :: generate ( ) , vec ! [ ] ) . await ;
749+ assert_eq ! (
750+ listed( & db, community, channel, & actor) . await ,
751+ [ vec![ id. clone( ) ] , vec![ id] ]
752+ ) ;
753+ }
754+
755+ #[ tokio:: test]
756+ #[ ignore = "requires Postgres" ]
757+ async fn an_explicit_follow_never_goes_dormant ( ) {
758+ let ( db, pool, community, channel, actor, _) = fixture ( ) . await ;
759+ // One thread followed only by intent, one followed implicitly first.
760+ let chosen = post ( & db, community, channel, & Keys :: generate ( ) , vec ! [ ] ) . await ;
761+ let joined = post ( & db, community, channel, & Keys :: generate ( ) , vec ! [ ] ) . await ;
762+ reply ( & db, community, channel, & joined, & actor, vec ! [ ] ) . await ;
763+ for root in [ & chosen, & joined] {
764+ assert_eq ! (
765+ intent(
766+ & db,
767+ community,
768+ & actor,
769+ follow_intent( channel, Some ( root) , true )
770+ )
771+ . await ,
772+ IntentOutcome :: Applied
773+ ) ;
774+ }
775+ let implicit = post ( & db, community, channel, & Keys :: generate ( ) , vec ! [ ] ) . await ;
776+ reply ( & db, community, channel, & implicit, & actor, vec ! [ ] ) . await ;
777+ for root in [ & chosen, & joined, & implicit] {
778+ reply ( & db, community, channel, root, & Keys :: generate ( ) , vec ! [ ] ) . await ;
779+ }
780+ go_dormant ( & pool, community, & actor) . await ;
781+ let mut explicit = vec ! [ chosen. id. to_hex( ) , joined. id. to_hex( ) ] ;
782+ explicit. sort ( ) ;
783+ let [ mut sidebar, mut view] = listed ( & db, community, channel, & actor) . await ;
784+ sidebar. sort ( ) ;
785+ view. sort ( ) ;
786+ assert_eq ! ( [ sidebar, view] , [ explicit. clone( ) , explicit] ) ;
787+
788+ // Unfollowing ends it; a later mention re-follows it implicitly, so it
789+ // can go dormant again.
790+ intent (
791+ & db,
792+ community,
793+ & actor,
794+ follow_intent ( channel, Some ( & chosen) , false ) ,
795+ )
796+ . await ;
797+ reply (
798+ & db,
799+ community,
800+ channel,
801+ & chosen,
802+ & Keys :: generate ( ) ,
803+ mention ( & actor) ,
804+ )
805+ . await ;
806+ assert_eq ! (
807+ threads( & row( & db, community, channel, & actor) . await ) . len( ) ,
808+ 2
809+ ) ;
810+ go_dormant ( & pool, community, & actor) . await ;
811+ assert_eq ! (
812+ listed( & db, community, channel, & actor) . await ,
813+ [ vec![ joined. id. to_hex( ) ] , vec![ joined. id. to_hex( ) ] ]
814+ ) ;
815+ }
816+
817+ #[ tokio:: test]
818+ #[ ignore = "requires Postgres" ]
819+ async fn an_agent_keeps_no_read_state ( ) {
820+ let ( db, pool, community, channel, actor, _) = fixture ( ) . await ;
821+ let agent = member ( & db, & pool, community, channel) . await ;
822+ sqlx:: query ( "DELETE FROM personal_read_accounts WHERE community_id=$1 AND actor=$2" )
823+ . bind ( community. as_uuid ( ) )
824+ . bind ( agent. public_key ( ) . to_bytes ( ) . as_slice ( ) )
825+ . execute ( & pool)
826+ . await
827+ . unwrap ( ) ;
828+ for ( who, owner) in [ ( & actor, None ) , ( & agent, Some ( & actor) ) ] {
829+ sqlx:: query (
830+ "INSERT INTO users (community_id, pubkey, agent_owner_pubkey) VALUES ($1,$2,$3)" ,
831+ )
832+ . bind ( community. as_uuid ( ) )
833+ . bind ( who. public_key ( ) . to_bytes ( ) . as_slice ( ) )
834+ . bind ( owner. map ( |o| o. public_key ( ) . to_bytes ( ) . to_vec ( ) ) )
835+ . execute ( & pool)
836+ . await
837+ . unwrap ( ) ;
838+ }
839+ // The agent posts, replies to its owner's root, is mentioned, and has a
840+ // root replied to: every way a person would gain a position or a follow.
841+ let own_root = post ( & db, community, channel, & agent, mention ( & actor) ) . await ;
842+ reply ( & db, community, channel, & own_root, & actor, mention ( & agent) ) . await ;
843+ let owner_root = post ( & db, community, channel, & actor, mention ( & agent) ) . await ;
844+ reply (
845+ & db,
846+ community,
847+ channel,
848+ & owner_root,
849+ & agent,
850+ mention ( & actor) ,
851+ )
852+ . await ;
853+ let rows: i64 = sqlx:: query_scalar (
854+ "SELECT (SELECT count(*) FROM personal_read_frontiers WHERE community_id=$1 AND actor=$2)
855+ + (SELECT count(*) FROM personal_read_accounts WHERE community_id=$1 AND actor=$2)" ,
856+ )
857+ . bind ( community. as_uuid ( ) )
858+ . bind ( agent. public_key ( ) . to_bytes ( ) . as_slice ( ) )
859+ . fetch_one ( & pool)
860+ . await
861+ . unwrap ( ) ;
862+ assert_eq ! ( rows, 0 , "an agent has no positions, follows or account" ) ;
863+ // The agent's messages still involve its owner.
864+ assert ! ( follow( & pool, community, & actor, & own_root) . await . is_some( ) ) ;
865+ assert ! ( follow( & pool, community, & actor, & owner_root)
866+ . await
867+ . is_some( ) ) ;
868+ }
0 commit comments