@@ -741,29 +741,41 @@ func SyncInvitedTo(userID, roomID string) SyncCheckOpt {
741741 }
742742}
743743
744- // Check that `userID` gets joined to `roomID` by inspecting the join timeline for a membership event
745- func SyncJoinedTo (userID , roomID string ) SyncCheckOpt {
744+ // Check that `userID` gets joined to `roomID` by inspecting the join timeline for a membership event.
745+ //
746+ // Additional checks can be passed to narrow down the check, all must pass.
747+ func SyncJoinedTo (userID , roomID string , checks ... func (gjson.Result ) bool ) SyncCheckOpt {
746748 checkJoined := func (ev gjson.Result ) bool {
747- return ev .Get ("type" ).Str == "m.room.member" && ev .Get ("state_key" ).Str == userID && ev .Get ("content.membership" ).Str == "join"
749+ if ev .Get ("type" ).Str == "m.room.member" && ev .Get ("state_key" ).Str == userID && ev .Get ("content.membership" ).Str == "join" {
750+ for _ , check := range checks {
751+ if ! check (ev ) {
752+ // short-circuit, bail early
753+ return false
754+ }
755+ }
756+ // passed both basic join check and all other checks
757+ return true
758+ }
759+ return false
748760 }
749761 return func (clientUserID string , topLevelSyncJSON gjson.Result ) error {
750762 // Check both the timeline and the state events for the join event
751763 // since on initial sync, the state events may only be in
752764 // <room>.state.events.
753- err := loopArray (
765+ firstErr := loopArray (
754766 topLevelSyncJSON , "rooms.join." + GjsonEscape (roomID )+ ".timeline.events" , checkJoined ,
755767 )
756- if err == nil {
768+ if firstErr == nil {
757769 return nil
758770 }
759771
760- err = loopArray (
772+ secondErr : = loopArray (
761773 topLevelSyncJSON , "rooms.join." + GjsonEscape (roomID )+ ".state.events" , checkJoined ,
762774 )
763- if err == nil {
775+ if secondErr == nil {
764776 return nil
765777 }
766- return fmt .Errorf ("SyncJoinedTo(%s): %s" , roomID , err )
778+ return fmt .Errorf ("SyncJoinedTo(%s): %s & %s " , roomID , firstErr , secondErr )
767779 }
768780}
769781
0 commit comments