mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
bugfix: distinguish between a 0 invited_count and a missing invited_count
This commit is contained in:
parent
150821f61e
commit
f22ef91da6
@ -571,7 +571,7 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
|
||||
Initial: true,
|
||||
IsDM: userRoomData.IsDM,
|
||||
JoinedCount: metadata.JoinCount,
|
||||
InvitedCount: metadata.InviteCount,
|
||||
InvitedCount: &metadata.InviteCount,
|
||||
PrevBatch: userRoomData.RequestedPrevBatch,
|
||||
}
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func (s *connStateLive) processLiveUpdate(ctx context.Context, up caches.Update,
|
||||
thisRoom.Name = internal.CalculateRoomName(metadata, 5) // TODO: customisable?
|
||||
}
|
||||
if delta.InviteCountChanged {
|
||||
thisRoom.InvitedCount = roomUpdate.GlobalRoomMetadata().InviteCount
|
||||
thisRoom.InvitedCount = &roomUpdate.GlobalRoomMetadata().InviteCount
|
||||
}
|
||||
if delta.JoinCountChanged {
|
||||
thisRoom.JoinedCount = roomUpdate.GlobalRoomMetadata().JoinCount
|
||||
|
@ -2,6 +2,7 @@ package sync3
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/matrix-org/sliding-sync/internal"
|
||||
|
||||
"github.com/matrix-org/sliding-sync/sync3/caches"
|
||||
@ -17,7 +18,7 @@ type Room struct {
|
||||
Initial bool `json:"initial,omitempty"`
|
||||
IsDM bool `json:"is_dm,omitempty"`
|
||||
JoinedCount int `json:"joined_count,omitempty"`
|
||||
InvitedCount int `json:"invited_count,omitempty"`
|
||||
InvitedCount *int `json:"invited_count,omitempty"`
|
||||
PrevBatch string `json:"prev_batch,omitempty"`
|
||||
NumLive int `json:"num_live,omitempty"`
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ func MatchRoomInviteState(events []Event, partial bool) m.RoomMatcher {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("MatchRoomInviteState: want event %+v but it does not exist", want)
|
||||
return fmt.Errorf("MatchRoomInviteState: want event %+v but it does not exist or failed to pass equality checks", want)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -64,7 +64,22 @@ func TestRoomStateTransitions(t *testing.T) {
|
||||
m.MatchRoomHighlightCount(1),
|
||||
m.MatchRoomInitial(true),
|
||||
m.MatchRoomRequiredState(nil),
|
||||
// TODO m.MatchRoomInviteState(inviteStrippedState.InviteState.Events),
|
||||
m.MatchInviteCount(1),
|
||||
m.MatchJoinCount(1),
|
||||
MatchRoomInviteState([]Event{
|
||||
{
|
||||
Type: "m.room.create",
|
||||
StateKey: ptr(""),
|
||||
// no content as it includes the room version which we don't want to guess/hardcode
|
||||
},
|
||||
{
|
||||
Type: "m.room.join_rules",
|
||||
StateKey: ptr(""),
|
||||
Content: map[string]interface{}{
|
||||
"join_rule": "public",
|
||||
},
|
||||
},
|
||||
}, true),
|
||||
},
|
||||
joinRoomID: {},
|
||||
}),
|
||||
@ -105,6 +120,8 @@ func TestRoomStateTransitions(t *testing.T) {
|
||||
},
|
||||
}),
|
||||
m.MatchRoomInitial(true),
|
||||
m.MatchJoinCount(2),
|
||||
m.MatchInviteCount(0),
|
||||
m.MatchRoomHighlightCount(0),
|
||||
))
|
||||
}
|
||||
@ -467,7 +484,7 @@ func TestMemberCounts(t *testing.T) {
|
||||
m.MatchResponse(t, res, m.MatchRoomSubscriptionsStrict(map[string][]m.RoomMatcher{
|
||||
secondRoomID: {
|
||||
m.MatchRoomInitial(false),
|
||||
m.MatchInviteCount(0),
|
||||
m.MatchNoInviteCount(),
|
||||
m.MatchJoinCount(0), // omitempty
|
||||
},
|
||||
}))
|
||||
@ -486,7 +503,7 @@ func TestMemberCounts(t *testing.T) {
|
||||
m.MatchResponse(t, res, m.MatchRoomSubscriptionsStrict(map[string][]m.RoomMatcher{
|
||||
secondRoomID: {
|
||||
m.MatchRoomInitial(false),
|
||||
m.MatchInviteCount(0),
|
||||
m.MatchNoInviteCount(),
|
||||
m.MatchJoinCount(2),
|
||||
},
|
||||
}))
|
||||
|
@ -48,10 +48,22 @@ func MatchJoinCount(count int) RoomMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
func MatchNoInviteCount() RoomMatcher {
|
||||
return func(r sync3.Room) error {
|
||||
if r.InvitedCount != nil {
|
||||
return fmt.Errorf("MatchInviteCount: invited_count is present when it should be missing: val=%v", *r.InvitedCount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func MatchInviteCount(count int) RoomMatcher {
|
||||
return func(r sync3.Room) error {
|
||||
if r.InvitedCount != count {
|
||||
return fmt.Errorf("MatchInviteCount: got %v want %v", r.InvitedCount, count)
|
||||
if r.InvitedCount == nil {
|
||||
return fmt.Errorf("MatchInviteCount: invited_count is missing")
|
||||
}
|
||||
if *r.InvitedCount != count {
|
||||
return fmt.Errorf("MatchInviteCount: got %v want %v", *r.InvitedCount, count)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user