aboutsummaryrefslogtreecommitdiff
path: root/roomserver/alias/alias.go
diff options
context:
space:
mode:
Diffstat (limited to 'roomserver/alias/alias.go')
-rw-r--r--roomserver/alias/alias.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/roomserver/alias/alias.go b/roomserver/alias/alias.go
index f699e336..aeaf5ae9 100644
--- a/roomserver/alias/alias.go
+++ b/roomserver/alias/alias.go
@@ -33,13 +33,16 @@ import (
type RoomserverAliasAPIDatabase interface {
// Save a given room alias with the room ID it refers to.
// Returns an error if there was a problem talking to the database.
- SetRoomAlias(ctx context.Context, alias string, roomID string) error
+ SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error
// Look up the room ID a given alias refers to.
// Returns an error if there was a problem talking to the database.
GetRoomIDForAlias(ctx context.Context, alias string) (string, error)
// Look up all aliases referring to a given room ID.
// Returns an error if there was a problem talking to the database.
GetAliasesForRoomID(ctx context.Context, roomID string) ([]string, error)
+ // Get the user ID of the creator of an alias.
+ // Returns an error if there was a problem talking to the database.
+ GetCreatorIDForAlias(ctx context.Context, alias string) (string, error)
// Remove a given room alias.
// Returns an error if there was a problem talking to the database.
RemoveRoomAlias(ctx context.Context, alias string) error
@@ -73,7 +76,7 @@ func (r *RoomserverAliasAPI) SetRoomAlias(
response.AliasExists = false
// Save the new alias
- if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID); err != nil {
+ if err := r.DB.SetRoomAlias(ctx, request.Alias, request.RoomID, request.UserID); err != nil {
return err
}
@@ -133,6 +136,22 @@ func (r *RoomserverAliasAPI) GetAliasesForRoomID(
return nil
}
+// GetCreatorIDForAlias implements alias.RoomserverAliasAPI
+func (r *RoomserverAliasAPI) GetCreatorIDForAlias(
+ ctx context.Context,
+ request *roomserverAPI.GetCreatorIDForAliasRequest,
+ response *roomserverAPI.GetCreatorIDForAliasResponse,
+) error {
+ // Look up the aliases in the database for the given RoomID
+ creatorID, err := r.DB.GetCreatorIDForAlias(ctx, request.Alias)
+ if err != nil {
+ return err
+ }
+
+ response.UserID = creatorID
+ return nil
+}
+
// RemoveRoomAlias implements alias.RoomserverAliasAPI
func (r *RoomserverAliasAPI) RemoveRoomAlias(
ctx context.Context,
@@ -278,6 +297,20 @@ func (r *RoomserverAliasAPI) SetupHTTP(servMux *http.ServeMux) {
}),
)
servMux.Handle(
+ roomserverAPI.RoomserverGetCreatorIDForAliasPath,
+ common.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
+ var request roomserverAPI.GetCreatorIDForAliasRequest
+ var response roomserverAPI.GetCreatorIDForAliasResponse
+ if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
+ return util.ErrorResponse(err)
+ }
+ if err := r.GetCreatorIDForAlias(req.Context(), &request, &response); err != nil {
+ return util.ErrorResponse(err)
+ }
+ return util.JSONResponse{Code: http.StatusOK, JSON: &response}
+ }),
+ )
+ servMux.Handle(
roomserverAPI.RoomserverGetAliasesForRoomIDPath,
common.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
var request roomserverAPI.GetAliasesForRoomIDRequest