mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
client: add wrapper for /relations endpoints
This commit is contained in:
parent
50f0b5fa7d
commit
68565a1f18
3 changed files with 54 additions and 0 deletions
|
|
@ -2088,6 +2088,12 @@ func (cli *Client) GetUnredactedEventContent(ctx context.Context, roomID id.Room
|
|||
return
|
||||
}
|
||||
|
||||
func (cli *Client) GetRelations(ctx context.Context, roomID id.RoomID, eventID id.EventID, req *ReqGetRelations) (resp *RespGetRelations, err error) {
|
||||
urlPath := cli.BuildURLWithQuery(append(ClientURLPath{"v1", "rooms", roomID, "relations", eventID}, req.PathSuffix()...), req.Query())
|
||||
_, err = cli.MakeRequest(ctx, http.MethodGet, urlPath, nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *Client) MarkRead(ctx context.Context, roomID id.RoomID, eventID id.EventID) (err error) {
|
||||
return cli.SendReceipt(ctx, roomID, eventID, event.ReceiptTypeRead, nil)
|
||||
}
|
||||
|
|
|
|||
41
requests.go
41
requests.go
|
|
@ -543,3 +543,44 @@ type ReqReport struct {
|
|||
Reason string `json:"reason,omitempty"`
|
||||
Score int `json:"score,omitempty"`
|
||||
}
|
||||
|
||||
type ReqGetRelations struct {
|
||||
RelationType event.RelationType
|
||||
EventType event.Type
|
||||
|
||||
Dir Direction
|
||||
From string
|
||||
To string
|
||||
Limit int
|
||||
Recurse bool
|
||||
}
|
||||
|
||||
func (rgr *ReqGetRelations) PathSuffix() ClientURLPath {
|
||||
if rgr.RelationType != "" {
|
||||
if rgr.EventType.Type != "" {
|
||||
return ClientURLPath{rgr.RelationType, rgr.EventType.Type}
|
||||
}
|
||||
return ClientURLPath{rgr.RelationType}
|
||||
}
|
||||
return ClientURLPath{}
|
||||
}
|
||||
|
||||
func (rgr *ReqGetRelations) Query() map[string]string {
|
||||
query := map[string]string{}
|
||||
if rgr.Dir != 0 {
|
||||
query["dir"] = string(rgr.Dir)
|
||||
}
|
||||
if rgr.From != "" {
|
||||
query["from"] = rgr.From
|
||||
}
|
||||
if rgr.To != "" {
|
||||
query["to"] = rgr.To
|
||||
}
|
||||
if rgr.Limit > 0 {
|
||||
query["limit"] = strconv.Itoa(rgr.Limit)
|
||||
}
|
||||
if rgr.Recurse {
|
||||
query["recurse"] = "true"
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
|
|
|||
|
|
@ -709,3 +709,10 @@ type RespOpenIDToken struct {
|
|||
MatrixServerName string `json:"matrix_server_name"`
|
||||
TokenType string `json:"token_type"` // Always "Bearer"
|
||||
}
|
||||
|
||||
type RespGetRelations struct {
|
||||
Chunk []*event.Event `json:"chunk"`
|
||||
NextBatch string `json:"next_batch,omitempty"`
|
||||
PrevBatch string `json:"prev_batch,omitempty"`
|
||||
RecursionDepth int `json:"recursion_depth,omitempty"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue