@@ -35,7 +35,7 @@ macro_rules! statestore_integration_tests {
35
35
use ruma:: {
36
36
api:: client:: media:: get_content_thumbnail:: v3:: Method ,
37
37
events:: room:: MediaSource ,
38
- mxc_uri, uint ,
38
+ mxc_uri,
39
39
} ;
40
40
41
41
use $crate:: media:: { MediaFormat , MediaRequest , MediaThumbnailSize } ;
@@ -150,7 +150,7 @@ macro_rules! statestore_integration_tests {
150
150
} ,
151
151
room_id,
152
152
serde:: Raw ,
153
- user_id, EventId , OwnedEventId , RoomId , UserId ,
153
+ uint , user_id, EventId , OwnedEventId , RoomId , UserId ,
154
154
} ;
155
155
use serde_json:: { json, Value as JsonValue } ;
156
156
@@ -596,11 +596,15 @@ macro_rules! statestore_integration_tests {
596
596
let first_event_id = event_id!( "$1435641916114394fHBLK:matrix.org" ) ;
597
597
let second_event_id = event_id!( "$fHBLK1435641916114394:matrix.org" ) ;
598
598
599
+ let first_receipt_ts = uint!( 1436451550 ) ;
600
+ let second_receipt_ts = uint!( 1436451653 ) ;
601
+ let third_receipt_ts = uint!( 1436474532 ) ;
602
+
599
603
let first_receipt_event = serde_json:: from_value( json!( {
600
604
first_event_id: {
601
605
"m.read" : {
602
606
user_id( ) : {
603
- "ts" : 1436451550453u64
607
+ "ts" : first_receipt_ts ,
604
608
}
605
609
}
606
610
}
@@ -611,7 +615,19 @@ macro_rules! statestore_integration_tests {
611
615
second_event_id: {
612
616
"m.read" : {
613
617
user_id( ) : {
614
- "ts" : 1436451551453u64
618
+ "ts" : second_receipt_ts,
619
+ }
620
+ }
621
+ }
622
+ } ) )
623
+ . expect( "json creation failed" ) ;
624
+
625
+ let third_receipt_event = serde_json:: from_value( json!( {
626
+ second_event_id: {
627
+ "m.read" : {
628
+ user_id( ) : {
629
+ "ts" : third_receipt_ts,
630
+ "thread_id" : "main" ,
615
631
}
616
632
}
617
633
}
@@ -626,7 +642,7 @@ macro_rules! statestore_integration_tests {
626
642
user_id( )
627
643
)
628
644
. await
629
- . expect( "failed to read user room receipt" )
645
+ . expect( "failed to read unthreaded user room receipt" )
630
646
. is_none( ) ) ;
631
647
assert!( store
632
648
. get_event_room_receipt_events(
@@ -636,7 +652,7 @@ macro_rules! statestore_integration_tests {
636
652
& first_event_id
637
653
)
638
654
. await
639
- . expect( "failed to read user room receipt for 1" )
655
+ . expect( "failed to read unthreaded event room receipt for 1" )
640
656
. is_empty( ) ) ;
641
657
assert!( store
642
658
. get_event_room_receipt_events(
@@ -646,37 +662,41 @@ macro_rules! statestore_integration_tests {
646
662
& second_event_id
647
663
)
648
664
. await
649
- . expect( "failed to read user room receipt for 2" )
665
+ . expect( "failed to read unthreaded event room receipt for 2" )
650
666
. is_empty( ) ) ;
651
667
652
668
let mut changes = StateChanges :: default ( ) ;
653
669
changes. add_receipts( room_id, first_receipt_event) ;
654
670
655
671
store. save_changes( & changes) . await . expect( "writing changes fauked" ) ;
656
- assert! ( store
672
+ let ( unthreaded_user_receipt_event_id , unthreaded_user_receipt ) = store
657
673
. get_user_room_receipt_event(
658
674
room_id,
659
675
ReceiptType :: Read ,
660
676
ReceiptThread :: Unthreaded ,
661
677
user_id( )
662
678
)
663
679
. await
664
- . expect( "failed to read user room receipt after save" )
665
- . is_some( ) ) ;
680
+ . expect( "failed to read unthreaded user room receipt after save" )
681
+ . unwrap( ) ;
682
+ assert_eq!( unthreaded_user_receipt_event_id, first_event_id) ;
683
+ assert_eq!( unthreaded_user_receipt. ts. unwrap( ) . 0 , first_receipt_ts) ;
684
+ let first_event_unthreaded_receipts = store
685
+ . get_event_room_receipt_events(
686
+ room_id,
687
+ ReceiptType :: Read ,
688
+ ReceiptThread :: Unthreaded ,
689
+ & first_event_id
690
+ )
691
+ . await
692
+ . expect( "failed to read unthreaded event room receipt for 1 after save" ) ;
666
693
assert_eq!(
667
- store
668
- . get_event_room_receipt_events(
669
- room_id,
670
- ReceiptType :: Read ,
671
- ReceiptThread :: Unthreaded ,
672
- & first_event_id
673
- )
674
- . await
675
- . expect( "failed to read user room receipt for 1 after save" )
676
- . len( ) ,
694
+ first_event_unthreaded_receipts. len( ) ,
677
695
1 ,
678
- "Found a wrong number of receipts for 1 after save"
696
+ "Found a wrong number of unthreaded receipts for 1 after save"
679
697
) ;
698
+ assert_eq!( first_event_unthreaded_receipts[ 0 ] . 0 , user_id( ) ) ;
699
+ assert_eq!( first_event_unthreaded_receipts[ 0 ] . 1 . ts. unwrap( ) . 0 , first_receipt_ts) ;
680
700
assert!( store
681
701
. get_event_room_receipt_events(
682
702
room_id,
@@ -685,23 +705,25 @@ macro_rules! statestore_integration_tests {
685
705
& second_event_id
686
706
)
687
707
. await
688
- . expect( "failed to read user room receipt for 2 after save" )
708
+ . expect( "failed to read unthreaded event room receipt for 2 after save" )
689
709
. is_empty( ) ) ;
690
710
691
711
let mut changes = StateChanges :: default ( ) ;
692
712
changes. add_receipts( room_id, second_receipt_event) ;
693
713
694
714
store. save_changes( & changes) . await . expect( "Saving works" ) ;
695
- assert! ( store
715
+ let ( unthreaded_user_receipt_event_id , unthreaded_user_receipt ) = store
696
716
. get_user_room_receipt_event(
697
717
room_id,
698
718
ReceiptType :: Read ,
699
719
ReceiptThread :: Unthreaded ,
700
720
user_id( )
701
721
)
702
722
. await
703
- . expect( "Getting user room receipts failed" )
704
- . is_some( ) ) ;
723
+ . expect( "Getting unthreaded user room receipt after save failed" )
724
+ . unwrap( ) ;
725
+ assert_eq!( unthreaded_user_receipt_event_id, second_event_id) ;
726
+ assert_eq!( unthreaded_user_receipt. ts. unwrap( ) . 0 , second_receipt_ts) ;
705
727
assert!( store
706
728
. get_event_room_receipt_events(
707
729
room_id,
@@ -710,22 +732,108 @@ macro_rules! statestore_integration_tests {
710
732
& first_event_id
711
733
)
712
734
. await
713
- . expect( "Getting event room receipt events for first event failed" )
735
+ . expect( "Getting unthreaded event room receipt events for first event failed" )
714
736
. is_empty( ) ) ;
737
+ let second_event_unthreaded_receipts = store
738
+ . get_event_room_receipt_events(
739
+ room_id,
740
+ ReceiptType :: Read ,
741
+ ReceiptThread :: Unthreaded ,
742
+ & second_event_id
743
+ )
744
+ . await
745
+ . expect( "Getting unthreaded event room receipt events for second event failed" ) ;
715
746
assert_eq!(
716
- store
717
- . get_event_room_receipt_events(
718
- room_id,
719
- ReceiptType :: Read ,
720
- ReceiptThread :: Unthreaded ,
721
- & second_event_id
722
- )
723
- . await
724
- . expect( "Getting event room receipt events for second event failed" )
725
- . len( ) ,
747
+ second_event_unthreaded_receipts. len( ) ,
748
+ 1 ,
749
+ "Found a wrong number of unthreaded receipts for second event after save"
750
+ ) ;
751
+ assert_eq!( second_event_unthreaded_receipts[ 0 ] . 0 , user_id( ) ) ;
752
+ assert_eq!( second_event_unthreaded_receipts[ 0 ] . 1 . ts. unwrap( ) . 0 , second_receipt_ts) ;
753
+
754
+ assert!( store
755
+ . get_user_room_receipt_event(
756
+ room_id,
757
+ ReceiptType :: Read ,
758
+ ReceiptThread :: Main ,
759
+ user_id( )
760
+ )
761
+ . await
762
+ . expect( "failed to read threaded user room receipt" )
763
+ . is_none( ) ) ;
764
+ assert!( store
765
+ . get_event_room_receipt_events(
766
+ room_id,
767
+ ReceiptType :: Read ,
768
+ ReceiptThread :: Main ,
769
+ & second_event_id
770
+ )
771
+ . await
772
+ . expect( "Getting threaded event room receipts for 2 failed" )
773
+ . is_empty( ) ) ;
774
+
775
+ let mut changes = StateChanges :: default ( ) ;
776
+ changes. add_receipts( room_id, third_receipt_event) ;
777
+
778
+ store. save_changes( & changes) . await . expect( "Saving works" ) ;
779
+ // Unthreaded receipts should not have changed.
780
+ let ( unthreaded_user_receipt_event_id, unthreaded_user_receipt) = store
781
+ . get_user_room_receipt_event(
782
+ room_id,
783
+ ReceiptType :: Read ,
784
+ ReceiptThread :: Unthreaded ,
785
+ user_id( )
786
+ )
787
+ . await
788
+ . expect( "Getting unthreaded user room receipt after save failed" )
789
+ . unwrap( ) ;
790
+ assert_eq!( unthreaded_user_receipt_event_id, second_event_id) ;
791
+ assert_eq!( unthreaded_user_receipt. ts. unwrap( ) . 0 , second_receipt_ts) ;
792
+ let second_event_unthreaded_receipts = store
793
+ . get_event_room_receipt_events(
794
+ room_id,
795
+ ReceiptType :: Read ,
796
+ ReceiptThread :: Unthreaded ,
797
+ & second_event_id
798
+ )
799
+ . await
800
+ . expect( "Getting unthreaded event room receipt events for second event failed" ) ;
801
+ assert_eq!(
802
+ second_event_unthreaded_receipts. len( ) ,
803
+ 1 ,
804
+ "Found a wrong number of unthreaded receipts for second event after save"
805
+ ) ;
806
+ assert_eq!( second_event_unthreaded_receipts[ 0 ] . 0 , user_id( ) ) ;
807
+ assert_eq!( second_event_unthreaded_receipts[ 0 ] . 1 . ts. unwrap( ) . 0 , second_receipt_ts) ;
808
+ // Threaded receipts should have changed
809
+ let ( threaded_user_receipt_event_id, threaded_user_receipt) = store
810
+ . get_user_room_receipt_event(
811
+ room_id,
812
+ ReceiptType :: Read ,
813
+ ReceiptThread :: Main ,
814
+ user_id( )
815
+ )
816
+ . await
817
+ . expect( "Getting threaded user room receipt after save failed" )
818
+ . unwrap( ) ;
819
+ assert_eq!( threaded_user_receipt_event_id, second_event_id) ;
820
+ assert_eq!( threaded_user_receipt. ts. unwrap( ) . 0 , third_receipt_ts) ;
821
+ let second_event_threaded_receipts = store
822
+ . get_event_room_receipt_events(
823
+ room_id,
824
+ ReceiptType :: Read ,
825
+ ReceiptThread :: Main ,
826
+ & second_event_id
827
+ )
828
+ . await
829
+ . expect( "Getting threaded event room receipt events for second event failed" ) ;
830
+ assert_eq!(
831
+ second_event_threaded_receipts. len( ) ,
726
832
1 ,
727
- "Found a wrong number of receipts for second event after save"
833
+ "Found a wrong number of threaded receipts for second event after save"
728
834
) ;
835
+ assert_eq!( second_event_threaded_receipts[ 0 ] . 0 , user_id( ) ) ;
836
+ assert_eq!( second_event_threaded_receipts[ 0 ] . 1 . ts. unwrap( ) . 0 , third_receipt_ts) ;
729
837
}
730
838
731
839
#[ async_test]
0 commit comments