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
|
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{
|
queryReq := roomserverAPI.SetRoomAliasRequest{
|
||||||
UserID: device.UserID,
|
SenderID: senderID,
|
||||||
RoomID: r.RoomID,
|
RoomID: r.RoomID,
|
||||||
Alias: alias,
|
Alias: alias,
|
||||||
}
|
}
|
||||||
var queryRes roomserverAPI.SetRoomAliasResponse
|
var queryRes roomserverAPI.SetRoomAliasResponse
|
||||||
if err := rsAPI.SetRoomAlias(req.Context(), &queryReq, &queryRes); err != nil {
|
if err := rsAPI.SetRoomAlias(req.Context(), &queryReq, &queryRes); err != nil {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
// 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
|
||||||
UserID string `json:"user_id"`
|
SenderID spec.SenderID `json:"sender"`
|
||||||
// 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.UserID); err != nil {
|
if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID, string(request.SenderID)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -434,9 +434,9 @@ func (c *Creator) PerformCreateRoom(ctx context.Context, userID spec.UserID, roo
|
||||||
// been taken.
|
// been taken.
|
||||||
if roomAlias != "" {
|
if roomAlias != "" {
|
||||||
aliasReq := api.SetRoomAliasRequest{
|
aliasReq := api.SetRoomAliasRequest{
|
||||||
Alias: roomAlias,
|
SenderID: senderID,
|
||||||
RoomID: roomID.String(),
|
Alias: roomAlias,
|
||||||
UserID: userID.String(),
|
RoomID: roomID.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
var aliasResp api.SetRoomAliasResponse
|
var aliasResp api.SetRoomAliasResponse
|
||||||
|
|
|
@ -188,7 +188,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{UserID: userID.String(), Alias: alias, RoomID: newRoomID}
|
setAliasReq := api.SetRoomAliasRequest{SenderID: senderID, 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)
|
||||||
|
|
|
@ -274,9 +274,8 @@ func TestPurgeRoom(t *testing.T) {
|
||||||
if !isPublished {
|
if !isPublished {
|
||||||
t.Fatalf("room should be published before purging")
|
t.Fatalf("room should be published before purging")
|
||||||
}
|
}
|
||||||
|
|
||||||
aliasResp := &api.SetRoomAliasResponse{}
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// check the alias is actually there
|
// check the alias is actually there
|
||||||
|
|
Loading…
Reference in a new issue