mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-10 16:33:11 -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)
|
||||
}
|
||||
|
||||
if queryRes.AliasExists {
|
||||
return util.JSONResponse{
|
||||
Code: 409,
|
||||
JSON: jsonerror.Unknown("The alias " + alias + " already exists."),
|
||||
}
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
Code: 200,
|
||||
JSON: struct{}{},
|
||||
|
|
|
|||
|
|
@ -111,7 +111,10 @@ type SetRoomAliasRequest struct {
|
|||
}
|
||||
|
||||
// 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.
|
||||
type RoomserverQueryAPI interface {
|
||||
|
|
|
|||
|
|
@ -172,8 +172,19 @@ func (r *RoomserverQueryAPI) SetRoomAlias(
|
|||
request *api.SetRoomAliasRequest,
|
||||
response *api.SetRoomAliasResponse,
|
||||
) 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
|
||||
// TODO: Check if alias already exists
|
||||
if err := r.DB.SetRoomAlias(request.Alias, request.RoomID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -183,7 +194,6 @@ func (r *RoomserverQueryAPI) SetRoomAlias(
|
|||
return err
|
||||
}
|
||||
|
||||
// We don't need to return anything in the response, so we don't edit it
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue