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 acc7f45f1..c4a5e8933 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 @@ -20,11 +20,17 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) +// Creates and returns a new MTag type variable +func NewMTag() MTag { + return MTag{ + Tags: make(map[string]TagProperties), + } +} + // GetTag implements GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags func GetTag(req *http.Request, userId string, roomId string) util.JSONResponse { @@ -50,7 +56,7 @@ func GetTag(req *http.Request, userId string, roomId string) util.JSONResponse { } // PutTag implements PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} -func PutTag(req *http.Request, userId string, roomId string, tag common.Tag) util.JSONResponse { +func PutTag(req *http.Request, userId string, roomId string, tag string) util.JSONResponse { if req.Method != http.MethodPut { return util.JSONResponse{ @@ -73,18 +79,22 @@ func PutTag(req *http.Request, userId string, roomId string, tag common.Tag) uti return httputil.LogThenError(req, err) } - outInterface := map[string]interface{}{} - json.Unmarshal([]byte(data), &outInterface) + mtag := NewMTag() + + // outInterface := map[string]interface{}{} if len(data) > 0 { - if outInterface[tag.Name] != nil { + json.Unmarshal([]byte(data), &mtag) + if outInterface[tag] != nil { // Error saying this Tag already exists } } - outInterface[tag.Name] = tag.Order + mtag.Tags[tag] = TagProperties{ + Order: 0.5, // Change value based on need + } - newTagData, _ := json.Marshal(outInterface) + newTagData, _ := json.Marshal(mtag) if err := accountDB.SaveAccountData( req.Context(), localpart, "ROOM_ID", "m.tag", newTagData, diff --git a/src/github.com/matrix-org/dendrite/common/types.go b/src/github.com/matrix-org/dendrite/common/types.go index a6171050d..2e8cdfb97 100644 --- a/src/github.com/matrix-org/dendrite/common/types.go +++ b/src/github.com/matrix-org/dendrite/common/types.go @@ -46,10 +46,14 @@ type DisplayName struct { // recognized by strconv.ParseBool type WeakBoolean bool -// RoomTags contain the data of the Tags per User for each Room -type Tag struct { - Name string - Order string +// MTag contains the data for a Tag which can be referenced by the Tag name +type MTag struct { + Tags map[string]TagProperties `json:"tags"` +} + +// TagProperties contains the properties of an MTag datatype +type TagProperties struct { + Order float32 `json:"order,omitempty"` // Empty values must be neglected } // UnmarshalJSON is overridden here to allow strings vaguely representing a true