Skip to content
Open
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
2 changes: 1 addition & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ func (q *sqlQuerier) GetAuthorizedChats(ctx context.Context, arg GetChatsParams,
arg.DiffURL,
arg.TitleQuery,
arg.HasUnread,
pq.Array(arg.ChatStatuses),
pq.Array(arg.PullRequestStatuses),
arg.PrNumber,
arg.RepoQuery,
Expand Down
36 changes: 34 additions & 2 deletions coderd/database/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17431,6 +17431,27 @@ func TestGetChatsFilter(t *testing.T) {
unreadNoPR := createRoot("unread no pr")
makeUnread(unreadNoPR.ID)

setStatus := func(chat database.Chat, status database.ChatStatus) {
t.Helper()
_, err := store.UpdateChatStatus(ctx, database.UpdateChatStatusParams{
ID: chat.ID,
Status: status,
})
require.NoError(t, err)
}

// Inbox status is computed from lifecycle status, then unread.
// A running chat with unread messages stays working.
workingUnread := createRoot("working unread chat")
makeUnread(workingUnread.ID)
setStatus(workingUnread, database.ChatStatusRunning)
needsAttention := createRoot("needs attention chat")
setStatus(needsAttention, database.ChatStatusRequiresAction)
failedChat := createRoot("failed chat")
setStatus(failedChat, database.ChatStatusError)
interruptingChat := createRoot("interrupting chat")
setStatus(interruptingChat, database.ChatStatusInterrupting)

// Read chat (message exists but marked read).
readChat := createRoot("read chat")
makeUnread(readChat.ID)
Expand Down Expand Up @@ -17473,11 +17494,13 @@ func TestGetChatsFilter(t *testing.T) {
draftPR.ID, openPR.ID, mergedPR.ID, closedPR.ID,
unreadNoPR.ID, readChat.ID, childParent.ID,
prNumberChat.ID, repoChat.ID, prTitleChat.ID, clearedPR.ID,
workingUnread.ID, needsAttention.ID, failedChat.ID, interruptingChat.ID,
}
noPRRootIDs := []uuid.UUID{
alphaProject.ID, betaProject.ID, gammaUnrelated.ID,
percentComplete.ID, thousandOne.ID, underscoreConfig.ID, hyphenConfig.ID,
unreadNoPR.ID, readChat.ID, childParent.ID, clearedPR.ID,
workingUnread.ID, needsAttention.ID, failedChat.ID, interruptingChat.ID,
}
noPROrOpenRootIDs := append(append([]uuid.UUID{}, noPRRootIDs...),
openPR.ID, prNumberChat.ID, prTitleChat.ID)
Expand Down Expand Up @@ -17511,9 +17534,18 @@ func TestGetChatsFilter(t *testing.T) {
{"PRStatus/NoneAndOpen", database.GetChatsParams{PullRequestStatuses: []string{"none", "open"}}, noPROrOpenRootIDs},

// Unread filter.
{"Unread/MatchesUnread", database.GetChatsParams{HasUnread: sql.NullBool{Bool: true, Valid: true}}, []uuid.UUID{draftPR.ID, unreadNoPR.ID}},
{"Unread/MatchesUnread", database.GetChatsParams{HasUnread: sql.NullBool{Bool: true, Valid: true}}, []uuid.UUID{draftPR.ID, unreadNoPR.ID, workingUnread.ID}},
// HasUnread=false returns chats without unread messages.
{"Unread/ExcludesRead", database.GetChatsParams{HasUnread: sql.NullBool{Bool: false, Valid: true}}, []uuid.UUID{alphaProject.ID, betaProject.ID, gammaUnrelated.ID, percentComplete.ID, thousandOne.ID, underscoreConfig.ID, hyphenConfig.ID, openPR.ID, mergedPR.ID, closedPR.ID, readChat.ID, childParent.ID, prNumberChat.ID, repoChat.ID, prTitleChat.ID, clearedPR.ID}},
{"Unread/ExcludesRead", database.GetChatsParams{HasUnread: sql.NullBool{Bool: false, Valid: true}}, []uuid.UUID{alphaProject.ID, betaProject.ID, gammaUnrelated.ID, percentComplete.ID, thousandOne.ID, underscoreConfig.ID, hyphenConfig.ID, openPR.ID, mergedPR.ID, closedPR.ID, readChat.ID, childParent.ID, prNumberChat.ID, repoChat.ID, prTitleChat.ID, clearedPR.ID, needsAttention.ID, failedChat.ID, interruptingChat.ID}},

// chat_status enum, the same value the sidebar row icon uses.
{"Status/Running", database.GetChatsParams{ChatStatuses: []string{"running"}}, []uuid.UUID{workingUnread.ID}},
{"Status/Interrupting", database.GetChatsParams{ChatStatuses: []string{"interrupting"}}, []uuid.UUID{interruptingChat.ID}},
{"Status/RequiresAction", database.GetChatsParams{ChatStatuses: []string{"requires_action"}}, []uuid.UUID{needsAttention.ID}},
{"Status/Error", database.GetChatsParams{ChatStatuses: []string{"error"}}, []uuid.UUID{failedChat.ID}},
{"Status/Waiting", database.GetChatsParams{ChatStatuses: []string{"waiting"}}, []uuid.UUID{alphaProject.ID, betaProject.ID, gammaUnrelated.ID, percentComplete.ID, thousandOne.ID, underscoreConfig.ID, hyphenConfig.ID, openPR.ID, mergedPR.ID, closedPR.ID, draftPR.ID, unreadNoPR.ID, readChat.ID, childParent.ID, prNumberChat.ID, repoChat.ID, prTitleChat.ID, clearedPR.ID}},
{"Status/RunningAndError", database.GetChatsParams{ChatStatuses: []string{"running", "error"}}, []uuid.UUID{workingUnread.ID, failedChat.ID}},
{"Status/EmptyIsNoOp", database.GetChatsParams{ChatStatuses: nil}, allRootIDs},

// PR number filter.
{"PRNumber/ExactMatch", database.GetChatsParams{PrNumber: 42}, []uuid.UUID{prNumberChat.ID}},
Expand Down
47 changes: 28 additions & 19 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions coderd/database/queries/chats.sql
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,13 @@ WHERE
) = sqlc.narg('has_unread')::boolean
ELSE true
END
-- Filter by the stored chat_status enum, the same value the sidebar
-- row icon uses.
AND CASE
WHEN COALESCE(array_length(@chat_statuses::text[], 1), 0) > 0 THEN
chats_expanded.status::text = ANY(@chat_statuses::text[])
ELSE true
END
-- Filter by pull request status. Unlike the diff_url filter above,
-- this intentionally checks only the root chat's own diff status.
-- Child chats share the same workspace and git branch as their
Expand Down
Loading
Loading