Skip to content

Commit cb2982b

Browse files
authored
feat(desktop): handle project work from Inbox (#3117)
## Summary Pull requests and issues that mention you now appear as repository-scoped Inbox conversations, so project work can be reviewed without first navigating to Projects. Opening a project item resolves its current canonical state and reuses the existing review, comment, merge, and issue actions. Repository-aware grouping keeps identical event IDs from different repositories separate, while loading, missing-data, and partial-query states avoid exposing stale actions. ### Related issue None found. ### Testing - `node --import ./test-loader.mjs --experimental-strip-types --test src/features/home/lib/projectInbox.test.mjs` — 6 tests passed - `CI=1 pnpm exec playwright test tests/e2e/project-inbox.spec.ts --project=smoke` — passed - Pre-push desktop, mobile, Tauri, and Rust checks — passed --------- Signed-off-by: Thomas Petersen <[email protected]>
1 parent ca5fde1 commit cb2982b

17 files changed

Lines changed: 952 additions & 28 deletions

‎crates/buzz-db/src/feed.rs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ use sqlx::{PgPool, QueryBuilder};
3434
use uuid::Uuid;
3535

3636
use buzz_core::kind::{
37-
KIND_FORUM_COMMENT, KIND_FORUM_POST, KIND_JOB_PROGRESS, KIND_JOB_REQUEST, KIND_JOB_RESULT,
38-
KIND_STREAM_MESSAGE, KIND_STREAM_MESSAGE_V2, KIND_STREAM_REMINDER,
39-
KIND_WORKFLOW_APPROVAL_REQUESTED,
37+
KIND_FORUM_COMMENT, KIND_FORUM_POST, KIND_GIT_ISSUE, KIND_GIT_PR_UPDATE, KIND_GIT_PULL_REQUEST,
38+
KIND_GIT_STATUS_CLOSED, KIND_GIT_STATUS_DRAFT, KIND_GIT_STATUS_MERGED, KIND_GIT_STATUS_OPEN,
39+
KIND_JOB_PROGRESS, KIND_JOB_REQUEST, KIND_JOB_RESULT, KIND_STREAM_MESSAGE,
40+
KIND_STREAM_MESSAGE_V2, KIND_STREAM_REMINDER, KIND_TEXT_NOTE, KIND_WORKFLOW_APPROVAL_REQUESTED,
4041
};
4142
use buzz_core::{CommunityId, StoredEvent};
4243

@@ -103,7 +104,9 @@ fn build_mentions_query(
103104
qb.push(" AND e.deleted_at IS NULL");
104105
qb.push(format!(
105106
" AND e.kind IN ({KIND_STREAM_MESSAGE}, {KIND_STREAM_MESSAGE_V2}, \
106-
{KIND_FORUM_POST}, {KIND_FORUM_COMMENT})"
107+
{KIND_TEXT_NOTE}, {KIND_FORUM_POST}, {KIND_FORUM_COMMENT}, {KIND_GIT_PULL_REQUEST}, \
108+
{KIND_GIT_PR_UPDATE}, {KIND_GIT_ISSUE}, {KIND_GIT_STATUS_OPEN}, \
109+
{KIND_GIT_STATUS_MERGED}, {KIND_GIT_STATUS_CLOSED}, {KIND_GIT_STATUS_DRAFT})"
107110
));
108111
push_visible_channel_filter(&mut qb, "e.channel_id", accessible_channel_ids);
109112
if let Some(s) = since {
@@ -252,7 +255,7 @@ mod tests {
252255
use nostr::{EventBuilder, Keys, Kind, Tag};
253256
use uuid::Uuid;
254257

255-
const TEST_DB_URL: &str = "postgres://buzz:buzz_dev@localhost:5432/buzz";
258+
const TEST_DB_URL: &str = "postgres://buzz:buzz_dev@localhost:5432/buzz"; // sadscan:disable np.postgres.1 -- local test-only credentials
256259

257260
async fn setup_pool() -> PgPool {
258261
let database_url = std::env::var("BUZZ_TEST_DATABASE_URL")
@@ -777,6 +780,12 @@ mod tests {
777780
sql.contains("AND m.community_id = "),
778781
"mentions feed must also bind event_mentions.community_id: {sql}"
779782
);
783+
assert!(
784+
sql.contains(&KIND_GIT_PULL_REQUEST.to_string())
785+
&& sql.contains(&KIND_GIT_ISSUE.to_string())
786+
&& sql.contains(&KIND_TEXT_NOTE.to_string()),
787+
"mentions feed must include Buzz Git roots and comments: {sql}"
788+
);
780789
}
781790

782791
#[test]

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default defineConfig({
9898
"**/inbox-reactions.spec.ts",
9999
"**/send-channel-binding.spec.ts",
100100
"**/project-commit-detail.spec.ts",
101+
"**/project-inbox.spec.ts",
101102
"**/project-pr-review.spec.ts",
102103
"**/persona-model-combobox-screenshots.spec.ts",
103104
"**/drafts-screenshots.spec.ts",

‎desktop/src-tauri/src/commands/messages.rs‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,20 @@ pub async fn get_feed(
6868

6969
// Mentions: messages that reference me via #p.
7070
let mut mention_filter = serde_json::json!({
71-
"kinds": [9, 40002, 1, 45001, 45003],
71+
"kinds": [
72+
9,
73+
40002,
74+
1,
75+
45001,
76+
45003,
77+
buzz_core_pkg::kind::KIND_GIT_PULL_REQUEST,
78+
buzz_core_pkg::kind::KIND_GIT_PR_UPDATE,
79+
buzz_core_pkg::kind::KIND_GIT_ISSUE,
80+
buzz_core_pkg::kind::KIND_GIT_STATUS_OPEN,
81+
buzz_core_pkg::kind::KIND_GIT_STATUS_MERGED,
82+
buzz_core_pkg::kind::KIND_GIT_STATUS_CLOSED,
83+
buzz_core_pkg::kind::KIND_GIT_STATUS_DRAFT,
84+
],
7285
"#p": [my_pubkey],
7386
"limit": cap,
7487
});

‎desktop/src/features/home/lib/inbox.ts‎

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
getThreadReference,
77
isBroadcastReply,
88
} from "@/features/messages/lib/threading";
9+
import {
10+
getProjectInboxReference,
11+
isProjectInboxItem,
12+
} from "@/features/home/lib/projectInbox";
913
import type { TimelineReaction } from "@/features/messages/types";
1014
import type {
1115
Channel,
@@ -18,6 +22,7 @@ import { resolveMentionProps } from "@/shared/lib/resolveMentionNames";
1822

1923
export type InboxFilter =
2024
| "all"
25+
| "project"
2126
| "mention"
2227
| "thread"
2328
| "needs_action"
@@ -29,10 +34,10 @@ export type InboxFilter =
2934
export type InboxItem = {
3035
avatarUrl: string | null;
3136
/**
32-
* Stable conversation identity: `rootId ?? parentId ?? event.id` for the
33-
* thread group. Does NOT change when a new reply advances the representative
34-
* latest event. Use this for lifecycle continuity: scroll gating, draft
35-
* keys, local-reply storage, and selection identity.
37+
* Stable conversation identity: the NIP-10 root for messages, or a
38+
* repository-scoped root for Buzz Git work. Does NOT change when a new reply
39+
* advances the representative latest event. Use this for lifecycle
40+
* continuity: scroll gating, draft keys, local-reply storage, and selection.
3641
*/
3742
conversationId: string;
3843
id: string;
@@ -136,7 +141,33 @@ function diffInDays(from: Date, to: Date) {
136141
);
137142
}
138143

139-
function feedHeadline(item: FeedItem) {
144+
function tagValue(item: FeedItem, name: string) {
145+
return item.tags.find((tag) => tag[0] === name)?.[1]?.trim() || null;
146+
}
147+
148+
function projectRootItem(item: FeedItem, groupItems: readonly FeedItem[]) {
149+
return (
150+
groupItems.find(
151+
(candidate) => candidate.kind === 1618 || candidate.kind === 1621,
152+
) ?? item
153+
);
154+
}
155+
156+
function projectTypeLabel(item: FeedItem) {
157+
if (item.kind === 1618) return "Pull request";
158+
if (item.kind === 1621) return "Issue";
159+
return "Project update";
160+
}
161+
162+
function feedHeadline(item: FeedItem, groupItems: readonly FeedItem[] = []) {
163+
if (isProjectInboxItem(item)) {
164+
const root = projectRootItem(item, groupItems);
165+
return (
166+
(tagValue(root, "subject") ?? root.content.trim().split("\n")[0]) ||
167+
projectTypeLabel(root)
168+
);
169+
}
170+
140171
switch (item.kind) {
141172
case 40007:
142173
return "Reminder";
@@ -242,6 +273,14 @@ function resolveGroupChannel(
242273
export function getInboxTypeLabel(item: InboxItem): InboxTypeLabel {
243274
const channelName = item.channelLabel;
244275

276+
if (item.groupItems.some(isProjectInboxItem)) {
277+
const root = projectRootItem(item.item, item.groupItems);
278+
return {
279+
text: projectTypeLabel(root),
280+
channelLabel: null,
281+
};
282+
}
283+
245284
if (item.item.channelType === "dm") {
246285
return {
247286
text: item.senderLabel ? `DM from ${item.senderLabel}` : "DM",
@@ -300,23 +339,50 @@ function categoryPriority(category: FeedItemCategory) {
300339
}
301340

302341
function getInboxThreadKey(item: FeedItem) {
342+
const projectReference = getProjectInboxReference(item);
343+
if (projectReference) {
344+
return `project:${projectReference.repoAddress}:${projectReference.rootId}`;
345+
}
346+
303347
const thread = getThreadReference(item.tags);
304348
return thread.rootId ?? thread.parentId ?? item.id;
305349
}
306350

351+
function getStableConversationId(item: FeedItem) {
352+
return getInboxItemConversationId(item);
353+
}
354+
307355
/**
308-
* Returns the stable conversation ID for any FeedItem or relay event: the
309-
* NIP-10 root tag id, falling back to parent-reply tag id, then event id.
356+
* Returns the stable conversation ID for any FeedItem or relay event. Buzz Git
357+
* roots include their repository coordinate; messages use the NIP-10 root,
358+
* parent-reply tag, then event id.
310359
* This is the same derivation used by `buildInboxItems` for `conversationId`.
311360
*/
312361
export function getInboxConversationId(
313362
tags: string[][],
314363
eventId: string,
364+
kind?: number,
315365
): string {
366+
if (kind !== undefined) {
367+
const projectReference = getProjectInboxReference({
368+
id: eventId,
369+
kind,
370+
tags,
371+
});
372+
if (projectReference) {
373+
return `project:${projectReference.repoAddress}:${projectReference.rootId}`;
374+
}
375+
}
376+
316377
const thread = getThreadReference(tags);
317378
return thread.rootId ?? thread.parentId ?? eventId;
318379
}
319380

381+
/** Returns the stable conversation identity for a complete Inbox feed item. */
382+
export function getInboxItemConversationId(item: FeedItem) {
383+
return getInboxConversationId(item.tags, item.id, item.kind);
384+
}
385+
320386
function formatInboxTimestamp(unixSeconds: number) {
321387
const date = new Date(unixSeconds * 1_000);
322388
const now = new Date();
@@ -436,7 +502,7 @@ export function buildInboxItems({
436502

437503
group.items.push(item);
438504
group.latestActivityAt = Math.max(group.latestActivityAt, item.createdAt);
439-
if (item.id === threadKey) {
505+
if (item.id === getStableConversationId(item)) {
440506
group.rootItem = item;
441507
}
442508

@@ -447,7 +513,8 @@ export function buildInboxItems({
447513
.sort(
448514
([, left], [, right]) => right.latestActivityAt - left.latestActivityAt,
449515
)
450-
.map(([conversationId, group]) => {
516+
.map(([, group]) => {
517+
const conversationId = getStableConversationId(group.items[0]);
451518
const latestItem = group.items.reduce((latest, current) =>
452519
current.createdAt > latest.createdAt ? current : latest,
453520
);
@@ -461,7 +528,7 @@ export function buildInboxItems({
461528
profiles,
462529
preferResolvedSelfLabel: true,
463530
});
464-
const subject = feedHeadline(item);
531+
const subject = feedHeadline(item, group.items);
465532
const preview = feedPreview(item);
466533
const { mentionNames, mentionPubkeysByName } = resolveMentionProps(
467534
item.tags,

‎desktop/src/features/home/lib/inboxViewHelpers.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type InboxContextMessage,
44
type InboxFilter,
55
} from "@/features/home/lib/inbox";
6+
import { isProjectInboxItem } from "@/features/home/lib/projectInbox";
67
import {
78
getChannelIdFromTags,
89
getThreadReference,
@@ -39,6 +40,12 @@ export function matchesInboxFilter(
3940
);
4041
}
4142

43+
if (filter === "project") {
44+
return [item.item, ...(item.groupItems ?? [])].some(
45+
(groupItem) => groupItem && isProjectInboxItem(groupItem),
46+
);
47+
}
48+
4249
return item.categories.includes(filter);
4350
}
4451

0 commit comments

Comments
 (0)