mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 10:53:09 -06:00
Suggested changes resolved (Comments, new lines, copyright)
This commit is contained in:
parent
80b451df1b
commit
85edb4033d
|
|
@ -146,3 +146,8 @@ func NotTrusted(serverName string) *MatrixError {
|
||||||
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
Err: fmt.Sprintf("Untrusted server '%s'", serverName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoTagExists is an error that indicates the Tag to be deleted doesnt exist.
|
||||||
|
func NoTagExists(msg string) *MatrixError {
|
||||||
|
return &MatrixError{"M_NOT_FOUND", msg}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2017 Vector Creations Ltd
|
// Copyright 2019 Sumukha PK
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMTag creates and returns a new MTag type variable
|
// newMTag creates and returns a new MTag type variable
|
||||||
func NewMTag() common.MTag {
|
func newMTag() common.MTag {
|
||||||
return common.MTag{
|
return common.MTag{
|
||||||
Tags: make(map[string]common.TagProperties),
|
Tags: make(map[string]common.TagProperties),
|
||||||
}
|
}
|
||||||
|
|
@ -35,14 +35,12 @@ func NewMTag() common.MTag {
|
||||||
|
|
||||||
// GetTag implements GET /_matrix/client/r0/user/{userID}/rooms/{roomID}/tags
|
// GetTag implements GET /_matrix/client/r0/user/{userID}/rooms/{roomID}/tags
|
||||||
func GetTag(req *http.Request, accountDB *accounts.Database, userID string, roomID string) util.JSONResponse {
|
func GetTag(req *http.Request, accountDB *accounts.Database, userID string, roomID string) util.JSONResponse {
|
||||||
|
|
||||||
if req.Method != http.MethodGet {
|
if req.Method != http.MethodGet {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusMethodNotAllowed,
|
Code: http.StatusMethodNotAllowed,
|
||||||
JSON: jsonerror.NotFound("Bad method"),
|
JSON: jsonerror.NotFound("Bad method"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mtag := NewMTag()
|
mtag := NewMTag()
|
||||||
|
|
||||||
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
|
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
|
||||||
|
|
@ -73,7 +71,6 @@ func GetTag(req *http.Request, accountDB *accounts.Database, userID string, room
|
||||||
|
|
||||||
// PutTag implements PUT /_matrix/client/r0/user/{userID}/rooms/{roomID}/tags/{tag}
|
// PutTag implements PUT /_matrix/client/r0/user/{userID}/rooms/{roomID}/tags/{tag}
|
||||||
func PutTag(req *http.Request, accountDB *accounts.Database, userID string, roomID string, tag string) util.JSONResponse {
|
func PutTag(req *http.Request, accountDB *accounts.Database, userID string, roomID string, tag string) util.JSONResponse {
|
||||||
|
|
||||||
if req.Method != http.MethodPut {
|
if req.Method != http.MethodPut {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusMethodNotAllowed,
|
Code: http.StatusMethodNotAllowed,
|
||||||
|
|
@ -94,9 +91,7 @@ func PutTag(req *http.Request, accountDB *accounts.Database, userID string, room
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httputil.LogThenError(req, err)
|
return httputil.LogThenError(req, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mtag := NewMTag()
|
mtag := NewMTag()
|
||||||
|
|
||||||
var properties common.TagProperties
|
var properties common.TagProperties
|
||||||
|
|
||||||
if reqErr := httputil.UnmarshalJSONRequest(req, &properties); reqErr != nil {
|
if reqErr := httputil.UnmarshalJSONRequest(req, &properties); reqErr != nil {
|
||||||
|
|
@ -112,7 +107,6 @@ func PutTag(req *http.Request, accountDB *accounts.Database, userID string, room
|
||||||
}
|
}
|
||||||
|
|
||||||
mtag.Tags[tag] = properties
|
mtag.Tags[tag] = properties
|
||||||
|
|
||||||
newTagData, _ := json.Marshal(mtag)
|
newTagData, _ := json.Marshal(mtag)
|
||||||
|
|
||||||
if err := accountDB.SaveAccountData(
|
if err := accountDB.SaveAccountData(
|
||||||
|
|
@ -149,7 +143,6 @@ func DeleteTag(req *http.Request, accountDB *accounts.Database, userID string, r
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httputil.LogThenError(req, err)
|
return httputil.LogThenError(req, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mtag := NewMTag()
|
mtag := NewMTag()
|
||||||
|
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
|
|
@ -160,7 +153,10 @@ func DeleteTag(req *http.Request, accountDB *accounts.Database, userID string, r
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Error indicating there is no Tag data
|
//Error indicating there is no Tag data
|
||||||
return util.JSONResponse{}
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusMethodNotAllowed,
|
||||||
|
JSON: jsonerror.NoTagExists("No Tag Exists"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check whether the Tag to be deleted exists
|
//Check whether the Tag to be deleted exists
|
||||||
|
|
@ -168,9 +164,11 @@ func DeleteTag(req *http.Request, accountDB *accounts.Database, userID string, r
|
||||||
delete(mtag.Tags, tag) //Deletion completed
|
delete(mtag.Tags, tag) //Deletion completed
|
||||||
} else {
|
} else {
|
||||||
//Error indicating that there is no Tag to delete
|
//Error indicating that there is no Tag to delete
|
||||||
return util.JSONResponse{}
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusMethodNotAllowed,
|
||||||
|
JSON: jsonerror.NoTagExists("No Tag Exists"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newTagData, _ := json.Marshal(mtag)
|
newTagData, _ := json.Marshal(mtag)
|
||||||
|
|
||||||
if err := accountDB.SaveAccountData(
|
if err := accountDB.SaveAccountData(
|
||||||
|
|
|
||||||
|
|
@ -409,8 +409,6 @@ func Setup(
|
||||||
|
|
||||||
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
||||||
common.MakeAuthAPI("get_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
common.MakeAuthAPI("get_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
// When a GET tag request is done, obtain all data of user from here and provide a JSON response.
|
|
||||||
// MakeAuthAPI will convert it to a HTTP response and reflect it on the browser.
|
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
return GetTag(req, accountDB, vars["userId"], vars["roomId"])
|
return GetTag(req, accountDB, vars["userId"], vars["roomId"])
|
||||||
}),
|
}),
|
||||||
|
|
@ -418,8 +416,6 @@ func Setup(
|
||||||
|
|
||||||
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
||||||
common.MakeAuthAPI("put_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
common.MakeAuthAPI("put_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
// When a PUT tag request is done, obtain all data of user from here and provide a JSON response.
|
|
||||||
// MakeAuthAPI will convert it to a HTTP response and reflect it on the browser.
|
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
return PutTag(req, accountDB, vars["userId"], vars["roomId"], vars["tag"])
|
return PutTag(req, accountDB, vars["userId"], vars["roomId"], vars["tag"])
|
||||||
}),
|
}),
|
||||||
|
|
@ -427,8 +423,6 @@ func Setup(
|
||||||
|
|
||||||
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
||||||
common.MakeAuthAPI("delete_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
common.MakeAuthAPI("delete_tag", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
// When a DELETE tag request is done, obtain all data of user from here and provide a JSON response.
|
|
||||||
// MakeAuthAPI will convert it to a HTTP response and reflect it on the browser.
|
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
return DeleteTag(req, accountDB, vars["userId"], vars["roomId"], vars["tag"])
|
return DeleteTag(req, accountDB, vars["userId"], vars["roomId"], vars["tag"])
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue