diff --git a/client.go b/client.go index a452bf2a5..76ad2306f 100644 --- a/client.go +++ b/client.go @@ -1358,6 +1358,16 @@ func (cli *Client) Context(roomID id.RoomID, eventID id.EventID, filter *FilterP return } +func (cli *Client) Search(search SearchCategories, nextBatch *string) (resp *RespSearch, err error) { + query := make(map[string]string) + if nextBatch != nil { + query["next_batch"] = *nextBatch + } + urlPath := cli.BuildURLWithQuery(ClientURLPath{"v3", "search"}, query) + _, err = cli.MakeRequest("POST", urlPath, &search, &resp) + return +} + func (cli *Client) GetEvent(roomID id.RoomID, eventID id.EventID) (resp *event.Event, err error) { urlPath := cli.BuildClientURL("v3", "rooms", roomID, "event", eventID) _, err = cli.MakeRequest("GET", urlPath, nil, &resp) diff --git a/requests.go b/requests.go index 34d4e3c3d..f601ba34c 100644 --- a/requests.go +++ b/requests.go @@ -324,3 +324,31 @@ type ReqSetReadMarkers struct { Read id.EventID `json:"m.read"` FullyRead id.EventID `json:"m.fully_read"` } + +type SearchGroups struct { + Key string `json:"key,omitempty"` +} + +// The include event context. Part of +// https://spec.matrix.org/v1.3/client-server-api/#post_matrixclientv3search. +type IncludeEventContext struct { + AfterLimit int `json:"after_limit,omitempty"` + BeforeLimit int `json:"before_limit,omitempty"` + IncludeProfile bool `json:"include_profile,omitempty"` +} + +type RoomEventCriteria struct { + EventContext IncludeEventContext `json:"event_context,omitempty"` + Filter FilterPart `json:"filter,omitempty"` + Groupings struct { + GroupBy []SearchGroups `json:"group_by,omitempty"` + } `json:"groupings,omitempty"` + IncludeState bool `json:"include_state,omitempty"` + Keys []string `json:"keys,omitempty"` + OrderBy string `json:"order_by,omitempty"` + SearchTerm string `json:"search_term"` +} + +type SearchCategories struct { + RoomEvents RoomEventCriteria `json:"room_events"` +} diff --git a/responses.go b/responses.go index 19cabfadc..89f9e459f 100644 --- a/responses.go +++ b/responses.go @@ -342,3 +342,35 @@ type RespBatchSend struct { NextBatchID id.BatchID `json:"next_batch_id"` } + +type EventContext struct { + End string `json:"end"` + EventsAfter []*event.Event `json:"events_after"` + EventsBefore []*event.Event `json:"events_before"` + ProfileInfo map[string]struct { + AvatarURL *string `json:"avatar_url"` + DisplayName *string `json:"display_name"` + } `json:"profile_info"` + Start string `json:"start"` +} + +type SearchResults struct { + Context EventContext `json:"context"` + Rank float64 `json:"rank"` + Result *event.Event `json:"result"` +} + +type ResRoomEvents struct { + Count int `json:"count"` + Groups map[string]string `json:"groups"` + Highlights []string `json:"highlights"` + NextBatch string `json:"next_batch"` + Results []SearchResults `json:"results"` + State map[id.RoomID][]map[string]*event.Event `json:"state"` +} + +type RespSearch struct { + SearchCategories struct { + RoomEvents ResRoomEvents `json:"room_events"` + } `json:"search_categories"` +}