mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 02:43:09 -06:00
Interface approach removed, map approach added
This commit is contained in:
parent
b15a444404
commit
9f7b1290af
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue