THAT test finally passed!

This commit is contained in:
SUMUKHA-PK 2019-08-01 12:00:22 +05:30
parent d28f245a32
commit 192b263bf0

View file

@ -26,7 +26,6 @@ import (
"github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/sirupsen/logrus"
) )
// newTag creates and returns a new Tag type // newTag creates and returns a new Tag type
@ -52,14 +51,7 @@ func GetTags(
} }
} }
localpart, _, err := gomatrixserverlib.SplitID('@', userID) _, data, err := obtainSavedTags(req, userID, roomID, accountDB)
if err != nil {
return httputil.LogThenError(req, err)
}
data, err := accountDB.GetAccountDataByType(
req.Context(), localpart, roomID, "m.tag",
)
if err != nil { if err != nil {
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
@ -70,32 +62,15 @@ func GetTags(
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
} }
logrus.Info("MYDUMBDATA")
var tagData []gomatrix.TagData var tagData []gomatrix.TagData
tagContent := newTag() tagContent := newTag()
err = json.Unmarshal(dataByte, &tagData) err = json.Unmarshal(dataByte, &tagData)
// tagData[0].Content.Tags["something"] = gomatrix.TagProperties{0}
logrus.Info(tagData[0].Content.Tags)
logrus.Info(tagData[0].Content)
tagContent = tagData[0].Content tagContent = tagData[0].Content
logrus.Info(tagContent)
logrus.Info(tagContent.Tags)
if err != nil { if err != nil {
return httputil.LogThenError(req, err) return httputil.LogThenError(req, err)
} }
// outJSON, err := json.Marshal(tagContent)
// if err != nil {
// return httputil.LogThenError(req, err)
// }
// logrus.Info(string(outJSON))
// // send data to syncapi
// if err := syncProducer.SendData(userID, roomID, tag); err != nil {
// return httputil.LogThenError(req, err)
// }
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusOK, Code: http.StatusOK,
JSON: tagContent, JSON: tagContent,
@ -128,9 +103,9 @@ func PutTag(
var properties gomatrix.TagProperties var properties gomatrix.TagProperties
if reqErr := httputil.UnmarshalJSONRequest(req, &properties); reqErr != nil { // if reqErr := httputil.UnmarshalJSONRequest(req, &properties); reqErr != nil {
return *reqErr // return *reqErr
} // }
tagContent := newTag() tagContent := newTag()
var dataByte []byte var dataByte []byte
@ -201,6 +176,7 @@ func DeleteTag(
var tagData []gomatrix.TagData var tagData []gomatrix.TagData
tagContent := newTag() tagContent := newTag()
err = json.Unmarshal(dataByte, &tagData) err = json.Unmarshal(dataByte, &tagData)
tagContent = tagData[0].Content
// Check whether the Tag to be deleted exists // Check whether the Tag to be deleted exists
if _, ok := tagContent.Tags[tag]; ok { if _, ok := tagContent.Tags[tag]; ok {
@ -235,7 +211,7 @@ func obtainSavedTags(
userID string, userID string,
roomID string, roomID string,
accountDB *accounts.Database, accountDB *accounts.Database,
) (string, []gomatrixserverlib.RawJSON, error) { ) (string, []gomatrixserverlib.ClientEvent, error) {
localpart, _, err := gomatrixserverlib.SplitID('@', userID) localpart, _, err := gomatrixserverlib.SplitID('@', userID)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
@ -248,7 +224,7 @@ func obtainSavedTags(
return "", nil, err return "", nil, err
} }
return localpart, extractEventContents(data), nil return localpart, data, nil
} }
// saveTagData is a utility function to save the tag data into the DB // saveTagData is a utility function to save the tag data into the DB
@ -275,17 +251,3 @@ func extractEventContents(data []gomatrixserverlib.ClientEvent) []gomatrixserver
} }
return contentData return contentData
} }
func deleteTagData(req *http.Request,
localpart string,
roomID string,
accountDB *accounts.Database,
Tag gomatrix.TagContent,
) error {
newTagData, err := json.Marshal(Tag)
if err != nil {
return err
}
return accountDB.SaveAccountData(req.Context(), localpart, roomID, "m.tag", string(newTagData))
}