diff --git a/client.go b/client.go index 54a70bef..c05826e1 100644 --- a/client.go +++ b/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) diff --git a/id/opaque.go b/id/opaque.go index 0f632f11..0ec37da0 100644 --- a/id/opaque.go +++ b/id/opaque.go @@ -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) +} \ No newline at end of file diff --git a/requests.go b/requests.go index 6455e2f8..81d4689e 100644 --- a/requests.go +++ b/requests.go @@ -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"` +} diff --git a/responses.go b/responses.go index f74f95f0..f87be96d 100644 --- a/responses.go +++ b/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"` +}