diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go b/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go index c4a5e8933..7cec71c46 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go @@ -81,13 +81,8 @@ func PutTag(req *http.Request, userId string, roomId string, tag string) util.JS mtag := NewMTag() - // outInterface := map[string]interface{}{} - if len(data) > 0 { json.Unmarshal([]byte(data), &mtag) - if outInterface[tag] != nil { - // Error saying this Tag already exists - } } mtag.Tags[tag] = TagProperties{ @@ -123,6 +118,31 @@ func DeleteTag(req *http.Request, userId string, roomId string, tag string) util return httputil.LogThenError(req, err) } + data, err := accountDB.GetAccountDataByType( + req.Context(), localpart, "ROOM_ID", "m.tag", + ) + + if err != nil { + return httputil.LogThenError(req, err) + } + + mtag := NewMTag() + + if len(data) > 0 { + json.Unmarshal([]byte(data), &mtag) + } else { + //Error indicating there is no Tag data + return util.JSONResponse{} + } + + //Check whether the Tag to be deleted exists + if _, ok := mtag.Tags[tag]; ok { + delete(mtag.Tags, tag) //Deletion completed + } else { + //Error indicating that there is no Tag to delete + return util.JSONResponse{} + } + return util.JSONResponse{ Code: http.StatusOK, JSON: {},