2017-07-28 05:31:43 -05:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
2023-06-07 12:14:35 -05:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
|
|
|
)
|
2022-03-07 03:37:04 -06:00
|
|
|
|
2017-07-28 05:31:43 -05:00
|
|
|
// SetRoomAliasRequest is a request to SetRoomAlias
|
|
|
|
type SetRoomAliasRequest struct {
|
|
|
|
// ID of the user setting the alias
|
2023-07-26 07:46:26 -05:00
|
|
|
SenderID spec.SenderID `json:"sender"`
|
2017-07-28 05:31:43 -05:00
|
|
|
// New alias for the room
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
// The room ID the alias is referring to
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRoomAliasResponse is a response to SetRoomAlias
|
|
|
|
type SetRoomAliasResponse struct {
|
|
|
|
// Does the alias already refer to a room?
|
|
|
|
AliasExists bool `json:"alias_exists"`
|
|
|
|
}
|
|
|
|
|
2018-05-30 07:43:13 -05:00
|
|
|
// GetRoomIDForAliasRequest is a request to GetRoomIDForAlias
|
|
|
|
type GetRoomIDForAliasRequest struct {
|
2017-07-28 05:31:43 -05:00
|
|
|
// Alias we want to lookup
|
|
|
|
Alias string `json:"alias"`
|
2021-03-03 11:00:31 -06:00
|
|
|
// Should we ask appservices for their aliases as a part of
|
|
|
|
// the request?
|
|
|
|
IncludeAppservices bool `json:"include_appservices"`
|
2017-07-28 05:31:43 -05:00
|
|
|
}
|
|
|
|
|
2018-05-30 07:43:13 -05:00
|
|
|
// GetRoomIDForAliasResponse is a response to GetRoomIDForAlias
|
|
|
|
type GetRoomIDForAliasResponse struct {
|
2017-07-28 05:31:43 -05:00
|
|
|
// The room ID the alias refers to
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
}
|
|
|
|
|
2018-05-30 07:43:13 -05:00
|
|
|
// GetAliasesForRoomIDRequest is a request to GetAliasesForRoomID
|
|
|
|
type GetAliasesForRoomIDRequest struct {
|
|
|
|
// The room ID we want to find aliases for
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAliasesForRoomIDResponse is a response to GetAliasesForRoomID
|
|
|
|
type GetAliasesForRoomIDResponse struct {
|
|
|
|
// The aliases the alias refers to
|
|
|
|
Aliases []string `json:"aliases"`
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:31:43 -05:00
|
|
|
// RemoveRoomAliasRequest is a request to RemoveRoomAlias
|
|
|
|
type RemoveRoomAliasRequest struct {
|
|
|
|
// ID of the user removing the alias
|
2023-06-07 12:14:35 -05:00
|
|
|
SenderID spec.SenderID `json:"user_id"`
|
2017-07-28 05:31:43 -05:00
|
|
|
// The room alias to remove
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveRoomAliasResponse is a response to RemoveRoomAlias
|
2021-07-21 10:53:50 -05:00
|
|
|
type RemoveRoomAliasResponse struct {
|
|
|
|
// Did the alias exist before?
|
|
|
|
Found bool `json:"found"`
|
|
|
|
// Did we remove it?
|
|
|
|
Removed bool `json:"removed"`
|
|
|
|
}
|
2022-03-07 03:37:04 -06:00
|
|
|
|
|
|
|
type AliasEvent struct {
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
AltAliases []string `json:"alt_aliases"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var validateAliasRegex = regexp.MustCompile("^#.*:.+$")
|
|
|
|
|
|
|
|
func (a AliasEvent) Valid() bool {
|
|
|
|
for _, alias := range a.AltAliases {
|
|
|
|
if !validateAliasRegex.MatchString(alias) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a.Alias == "" || validateAliasRegex.MatchString(a.Alias)
|
|
|
|
}
|