Move pseudoID ClientEvent hotswapping to a common location (#3199)

Fixes a variety of issues where clients were receiving pseudoIDs in
places that should be userIDs.
This change makes pseudoIDs work with sliding sync & element x.

---------

Co-authored-by: Till <2353100+S7evinK@users.noreply.github.com>
This commit is contained in:
devonh 2023-09-15 15:25:09 +00:00 committed by GitHub
parent 8245b24100
commit db83789654
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 426 additions and 333 deletions

View file

@ -23,6 +23,14 @@ import (
userUtil "github.com/matrix-org/dendrite/userapi/util"
)
func queryUserIDForSender(senderID spec.SenderID) (*spec.UserID, error) {
if senderID == "" {
return nil, nil
}
return spec.NewUserID(string(senderID), true)
}
func TestNotifyUserCountsAsync(t *testing.T) {
alice := test.NewUser(t)
aliceLocalpart, serverName, err := gomatrixserverlib.SplitID('@', alice.ID)
@ -100,13 +108,14 @@ func TestNotifyUserCountsAsync(t *testing.T) {
}
// Insert a dummy event
sender, err := spec.NewUserID(alice.ID, true)
ev, err := synctypes.ToClientEvent(dummyEvent, synctypes.FormatAll, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
return queryUserIDForSender(senderID)
})
if err != nil {
t.Error(err)
}
sk := ""
if err := db.InsertNotification(ctx, aliceLocalpart, serverName, dummyEvent.EventID(), 0, nil, &api.Notification{
Event: synctypes.ToClientEvent(dummyEvent, synctypes.FormatAll, sender.String(), &sk, dummyEvent.Unsigned()),
Event: *ev,
}); err != nil {
t.Error(err)
}