mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Don't query changed devices if device list isn't tracked
This commit is contained in:
parent
bef0c221af
commit
5b40077033
4 changed files with 24 additions and 3 deletions
|
|
@ -23,12 +23,18 @@ var (
|
|||
InvalidKeySignature = errors.New("invalid signature on device keys")
|
||||
)
|
||||
|
||||
func (mach *OlmMachine) fetchKeys(users []id.UserID, sinceToken string) (data map[id.UserID]map[id.DeviceID]*DeviceIdentity) {
|
||||
func (mach *OlmMachine) fetchKeys(users []id.UserID, sinceToken string, includeUntracked bool) (data map[id.UserID]map[id.DeviceID]*DeviceIdentity) {
|
||||
req := &mautrix.ReqQueryKeys{
|
||||
DeviceKeys: mautrix.DeviceKeysRequest{},
|
||||
Timeout: 10 * 1000,
|
||||
Token: sinceToken,
|
||||
}
|
||||
if !includeUntracked {
|
||||
users = mach.CryptoStore.FilterTrackedUsers(users)
|
||||
}
|
||||
if len(users) == 0 {
|
||||
return
|
||||
}
|
||||
for _, userID := range users {
|
||||
req.DeviceKeys[userID] = mautrix.DeviceIDList{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ func (mach *OlmMachine) ShareGroupSession(roomID id.RoomID, users []id.UserID) e
|
|||
|
||||
if len(fetchKeys) > 0 {
|
||||
mach.Log.Trace("Fetching missing keys for %v", fetchKeys)
|
||||
for userID, devices := range mach.fetchKeys(fetchKeys, "") {
|
||||
for userID, devices := range mach.fetchKeys(fetchKeys, "", true) {
|
||||
mach.Log.Trace("Got %d device keys for %s", len(devices), userID)
|
||||
missingSessions[userID] = devices
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ func (mach *OlmMachine) FlushStore() error {
|
|||
func (mach *OlmMachine) ProcessSyncResponse(resp *mautrix.RespSync, since string) {
|
||||
if len(resp.DeviceLists.Changed) > 0 {
|
||||
mach.Log.Trace("Device list changes in /sync: %v", resp.DeviceLists.Changed)
|
||||
mach.fetchKeys(resp.DeviceLists.Changed, since)
|
||||
mach.fetchKeys(resp.DeviceLists.Changed, since, false)
|
||||
}
|
||||
|
||||
for _, evt := range resp.ToDevice.Events {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ type Store interface {
|
|||
|
||||
GetDevices(id.UserID) (map[id.DeviceID]*DeviceIdentity, error)
|
||||
PutDevices(id.UserID, map[id.DeviceID]*DeviceIdentity) error
|
||||
FilterTrackedUsers([]id.UserID) []id.UserID
|
||||
}
|
||||
|
||||
type messageIndexKey struct {
|
||||
|
|
@ -291,3 +292,17 @@ func (gs *GobStore) PutDevices(userID id.UserID, devices map[id.DeviceID]*Device
|
|||
gs.lock.Unlock()
|
||||
return err
|
||||
}
|
||||
|
||||
func (gs *GobStore) FilterTrackedUsers(users []id.UserID) []id.UserID {
|
||||
gs.lock.RLock()
|
||||
var ptr int
|
||||
for _, userID := range users {
|
||||
_, ok := gs.Devices[userID]
|
||||
if ok {
|
||||
users[ptr] = userID
|
||||
ptr++
|
||||
}
|
||||
}
|
||||
gs.lock.RUnlock()
|
||||
return users[:ptr]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue