aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-08-25 18:59:00 +0100
committerGitHub <noreply@github.com>2020-08-25 18:59:00 +0100
commit55498c8deb262e564e1b79bf4409eb5593f3034e (patch)
treeb02e7f2cd5ee0508c43c0730bee7ea6d603dc1e3 /syncapi
parentc60270eea31f062f176b59e69e9d9e9e43b4b004 (diff)
Fix 'Invited user can reject invite over federation several times' (#1341)
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/storage/postgres/invites_table.go8
-rw-r--r--syncapi/storage/sqlite3/invites_table.go8
-rw-r--r--syncapi/storage/tables/interface.go3
3 files changed, 18 insertions, 1 deletions
diff --git a/syncapi/storage/postgres/invites_table.go b/syncapi/storage/postgres/invites_table.go
index 530dc645..eed58c15 100644
--- a/syncapi/storage/postgres/invites_table.go
+++ b/syncapi/storage/postgres/invites_table.go
@@ -139,6 +139,14 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
return nil, nil, err
}
+ // if we have seen this room before, it has a higher stream position and hence takes priority
+ // because the query is ORDER BY id DESC so drop them
+ _, isRetired := retired[roomID]
+ _, isInvited := result[roomID]
+ if isRetired || isInvited {
+ continue
+ }
+
var event gomatrixserverlib.HeaderedEvent
if err := json.Unmarshal(eventJSON, &event); err != nil {
return nil, nil, err
diff --git a/syncapi/storage/sqlite3/invites_table.go b/syncapi/storage/sqlite3/invites_table.go
index 45862efb..7da86683 100644
--- a/syncapi/storage/sqlite3/invites_table.go
+++ b/syncapi/storage/sqlite3/invites_table.go
@@ -150,6 +150,14 @@ func (s *inviteEventsStatements) SelectInviteEventsInRange(
return nil, nil, err
}
+ // if we have seen this room before, it has a higher stream position and hence takes priority
+ // because the query is ORDER BY id DESC so drop them
+ _, isRetired := retired[roomID]
+ _, isInvited := result[roomID]
+ if isRetired || isInvited {
+ continue
+ }
+
var event gomatrixserverlib.HeaderedEvent
if err := json.Unmarshal(eventJSON, &event); err != nil {
return nil, nil, err
diff --git a/syncapi/storage/tables/interface.go b/syncapi/storage/tables/interface.go
index 9d239d23..2ff229cb 100644
--- a/syncapi/storage/tables/interface.go
+++ b/syncapi/storage/tables/interface.go
@@ -33,7 +33,8 @@ type AccountData interface {
type Invites interface {
InsertInviteEvent(ctx context.Context, txn *sql.Tx, inviteEvent gomatrixserverlib.HeaderedEvent) (streamPos types.StreamPosition, err error)
DeleteInviteEvent(ctx context.Context, inviteEventID string) (types.StreamPosition, error)
- // SelectInviteEventsInRange returns a map of room ID to invite events.
+ // SelectInviteEventsInRange returns a map of room ID to invite events. If multiple invite/retired invites exist in the given range, return the latest value
+ // for the room.
SelectInviteEventsInRange(ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range) (invites map[string]gomatrixserverlib.HeaderedEvent, retired map[string]gomatrixserverlib.HeaderedEvent, err error)
SelectMaxInviteID(ctx context.Context, txn *sql.Tx) (id int64, err error)
}