mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 10:53:09 -06:00
Added TagContent to gomatrix, imported.
This commit is contained in:
parent
92bc8a42e2
commit
9fc30d85b3
|
|
@ -20,15 +20,15 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// newMTag creates and returns a new MTag type
|
||||
func newMTag() common.MTag {
|
||||
return common.MTag{
|
||||
Tags: make(map[string]common.TagProperties),
|
||||
// newTag creates and returns a new Tag type
|
||||
func newTag() gomatrix.TagContent {
|
||||
return gomatrix.TagContent{
|
||||
Tags: make(map[string]gomatrix.TagProperties),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ func GetTag(
|
|||
userID string,
|
||||
roomID string,
|
||||
) util.JSONResponse {
|
||||
mtag := newMTag()
|
||||
Tag := newTag()
|
||||
|
||||
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
|
||||
if err != nil {
|
||||
|
|
@ -47,7 +47,7 @@ func GetTag(
|
|||
}
|
||||
|
||||
data, err := accountDB.GetAccountDataByType(
|
||||
req.Context(), localpart, roomID, "m.tag",
|
||||
req.Context(), localpart, roomID, "tag",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -58,7 +58,7 @@ func GetTag(
|
|||
if err != nil {
|
||||
httputil.LogThenError(req, err)
|
||||
}
|
||||
err = json.Unmarshal(dataByte, &mtag)
|
||||
err = json.Unmarshal(dataByte, &Tag)
|
||||
|
||||
if err != nil {
|
||||
httputil.LogThenError(req, err)
|
||||
|
|
@ -66,7 +66,7 @@ func GetTag(
|
|||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: mtag,
|
||||
JSON: Tag,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,8 +83,8 @@ func PutTag(
|
|||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
mtag := newMTag()
|
||||
var properties common.TagProperties
|
||||
Tag := newTag()
|
||||
var properties gomatrix.TagProperties
|
||||
|
||||
if reqErr := httputil.UnmarshalJSONRequest(req, &properties); reqErr != nil {
|
||||
return *reqErr
|
||||
|
|
@ -95,12 +95,12 @@ func PutTag(
|
|||
if err != nil {
|
||||
httputil.LogThenError(req, err)
|
||||
}
|
||||
if err = json.Unmarshal(dataByte, &mtag); err != nil {
|
||||
if err = json.Unmarshal(dataByte, &Tag); err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
}
|
||||
mtag.Tags[tag] = properties
|
||||
addDataToDB(req, localpart, roomID, accountDB, mtag)
|
||||
Tag.Tags[tag] = properties
|
||||
addDataToDB(req, localpart, roomID, accountDB, Tag)
|
||||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
|
|
@ -121,17 +121,18 @@ func DeleteTag(
|
|||
if err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
mtag := newMTag()
|
||||
Tag := newTag()
|
||||
|
||||
if len(data) > 0 {
|
||||
dataByte, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
httputil.LogThenError(req, err)
|
||||
}
|
||||
if err := json.Unmarshal(dataByte, &mtag); err != nil {
|
||||
if err := json.Unmarshal(dataByte, &Tag); err != nil {
|
||||
return httputil.LogThenError(req, err)
|
||||
}
|
||||
} else {
|
||||
//Synapse returns a 200 OK response on finding no Tags, same policy is followed here.
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: struct{}{},
|
||||
|
|
@ -139,15 +140,16 @@ func DeleteTag(
|
|||
}
|
||||
|
||||
// Check whether the Tag to be deleted exists
|
||||
if _, ok := mtag.Tags[tag]; ok {
|
||||
delete(mtag.Tags, tag)
|
||||
if _, ok := Tag.Tags[tag]; ok {
|
||||
delete(Tag.Tags, tag)
|
||||
} else {
|
||||
//Synapse returns a 200 OK response on finding no Tags, same policy is followed here.
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: struct{}{},
|
||||
}
|
||||
}
|
||||
addDataToDB(req, localpart, roomID, accountDB, mtag)
|
||||
addDataToDB(req, localpart, roomID, accountDB, Tag)
|
||||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
|
|
@ -168,7 +170,7 @@ func obtainSavedTags(
|
|||
}
|
||||
|
||||
data, err := accountDB.GetAccountDataByType(
|
||||
req.Context(), localpart, roomID, "m.tag",
|
||||
req.Context(), localpart, roomID, "tag",
|
||||
)
|
||||
if err != nil {
|
||||
return "", []gomatrixserverlib.ClientEvent{}, err
|
||||
|
|
@ -183,14 +185,14 @@ func addDataToDB(
|
|||
localpart string,
|
||||
roomID string,
|
||||
accountDB *accounts.Database,
|
||||
mtag common.MTag,
|
||||
Tag gomatrix.TagContent,
|
||||
) {
|
||||
newTagData, err := json.Marshal(mtag)
|
||||
newTagData, err := json.Marshal(Tag)
|
||||
if err != nil {
|
||||
httputil.LogThenError(req, err)
|
||||
}
|
||||
if err = accountDB.SaveAccountData(
|
||||
req.Context(), localpart, roomID, "m.tag", string(newTagData),
|
||||
req.Context(), localpart, roomID, "tag", string(newTagData),
|
||||
); err != nil {
|
||||
httputil.LogThenError(req, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,16 +46,6 @@ type DisplayName struct {
|
|||
// recognized by strconv.ParseBool
|
||||
type WeakBoolean bool
|
||||
|
||||
// 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
|
||||
type TagProperties struct {
|
||||
Order float32 `json:"order,omitempty"` // Empty values must be neglected
|
||||
}
|
||||
|
||||
// UnmarshalJSON is overridden here to allow strings vaguely representing a true
|
||||
// or false boolean to be set as their closest counterpart
|
||||
func (b *WeakBoolean) UnmarshalJSON(data []byte) error {
|
||||
|
|
|
|||
2
vendor/manifest
vendored
2
vendor/manifest
vendored
|
|
@ -142,7 +142,7 @@
|
|||
{
|
||||
"importpath": "github.com/matrix-org/gomatrix",
|
||||
"repository": "https://github.com/matrix-org/gomatrix",
|
||||
"revision": "a7fc80c8060c2544fe5d4dae465b584f8e9b4e27",
|
||||
"revision": "51f01ddc3d93b709449b011bfc67a72a611b1510",
|
||||
"branch": "master"
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -68,6 +69,10 @@ func (cli *Client) BuildBaseURL(urlPath ...string) string {
|
|||
parts := []string{hsURL.Path}
|
||||
parts = append(parts, urlPath...)
|
||||
hsURL.Path = path.Join(parts...)
|
||||
// Manually add the trailing slash back to the end of the path if it's explicitly needed
|
||||
if strings.HasSuffix(urlPath[len(urlPath)-1], "/") {
|
||||
hsURL.Path = hsURL.Path + "/"
|
||||
}
|
||||
query := hsURL.Query()
|
||||
if cli.AccessToken != "" {
|
||||
query.Set("access_token", cli.AccessToken)
|
||||
|
|
@ -529,7 +534,7 @@ func (cli *Client) ForgetRoom(roomID string) (resp *RespForgetRoom, err error) {
|
|||
// InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
|
||||
func (cli *Client) InviteUser(roomID string, req *ReqInviteUser) (resp *RespInviteUser, err error) {
|
||||
u := cli.BuildURL("rooms", roomID, "invite")
|
||||
_, err = cli.MakeRequest("POST", u, struct{}{}, &resp)
|
||||
_, err = cli.MakeRequest("POST", u, req, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ type Event struct {
|
|||
ID string `json:"event_id"` // The unique ID of this event
|
||||
RoomID string `json:"room_id"` // The room the event was sent to. May be nil (e.g. for presence)
|
||||
Content map[string]interface{} `json:"content"` // The JSON content of the event.
|
||||
Redacts string `json:"redacts,omitempty"` // The event ID that was redacted if a m.room.redaction event
|
||||
Unsigned map[string]interface{} `json:"unsigned"` // The unsigned portions of the event, such as age and prev_content
|
||||
}
|
||||
|
||||
// Body returns the value of the "body" key in the event content if it is
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package gomatrix
|
||||
|
||||
import "errors"
|
||||
|
||||
//Filter is used by clients to specify how the server should filter responses to e.g. sync requests
|
||||
//Specified by: https://matrix.org/docs/spec/client_server/r0.2.0.html#filtering
|
||||
type Filter struct {
|
||||
|
|
@ -21,7 +23,11 @@ type Filter struct {
|
|||
EventFields []string `json:"event_fields,omitempty"`
|
||||
EventFormat string `json:"event_format,omitempty"`
|
||||
Presence FilterPart `json:"presence,omitempty"`
|
||||
Room struct {
|
||||
Room RoomFilter `json:"room,omitempty"`
|
||||
}
|
||||
|
||||
// RoomFilter is used to define filtering rules for room events
|
||||
type RoomFilter struct {
|
||||
AccountData FilterPart `json:"account_data,omitempty"`
|
||||
Ephemeral FilterPart `json:"ephemeral,omitempty"`
|
||||
IncludeLeave bool `json:"include_leave,omitempty"`
|
||||
|
|
@ -29,15 +35,56 @@ type Filter struct {
|
|||
Rooms []string `json:"rooms,omitempty"`
|
||||
State FilterPart `json:"state,omitempty"`
|
||||
Timeline FilterPart `json:"timeline,omitempty"`
|
||||
} `json:"room,omitempty"`
|
||||
}
|
||||
|
||||
// FilterPart is used to define filtering rules for specific categories of events
|
||||
type FilterPart struct {
|
||||
NotRooms []string `json:"not_rooms,omitempty"`
|
||||
Rooms []string `json:"rooms,omitempty"`
|
||||
Limit *int `json:"limit,omitempty"`
|
||||
Limit int `json:"limit,omitempty"`
|
||||
NotSenders []string `json:"not_senders,omitempty"`
|
||||
NotTypes []string `json:"not_types,omitempty"`
|
||||
Senders []string `json:"senders,omitempty"`
|
||||
Types []string `json:"types,omitempty"`
|
||||
ContainsURL *bool `json:"contains_url,omitempty"`
|
||||
}
|
||||
|
||||
// Validate checks if the filter contains valid property values
|
||||
func (filter *Filter) Validate() error {
|
||||
if filter.EventFormat != "client" && filter.EventFormat != "federation" {
|
||||
return errors.New("Bad event_format value. Must be one of [\"client\", \"federation\"]")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultFilter returns the default filter used by the Matrix server if no filter is provided in the request
|
||||
func DefaultFilter() Filter {
|
||||
return Filter{
|
||||
AccountData: DefaultFilterPart(),
|
||||
EventFields: nil,
|
||||
EventFormat: "client",
|
||||
Presence: DefaultFilterPart(),
|
||||
Room: RoomFilter{
|
||||
AccountData: DefaultFilterPart(),
|
||||
Ephemeral: DefaultFilterPart(),
|
||||
IncludeLeave: false,
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
State: DefaultFilterPart(),
|
||||
Timeline: DefaultFilterPart(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultFilterPart returns the default filter part used by the Matrix server if no filter is provided in the request
|
||||
func DefaultFilterPart() FilterPart {
|
||||
return FilterPart{
|
||||
NotRooms: nil,
|
||||
Rooms: nil,
|
||||
Limit: 20,
|
||||
NotSenders: nil,
|
||||
NotTypes: nil,
|
||||
Senders: nil,
|
||||
Types: nil,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ type RespUserInteractive struct {
|
|||
Stages []string `json:"stages"`
|
||||
} `json:"flows"`
|
||||
Params map[string]interface{} `json:"params"`
|
||||
Session string `json:"string"`
|
||||
Session string `json:"session"`
|
||||
Completed []string `json:"completed"`
|
||||
ErrCode string `json:"errcode"`
|
||||
Error string `json:"error"`
|
||||
|
|
@ -168,6 +168,7 @@ type RespSync struct {
|
|||
} `json:"rooms"`
|
||||
}
|
||||
|
||||
// RespTurnServer is the JSON response from a Turn Server
|
||||
type RespTurnServer struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
|
|
|
|||
26
vendor/src/github.com/matrix-org/gomatrix/tags.go
vendored
Normal file
26
vendor/src/github.com/matrix-org/gomatrix/tags.go
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package gomatrix
|
||||
|
||||
// TagContent contains the data for an m.tag message type
|
||||
// https://matrix.org/docs/spec/client_server/r0.4.0.html#m-tag
|
||||
type TagContent struct {
|
||||
Tags map[string]TagProperties `json:"tags"`
|
||||
}
|
||||
|
||||
// TagProperties contains the properties of a Tag
|
||||
type TagProperties struct {
|
||||
Order float32 `json:"order,omitempty"` // Empty values must be neglected
|
||||
}
|
||||
Loading…
Reference in a new issue