Suggested changes resolved (Comments, new lines, copyright)

This commit is contained in:
SUMUKHA-PK 2019-03-14 11:17:40 +05:30
parent 80b451df1b
commit 85edb4033d
3 changed files with 16 additions and 19 deletions

View file

@ -146,3 +146,8 @@ func NotTrusted(serverName string) *MatrixError {
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}
}

View file

@ -1,4 +1,4 @@
// Copyright 2017 Vector Creations Ltd
// Copyright 2019 Sumukha PK
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -26,8 +26,8 @@ import (
"github.com/matrix-org/util"
)
// NewMTag creates and returns a new MTag type variable
func NewMTag() common.MTag {
// newMTag creates and returns a new MTag type variable
func newMTag() common.MTag {
return common.MTag{
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
func GetTag(req *http.Request, accountDB *accounts.Database, userID string, roomID string) util.JSONResponse {
if req.Method != http.MethodGet {
return util.JSONResponse{
Code: http.StatusMethodNotAllowed,
JSON: jsonerror.NotFound("Bad method"),
}
}
mtag := NewMTag()
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}
func PutTag(req *http.Request, accountDB *accounts.Database, userID string, roomID string, tag string) util.JSONResponse {
if req.Method != http.MethodPut {
return util.JSONResponse{
Code: http.StatusMethodNotAllowed,
@ -94,9 +91,7 @@ func PutTag(req *http.Request, accountDB *accounts.Database, userID string, room
if err != nil {
return httputil.LogThenError(req, err)
}
mtag := NewMTag()
var properties common.TagProperties
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
newTagData, _ := json.Marshal(mtag)
if err := accountDB.SaveAccountData(
@ -149,7 +143,6 @@ func DeleteTag(req *http.Request, accountDB *accounts.Database, userID string, r
if err != nil {
return httputil.LogThenError(req, err)
}
mtag := NewMTag()
if len(data) > 0 {
@ -160,7 +153,10 @@ func DeleteTag(req *http.Request, accountDB *accounts.Database, userID string, r
}
} else {
//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
@ -168,9 +164,11 @@ func DeleteTag(req *http.Request, accountDB *accounts.Database, userID string, r
delete(mtag.Tags, tag) //Deletion completed
} else {
//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)
if err := accountDB.SaveAccountData(

View file

@ -409,8 +409,6 @@ func Setup(
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags",
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)
return GetTag(req, accountDB, vars["userId"], vars["roomId"])
}),
@ -418,8 +416,6 @@ func Setup(
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
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)
return PutTag(req, accountDB, vars["userId"], vars["roomId"], vars["tag"])
}),
@ -427,8 +423,6 @@ func Setup(
r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
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)
return DeleteTag(req, accountDB, vars["userId"], vars["roomId"], vars["tag"])
}),