Skip to content

Initial search support #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
32 changes: 32 additions & 0 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}