mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 01:13:10 -06:00
Check if alias already exists
This commit is contained in:
parent
61adfa125c
commit
26b050fad7
|
|
@ -113,6 +113,13 @@ func SetLocalAlias(
|
||||||
return httputil.LogThenError(req, err)
|
return httputil.LogThenError(req, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if queryRes.AliasExists {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 409,
|
||||||
|
JSON: jsonerror.Unknown("The alias " + alias + " already exists."),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
JSON: struct{}{},
|
JSON: struct{}{},
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,10 @@ type SetRoomAliasRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRoomAliasResponse is a response to SetRoomAlias
|
// SetRoomAliasResponse is a response to SetRoomAlias
|
||||||
type SetRoomAliasResponse struct{}
|
type SetRoomAliasResponse struct {
|
||||||
|
// Does the alias already refer to a room?
|
||||||
|
AliasExists bool `json:"alias_exists"`
|
||||||
|
}
|
||||||
|
|
||||||
// RoomserverQueryAPI is used to query information from the room server.
|
// RoomserverQueryAPI is used to query information from the room server.
|
||||||
type RoomserverQueryAPI interface {
|
type RoomserverQueryAPI interface {
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,19 @@ func (r *RoomserverQueryAPI) SetRoomAlias(
|
||||||
request *api.SetRoomAliasRequest,
|
request *api.SetRoomAliasRequest,
|
||||||
response *api.SetRoomAliasResponse,
|
response *api.SetRoomAliasResponse,
|
||||||
) error {
|
) error {
|
||||||
|
// Check if the alias isn't already referring to a room
|
||||||
|
roomID, err := r.DB.GetRoomIDFromAlias(request.Alias)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(roomID) > 0 {
|
||||||
|
// If the alias already exists, stop the process
|
||||||
|
response.AliasExists = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
response.AliasExists = false
|
||||||
|
|
||||||
// Save the new alias
|
// Save the new alias
|
||||||
// TODO: Check if alias already exists
|
|
||||||
if err := r.DB.SetRoomAlias(request.Alias, request.RoomID); err != nil {
|
if err := r.DB.SetRoomAlias(request.Alias, request.RoomID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +194,6 @@ func (r *RoomserverQueryAPI) SetRoomAlias(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't need to return anything in the response, so we don't edit it
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue