aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-04-27 12:03:34 +0100
committerGitHub <noreply@github.com>2022-04-27 12:03:34 +0100
commitdca4afd2f0871ed53109121dff17048e69cc4935 (patch)
tree2a911fdbddc2652b282fe45d622f8dc764b863d4 /syncapi
parent66b397b3c60c51bba36e4bce858733b2fda26f6a (diff)
Don't send account data or receipts for left/forgotten rooms (#2382)
* Only include account data and receipts for rooms in a complete sync that we care about * Fix global account data
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/streams/stream_accountdata.go6
-rw-r--r--syncapi/streams/stream_receipt.go6
-rw-r--r--syncapi/types/provider.go17
3 files changed, 29 insertions, 0 deletions
diff --git a/syncapi/streams/stream_accountdata.go b/syncapi/streams/stream_accountdata.go
index 99cd4a92..2cddbcf0 100644
--- a/syncapi/streams/stream_accountdata.go
+++ b/syncapi/streams/stream_accountdata.go
@@ -53,6 +53,12 @@ func (p *AccountDataStreamProvider) IncrementalSync(
// Iterate over the rooms
for roomID, dataTypes := range dataTypes {
+ // For a complete sync, make sure we're only including this room if
+ // that room was present in the joined rooms.
+ if from == 0 && roomID != "" && !req.IsRoomPresent(roomID) {
+ continue
+ }
+
// Request the missing data from the database
for _, dataType := range dataTypes {
dataReq := userapi.QueryAccountDataRequest{
diff --git a/syncapi/streams/stream_receipt.go b/syncapi/streams/stream_receipt.go
index 9d7d479a..f4e84c7d 100644
--- a/syncapi/streams/stream_receipt.go
+++ b/syncapi/streams/stream_receipt.go
@@ -62,6 +62,12 @@ func (p *ReceiptStreamProvider) IncrementalSync(
}
for roomID, receipts := range receiptsByRoom {
+ // For a complete sync, make sure we're only including this room if
+ // that room was present in the joined rooms.
+ if from == 0 && !req.IsRoomPresent(roomID) {
+ continue
+ }
+
jr := *types.NewJoinResponse()
if existing, ok := req.Response.Rooms.Join[roomID]; ok {
jr = existing
diff --git a/syncapi/types/provider.go b/syncapi/types/provider.go
index e6777f64..a9ea234d 100644
--- a/syncapi/types/provider.go
+++ b/syncapi/types/provider.go
@@ -25,6 +25,23 @@ type SyncRequest struct {
IgnoredUsers IgnoredUsers
}
+func (r *SyncRequest) IsRoomPresent(roomID string) bool {
+ membership, ok := r.Rooms[roomID]
+ if !ok {
+ return false
+ }
+ switch membership {
+ case gomatrixserverlib.Join:
+ return true
+ case gomatrixserverlib.Invite:
+ return true
+ case gomatrixserverlib.Peek:
+ return true
+ default:
+ return false
+ }
+}
+
type StreamProvider interface {
Setup()