MCPcopy Index your code
hub / github.com/coder/coder / listChats

Method listChats

coderd/exp_chats.go:320–436  ·  view source on GitHub ↗

EXPERIMENTAL: this endpoint is experimental and is subject to change. @Summary List chats @ID list-chats @Security CoderSessionToken @Tags Chats @Produce json @Param q query string false "Search query. Supports title: (case-insensitive, quote multi-word values), archived:bool, has_unread

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

318// @Router /api/experimental/chats [get]
319// @Description Experimental: this endpoint is subject to change.
320func (api *API) listChats(rw http.ResponseWriter, r *http.Request) {
321 ctx := r.Context()
322 apiKey := httpmw.APIKey(r)
323
324 paginationParams, ok := ParsePagination(rw, r)
325 if !ok {
326 return
327 }
328
329 queryStr := r.URL.Query().Get("q")
330 searchParams, errs := searchquery.Chats(queryStr)
331 if len(errs) > 0 {
332 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
333 Message: "Invalid chat search query.",
334 Validations: errs,
335 })
336 return
337 }
338
339 var labelFilter pqtype.NullRawMessage
340 if labelParams := r.URL.Query()["label"]; len(labelParams) > 0 {
341 labelMap := make(map[string]string, len(labelParams))
342 for _, lp := range labelParams {
343 key, value, ok := strings.Cut(lp, ":")
344 if !ok || key == "" || value == "" {
345 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
346 Message: fmt.Sprintf("Invalid label filter: %q (expected format key:value, both must be non-empty)", lp),
347 })
348 return
349 }
350 labelMap[key] = value
351 }
352 labelsJSON, err := json.Marshal(labelMap)
353 if err != nil {
354 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
355 Message: "Failed to marshal label filter.",
356 Detail: err.Error(),
357 })
358 return
359 }
360 labelFilter = pqtype.NullRawMessage{
361 RawMessage: labelsJSON,
362 Valid: true,
363 }
364 }
365
366 params := database.GetChatsParams{
367 OwnedOnly: true,
368 ViewerID: apiKey.UserID,
369 Archived: searchParams.Archived,
370 AfterID: paginationParams.AfterID,
371 LabelFilter: labelFilter,
372 DiffURL: searchParams.DiffURL,
373 TitleQuery: searchParams.TitleQuery,
374 HasUnread: searchParams.HasUnread,
375 PullRequestStatuses: searchParams.PullRequestStatuses,
376 PrNumber: searchParams.PrNumber,
377 RepoQuery: searchParams.RepoQuery,

Callers

nothing calls this directly

Calls 12

APIKeyFunction · 0.92
ChatsFunction · 0.92
WriteFunction · 0.92
ChatRowsWithChildrenFunction · 0.92
ParsePaginationFunction · 0.85
ContextMethod · 0.65
GetMethod · 0.65
GetChatsMethod · 0.65
MarshalMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected