mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-09 22:42:58 +00:00
Fix m.direct only being partially upgraded (#3209)
Previously we would update `m.direct` once we found the old room ID. If the roomID is found somewhere in the middle, we would never add the rest of the users, resulting in only partially upgraded `m.direct` and chats loosing their 1:1 flag.
This commit is contained in:
parent
05a8f1ede3
commit
10b4fbc66d
@ -266,8 +266,8 @@ func (s *OutputRoomEventConsumer) updateMDirect(ctx context.Context, oldRoomID,
|
|||||||
directChats := gjson.ParseBytes(directChatsRaw)
|
directChats := gjson.ParseBytes(directChatsRaw)
|
||||||
newDirectChats := make(map[string][]string)
|
newDirectChats := make(map[string][]string)
|
||||||
// iterate over all userID -> roomIDs
|
// iterate over all userID -> roomIDs
|
||||||
directChats.ForEach(func(userID, roomIDs gjson.Result) bool {
|
|
||||||
var found bool
|
var found bool
|
||||||
|
directChats.ForEach(func(userID, roomIDs gjson.Result) bool {
|
||||||
for _, roomID := range roomIDs.Array() {
|
for _, roomID := range roomIDs.Array() {
|
||||||
newDirectChats[userID.Str] = append(newDirectChats[userID.Str], roomID.Str)
|
newDirectChats[userID.Str] = append(newDirectChats[userID.Str], roomID.Str)
|
||||||
// add the new roomID to m.direct
|
// add the new roomID to m.direct
|
||||||
@ -276,22 +276,21 @@ func (s *OutputRoomEventConsumer) updateMDirect(ctx context.Context, oldRoomID,
|
|||||||
newDirectChats[userID.Str] = append(newDirectChats[userID.Str], newRoomID)
|
newDirectChats[userID.Str] = append(newDirectChats[userID.Str], newRoomID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
// Only hit the database if we found the old room as a DM for this user
|
// Only hit the database if we found the old room as a DM for this user
|
||||||
if found {
|
if found {
|
||||||
var data []byte
|
var data []byte
|
||||||
data, err = json.Marshal(newDirectChats)
|
data, err = json.Marshal(newDirectChats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true
|
return err
|
||||||
}
|
}
|
||||||
if err = s.db.SaveAccountData(ctx, localpart, serverName, "", "m.direct", data); err != nil {
|
if err = s.db.SaveAccountData(ctx, localpart, serverName, "", "m.direct", data); err != nil {
|
||||||
return true
|
return fmt.Errorf("failed to update m.direct state: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to update m.direct state")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user