@@ -339,6 +339,18 @@ function createSlackSendReceipt(params: {
339339 } ) ;
340340}
341341
342+ function createSlackSendReceiptFromResults (
343+ results : readonly SlackSendResult [ ] ,
344+ threadTs ?: string ,
345+ ) : MessageReceipt {
346+ const receipt = createMessageReceiptFromOutboundResults ( { results, threadId : threadTs } ) ;
347+ const thread = threadTs ? { threadId : threadTs } : { } ;
348+ for ( const [ index , part ] of receipt . parts . entries ( ) ) {
349+ Object . assign ( part , { index, ...thread } ) ;
350+ }
351+ return Object . assign ( receipt , thread ) ;
352+ }
353+
342354function resolveToken ( params : {
343355 explicit ?: string ;
344356 accountId : string ;
@@ -1134,6 +1146,7 @@ async function sendMessageSlackQueuedInner(params: {
11341146 accountId : account . accountId ,
11351147 token : delivery . credential ,
11361148 } ) ;
1149+ const deliveredResults : SlackSendResult [ ] = [ ] ;
11371150 const reportDelivery = async (
11381151 result : SlackSendResult ,
11391152 deliveredBlocks ?: ( Block | KnownBlock ) [ ] ,
@@ -1154,6 +1167,7 @@ async function sendMessageSlackQueuedInner(params: {
11541167 } ,
11551168 }
11561169 : result ;
1170+ deliveredResults . push ( deliveryResult ) ;
11571171 await opts . onDeliveryResult ?.( deliveryResult ) ;
11581172 return deliveryResult ;
11591173 } ;
@@ -1213,7 +1227,6 @@ async function sendMessageSlackQueuedInner(params: {
12131227 orderedBlockDeliveryPlan ?. skipOriginalBlocks
12141228 ? orderedBlockDeliveryPlan
12151229 : undefined ;
1216- const sentMessageIds : string [ ] = [ ] ;
12171230 let lastMessageId = "" ;
12181231 let deliveredChannelId = channelId ;
12191232 let canonicalDeliveredThreadTs : string | undefined ;
@@ -1310,7 +1323,6 @@ async function sendMessageSlackQueuedInner(params: {
13101323 lastMessageId = response . ts ;
13111324 deliveredChannelId = resolvePostedMessageChannelId ( response , deliveredChannelId ) ;
13121325 canonicalDeliveredThreadTs ??= resolvePostedMessageThreadTs ( response ) ;
1313- sentMessageIds . push ( response . ts ) ;
13141326 const deliveredThreadTs =
13151327 resolvePostedMessageThreadTs ( response ) ?? normalizeSlackThreadTsCandidate ( opts . threadTs ) ;
13161328 const fallbackDelivery = await reportDelivery (
@@ -1331,11 +1343,10 @@ async function sendMessageSlackQueuedInner(params: {
13311343 questionDelivery = fallbackDelivery ;
13321344 }
13331345 }
1334- const messageId = lastMessageId ;
13351346 const deliveredThreadTs =
13361347 canonicalDeliveredThreadTs ?? normalizeSlackThreadTsCandidate ( opts . threadTs ) ;
13371348 return {
1338- messageId,
1349+ messageId : lastMessageId ,
13391350 channelId : deliveredChannelId ,
13401351 threadTs : deliveredThreadTs ,
13411352 // Core replaces per-card progress with this aggregate; retain the
@@ -1348,12 +1359,7 @@ async function sendMessageSlackQueuedInner(params: {
13481359 } ,
13491360 }
13501361 : { } ) ,
1351- receipt : createSlackSendReceipt ( {
1352- platformMessageIds : sentMessageIds ,
1353- channelId : deliveredChannelId ,
1354- kind : fallbackMessages . some ( ( message ) => message . blocks ) ? "card" : "text" ,
1355- threadTs : deliveredThreadTs ,
1356- } ) ,
1362+ receipt : createSlackSendReceiptFromResults ( deliveredResults , deliveredThreadTs ) ,
13571363 } ;
13581364 }
13591365 }
@@ -1391,7 +1397,6 @@ async function sendMessageSlackQueuedInner(params: {
13911397 onPlatformSendDispatch : dispatchOnce ,
13921398 ...( delivery . upload ? { auditContext : delivery . upload . auditContext } : { } ) ,
13931399 } ) ;
1394- sentMessageIds . push ( lastMessageId ) ;
13951400 await reportDelivery ( {
13961401 messageId : lastMessageId ,
13971402 channelId,
@@ -1409,8 +1414,7 @@ async function sendMessageSlackQueuedInner(params: {
14091414 }
14101415
14111416 for ( const [ partIndex , chunk ] of chunksToPost . entries ( ) ) {
1412- const carriesPrimaryMessageOptions =
1413- partIndex === 0 && ! opts . mediaUrl && sentMessageIds . length === 0 ;
1417+ const carriesPrimaryMessageOptions = partIndex === 0 && ! opts . mediaUrl ;
14141418 const baseMetadata = carriesPrimaryMessageOptions ? opts . metadata : undefined ;
14151419 // Every post carries its index/count so reconciliation proves the complete
14161420 // logical text send and never mistakes a partial chunk fanout for success.
@@ -1442,7 +1446,6 @@ async function sendMessageSlackQueuedInner(params: {
14421446 lastMessageId = response . ts ;
14431447 deliveredChannelId = resolvePostedMessageChannelId ( response , deliveredChannelId ) ;
14441448 canonicalDeliveredThreadTs ??= resolvePostedMessageThreadTs ( response ) ;
1445- sentMessageIds . push ( response . ts ) ;
14461449 await reportDelivery ( {
14471450 messageId : response . ts ,
14481451 channelId : deliveredChannelId ,
@@ -1458,19 +1461,13 @@ async function sendMessageSlackQueuedInner(params: {
14581461 } ) ;
14591462 }
14601463
1461- const messageId = lastMessageId ;
14621464 const deliveredThreadTs =
14631465 canonicalDeliveredThreadTs ?? normalizeSlackThreadTsCandidate ( opts . threadTs ) ;
14641466 return {
1465- messageId,
1467+ messageId : lastMessageId ,
14661468 channelId : deliveredChannelId ,
14671469 threadTs : deliveredThreadTs ,
1468- receipt : createSlackSendReceipt ( {
1469- platformMessageIds : sentMessageIds ,
1470- channelId : deliveredChannelId ,
1471- kind : opts . mediaUrl ? "media" : "text" ,
1472- threadTs : deliveredThreadTs ,
1473- } ) ,
1470+ receipt : createSlackSendReceiptFromResults ( deliveredResults , deliveredThreadTs ) ,
14741471 } ;
14751472}
14761473/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */
0 commit comments