mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-01-18 18:04:27 -06:00
have setting room aliases use sender IDs
- deleting already used them, but since setting still used user IDs this caused bugs - also, should we even link pseudo IDs and room aliases? Question for future portable IDs work
This commit is contained in:
parent
79d4a0e399
commit
4b4fab209c
|
@ -181,10 +181,37 @@ func SetLocalAlias(
|
|||
return *resErr
|
||||
}
|
||||
|
||||
maybeRoomID, err := spec.NewRoomID(r.RoomID)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: spec.InvalidParam("invalid room ID"),
|
||||
}
|
||||
}
|
||||
roomID := *maybeRoomID // should be safe due to error check
|
||||
|
||||
maybeUserID, err := spec.NewUserID(device.UserID, true)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.Unknown("internal server error"),
|
||||
}
|
||||
}
|
||||
userID := *maybeUserID
|
||||
|
||||
senderID, err := rsAPI.QuerySenderIDForUser(req.Context(), roomID, userID)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("QuerySenderIDForUser failed")
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.Unknown("internal server error"),
|
||||
}
|
||||
}
|
||||
|
||||
queryReq := roomserverAPI.SetRoomAliasRequest{
|
||||
UserID: device.UserID,
|
||||
RoomID: r.RoomID,
|
||||
Alias: alias,
|
||||
SenderID: senderID,
|
||||
RoomID: r.RoomID,
|
||||
Alias: alias,
|
||||
}
|
||||
var queryRes roomserverAPI.SetRoomAliasResponse
|
||||
if err := rsAPI.SetRoomAlias(req.Context(), &queryReq, &queryRes); err != nil {
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
// SetRoomAliasRequest is a request to SetRoomAlias
|
||||
type SetRoomAliasRequest struct {
|
||||
// ID of the user setting the alias
|
||||
UserID string `json:"user_id"`
|
||||
SenderID spec.SenderID `json:"sender"`
|
||||
// New alias for the room
|
||||
Alias string `json:"alias"`
|
||||
// The room ID the alias is referring to
|
||||
|
|
|
@ -51,7 +51,7 @@ func (r *RoomserverInternalAPI) SetRoomAlias(
|
|||
response.AliasExists = false
|
||||
|
||||
// Save the new alias
|
||||
if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID, request.UserID); err != nil {
|
||||
if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID, string(request.SenderID)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -434,9 +434,9 @@ func (c *Creator) PerformCreateRoom(ctx context.Context, userID spec.UserID, roo
|
|||
// been taken.
|
||||
if roomAlias != "" {
|
||||
aliasReq := api.SetRoomAliasRequest{
|
||||
Alias: roomAlias,
|
||||
RoomID: roomID.String(),
|
||||
UserID: userID.String(),
|
||||
SenderID: senderID,
|
||||
Alias: roomAlias,
|
||||
RoomID: roomID.String(),
|
||||
}
|
||||
|
||||
var aliasResp api.SetRoomAliasResponse
|
||||
|
|
|
@ -188,7 +188,7 @@ func moveLocalAliases(ctx context.Context,
|
|||
return fmt.Errorf("Failed to remove old room alias: %w", err)
|
||||
}
|
||||
|
||||
setAliasReq := api.SetRoomAliasRequest{UserID: userID.String(), Alias: alias, RoomID: newRoomID}
|
||||
setAliasReq := api.SetRoomAliasRequest{SenderID: senderID, Alias: alias, RoomID: newRoomID}
|
||||
setAliasRes := api.SetRoomAliasResponse{}
|
||||
if err = URSAPI.SetRoomAlias(ctx, &setAliasReq, &setAliasRes); err != nil {
|
||||
return fmt.Errorf("Failed to set new room alias: %w", err)
|
||||
|
|
|
@ -274,9 +274,8 @@ func TestPurgeRoom(t *testing.T) {
|
|||
if !isPublished {
|
||||
t.Fatalf("room should be published before purging")
|
||||
}
|
||||
|
||||
aliasResp := &api.SetRoomAliasResponse{}
|
||||
if err = rsAPI.SetRoomAlias(ctx, &api.SetRoomAliasRequest{RoomID: room.ID, Alias: "myalias", UserID: alice.ID}, aliasResp); err != nil {
|
||||
if err = rsAPI.SetRoomAlias(ctx, &api.SetRoomAliasRequest{RoomID: room.ID, Alias: "myalias", SenderID: spec.SenderID(alice.ID)}, aliasResp); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// check the alias is actually there
|
||||
|
|
Loading…
Reference in a new issue