mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add wrapper for MSC2716 batch send
This commit is contained in:
parent
9cdc8ddcfe
commit
6b5ccdfd46
4 changed files with 42 additions and 0 deletions
15
client.go
15
client.go
|
|
@ -1510,6 +1510,21 @@ func (cli *Client) PutPushRule(scope string, kind pushrules.PushRuleType, ruleID
|
|||
return err
|
||||
}
|
||||
|
||||
// BatchSend sends a batch of historical events into a room. This is only available for appservices.
|
||||
//
|
||||
// See https://github.com/matrix-org/matrix-doc/pull/2716 for more info.
|
||||
func (cli *Client) BatchSend(roomID id.RoomID, req *ReqBatchSend) (resp *RespBatchSend, err error) {
|
||||
path := URLPath{"_matrix", "client", "unstable", "org.matrix.msc2716", "rooms", roomID, "batch_send"}
|
||||
query := map[string]string{
|
||||
"prev_event_id": req.PrevEventID.String(),
|
||||
}
|
||||
if len(req.BatchID) > 0 {
|
||||
query["batch_id"] = req.BatchID.String()
|
||||
}
|
||||
_, err = cli.MakeRequest("POST", cli.BuildBaseURLWithQuery(path, query), req, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
// TxnID returns the next transaction ID.
|
||||
func (cli *Client) TxnID() string {
|
||||
txnID := atomic.AddInt32(&cli.txnID, 1)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ func NewRoomAlias(localpart, server string) RoomAlias {
|
|||
// https://matrix.org/docs/spec/rooms/v4#event-ids
|
||||
type EventID string
|
||||
|
||||
// A BatchID is a string identifying a batch of events being backfilled to a room.
|
||||
// https://github.com/matrix-org/matrix-doc/pull/2716
|
||||
type BatchID string
|
||||
|
||||
func (roomID RoomID) String() string {
|
||||
return string(roomID)
|
||||
}
|
||||
|
|
@ -39,3 +43,7 @@ func (roomAlias RoomAlias) String() string {
|
|||
func (eventID EventID) String() string {
|
||||
return string(eventID)
|
||||
}
|
||||
|
||||
func (batchID BatchID) String() string {
|
||||
return string(batchID)
|
||||
}
|
||||
|
|
@ -302,3 +302,11 @@ type ReqPutPushRule struct {
|
|||
Conditions []pushrules.PushCondition `json:"conditions"`
|
||||
Pattern string `json:"pattern"`
|
||||
}
|
||||
|
||||
type ReqBatchSend struct {
|
||||
PrevEventID id.EventID `json:"-"`
|
||||
BatchID id.BatchID `json:"-"`
|
||||
|
||||
StateEventsAtStart []*event.Event `json:"state_events_at_start"`
|
||||
Events []*event.Event `json:"events"`
|
||||
}
|
||||
|
|
|
|||
11
responses.go
11
responses.go
|
|
@ -295,3 +295,14 @@ type RespDeviceInfo struct {
|
|||
LastSeenIP string `json:"last_seen_ip"`
|
||||
LastSeenTS int64 `json:"last_seen_ts"`
|
||||
}
|
||||
|
||||
type RespBatchSend struct {
|
||||
StateEventIDs []id.EventID `json:"state_event_ids"`
|
||||
EventIDs []id.EventID `json:"event_ids"`
|
||||
|
||||
InsertionEventID id.EventID `json:"insertion_event_id"`
|
||||
BatchEventID id.EventID `json:"batch_event_id"`
|
||||
BaseInsertionEventID id.EventID `json:"base_insertion_event_id"`
|
||||
|
||||
NextBatchID id.BatchID `json:"next_batch_id"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue