mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -06:00
Use userID for room alias handling
This commit is contained in:
parent
7420e731cc
commit
c0be935e59
|
|
@ -181,23 +181,8 @@ func SetLocalAlias(
|
||||||
return *resErr
|
return *resErr
|
||||||
}
|
}
|
||||||
|
|
||||||
userID, err := spec.NewUserID(device.UserID, true)
|
|
||||||
if err != nil {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusInternalServerError,
|
|
||||||
JSON: spec.InternalServerError{Err: "UserID for device is invalid"},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceSenderID, err := rsAPI.QuerySenderIDForUser(req.Context(), r.RoomID, *userID)
|
|
||||||
if err != nil {
|
|
||||||
return util.JSONResponse{
|
|
||||||
Code: http.StatusInternalServerError,
|
|
||||||
JSON: spec.InternalServerError{Err: "Could not find SenderID for this device"},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queryReq := roomserverAPI.SetRoomAliasRequest{
|
queryReq := roomserverAPI.SetRoomAliasRequest{
|
||||||
SenderID: deviceSenderID,
|
UserID: device.UserID,
|
||||||
RoomID: r.RoomID,
|
RoomID: r.RoomID,
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import "regexp"
|
||||||
// SetRoomAliasRequest is a request to SetRoomAlias
|
// SetRoomAliasRequest is a request to SetRoomAlias
|
||||||
type SetRoomAliasRequest struct {
|
type SetRoomAliasRequest struct {
|
||||||
// ID of the user setting the alias
|
// ID of the user setting the alias
|
||||||
SenderID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
// New alias for the room
|
// New alias for the room
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
// The room ID the alias is referring to
|
// The room ID the alias is referring to
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ func (r *RoomserverInternalAPI) SetRoomAlias(
|
||||||
response.AliasExists = false
|
response.AliasExists = false
|
||||||
|
|
||||||
// Save the new alias
|
// Save the new alias
|
||||||
if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID, request.SenderID); err != nil {
|
if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID, request.UserID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,7 @@ func (c *Creator) PerformCreateRoom(ctx context.Context, userID spec.UserID, roo
|
||||||
aliasReq := api.SetRoomAliasRequest{
|
aliasReq := api.SetRoomAliasRequest{
|
||||||
Alias: roomAlias,
|
Alias: roomAlias,
|
||||||
RoomID: roomID.String(),
|
RoomID: roomID.String(),
|
||||||
SenderID: userID.String(),
|
UserID: userID.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
var aliasResp api.SetRoomAliasResponse
|
var aliasResp api.SetRoomAliasResponse
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ func moveLocalAliases(ctx context.Context,
|
||||||
return fmt.Errorf("Failed to remove old room alias: %w", err)
|
return fmt.Errorf("Failed to remove old room alias: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
setAliasReq := api.SetRoomAliasRequest{SenderID: userID, Alias: alias, RoomID: newRoomID}
|
setAliasReq := api.SetRoomAliasRequest{UserID: userID, Alias: alias, RoomID: newRoomID}
|
||||||
setAliasRes := api.SetRoomAliasResponse{}
|
setAliasRes := api.SetRoomAliasResponse{}
|
||||||
if err = URSAPI.SetRoomAlias(ctx, &setAliasReq, &setAliasRes); err != nil {
|
if err = URSAPI.SetRoomAlias(ctx, &setAliasReq, &setAliasRes); err != nil {
|
||||||
return fmt.Errorf("Failed to set new room alias: %w", err)
|
return fmt.Errorf("Failed to set new room alias: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -267,7 +267,7 @@ func TestPurgeRoom(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
aliasResp := &api.SetRoomAliasResponse{}
|
aliasResp := &api.SetRoomAliasResponse{}
|
||||||
if err = rsAPI.SetRoomAlias(ctx, &api.SetRoomAliasRequest{RoomID: room.ID, Alias: "myalias", SenderID: alice.ID}, aliasResp); err != nil {
|
if err = rsAPI.SetRoomAlias(ctx, &api.SetRoomAliasRequest{RoomID: room.ID, Alias: "myalias", UserID: alice.ID}, aliasResp); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// check the alias is actually there
|
// check the alias is actually there
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue