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

Function ChatRowsWithChildren

coderd/database/db2sdk/db2sdk.go:1979–2011  ·  view source on GitHub ↗

ChatRowsWithChildren converts root chat rows and their child rows into codersdk.Chat values with children embedded under each parent. Both root and child diff statuses are resolved from the shared map.

(
	roots []database.GetChatsRow,
	children []database.GetChildChatsByParentIDsRow,
	diffStatuses map[uuid.UUID]database.ChatDiffStatus,
)

Source from the content-addressed store, hash-verified

1977// into codersdk.Chat values with children embedded under each parent.
1978// Both root and child diff statuses are resolved from the shared map.
1979func ChatRowsWithChildren(
1980 roots []database.GetChatsRow,
1981 children []database.GetChildChatsByParentIDsRow,
1982 diffStatuses map[uuid.UUID]database.ChatDiffStatus,
1983) []codersdk.Chat {
1984 // Group children by parent ID.
1985 childrenByParent := make(map[uuid.UUID][]database.GetChildChatsByParentIDsRow, len(children))
1986 for _, row := range children {
1987 parentID := row.Chat.ParentChatID.UUID
1988 childrenByParent[parentID] = append(childrenByParent[parentID], row)
1989 }
1990
1991 result := make([]codersdk.Chat, len(roots))
1992 for i, row := range roots {
1993 diffStatus, ok := diffStatuses[row.Chat.ID]
1994 if ok {
1995 result[i] = Chat(row.Chat, &diffStatus, nil)
1996 } else {
1997 result[i] = Chat(row.Chat, nil, nil)
1998 if diffStatuses != nil {
1999 emptyDiffStatus := ChatDiffStatus(row.Chat.ID, nil)
2000 result[i].DiffStatus = &emptyDiffStatus
2001 }
2002 }
2003 result[i].HasUnread = row.HasUnread
2004
2005 // Embed child chats.
2006 if childRows, ok := childrenByParent[row.Chat.ID]; ok {
2007 result[i].Children = ChildChatRows(childRows, diffStatuses)
2008 }
2009 }
2010 return result
2011}
2012
2013// ChatDiffStatus converts a database.ChatDiffStatus to a
2014// codersdk.ChatDiffStatus. When status is nil an empty value

Callers 1

listChatsMethod · 0.92

Calls 3

ChildChatRowsFunction · 0.85
ChatFunction · 0.70
ChatDiffStatusFunction · 0.70

Tested by

no test coverage detected