@@ -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" ;
913import type { TimelineReaction } from "@/features/messages/types" ;
1014import type {
1115 Channel ,
@@ -18,6 +22,7 @@ import { resolveMentionProps } from "@/shared/lib/resolveMentionNames";
1822
1923export type InboxFilter =
2024 | "all"
25+ | "project"
2126 | "mention"
2227 | "thread"
2328 | "needs_action"
@@ -29,10 +34,10 @@ export type InboxFilter =
2934export 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(
242273export 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
302341function 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 */
312361export 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+
320386function 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 ,
0 commit comments