mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 23:23:10 -06:00
Switch to using new db table for room userID lookup
This commit is contained in:
parent
50a783f0eb
commit
4b12b69044
|
|
@ -16,6 +16,7 @@ package query
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -1012,6 +1013,23 @@ func (r *Queryer) QueryUserIDForSender(ctx context.Context, roomID spec.RoomID,
|
|||
if err == nil {
|
||||
return userID, nil
|
||||
}
|
||||
// TODO: pseudoIDs
|
||||
return r.DB.GetUserIDForSender(ctx, roomID.String(), senderID)
|
||||
|
||||
bytes := spec.Base64Bytes{}
|
||||
err = bytes.Decode(string(senderID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
queryMap := map[spec.RoomID][]ed25519.PublicKey{roomID: {ed25519.PublicKey(bytes)}}
|
||||
result, err := r.DB.SelectUserIDsForPublicKeys(ctx, queryMap)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userKeys, ok := result[roomID]; ok {
|
||||
if userID, ok := userKeys[string(senderID)]; ok {
|
||||
return spec.NewUserID(userID, true)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,8 +168,6 @@ type Database interface {
|
|||
GetServerInRoom(ctx context.Context, roomNID types.RoomNID, serverName spec.ServerName) (bool, error)
|
||||
// GetKnownUsers searches all users that userID knows about.
|
||||
GetKnownUsers(ctx context.Context, userID, searchString string, limit int) ([]string, error)
|
||||
// GetKnownUsers tries to obtain the current mxid for a given user.
|
||||
GetUserIDForSender(ctx context.Context, roomID string, senderID spec.SenderID) (*spec.UserID, error)
|
||||
// GetKnownRooms returns a list of all rooms we know about.
|
||||
GetKnownRooms(ctx context.Context) ([]string, error)
|
||||
// ForgetRoom sets a flag in the membership table, that the user wishes to forget a specific room
|
||||
|
|
@ -207,6 +205,8 @@ type UserRoomKeys interface {
|
|||
SelectUserRoomPublicKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (key ed25519.PublicKey, err error)
|
||||
// SelectUserIDsForPublicKeys selects all userIDs for the requested senderKeys. Returns a map from roomID -> map from publicKey to userID.
|
||||
// If a senderKey can't be found, it is omitted in the result.
|
||||
// TODO: Why is the result map indexed by string not public key?
|
||||
// TODO: Shouldn't the input & result map be changed to be indexed by string instead of the RoomID struct?
|
||||
SelectUserIDsForPublicKeys(ctx context.Context, publicKeys map[spec.RoomID][]ed25519.PublicKey) (map[spec.RoomID]map[string]string, error)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1546,11 +1546,6 @@ func (d *Database) GetKnownUsers(ctx context.Context, userID, searchString strin
|
|||
return d.MembershipTable.SelectKnownUsers(ctx, nil, stateKeyNID, searchString, limit)
|
||||
}
|
||||
|
||||
func (d *Database) GetUserIDForSender(ctx context.Context, roomID string, senderID spec.SenderID) (*spec.UserID, error) {
|
||||
// TODO: Use real logic once DB for pseudoIDs is in place
|
||||
return spec.NewUserID(string(senderID), true)
|
||||
}
|
||||
|
||||
// GetKnownRooms returns a list of all rooms we know about.
|
||||
func (d *Database) GetKnownRooms(ctx context.Context) ([]string, error) {
|
||||
return d.RoomsTable.SelectRoomIDsWithEvents(ctx, nil)
|
||||
|
|
|
|||
Loading…
Reference in a new issue