@@ -170,6 +170,22 @@ function countDistinctInlineCandidates(
170170 return dataCount + seenUrls . size ;
171171}
172172
173+ function countUnrepresentedHtmlAttachmentIds ( attachments : MSTeamsAttachmentLike [ ] ) : number {
174+ const representedIds = new Set < string > ( ) ;
175+ for ( const attachment of attachments ) {
176+ const contentType = normalizeContentType ( attachment . contentType ) ?? "" ;
177+ if ( contentType . startsWith ( "text/html" ) ) {
178+ continue ;
179+ }
180+ const id = attachment . id ?. trim ( ) ;
181+ if ( id ) {
182+ representedIds . add ( id ) ;
183+ }
184+ }
185+ return extractMSTeamsHtmlAttachmentIds ( attachments ) . filter ( ( id ) => ! representedIds . has ( id ) )
186+ . length ;
187+ }
188+
173189export function resolveMSTeamsInboundAttachmentPresentation (
174190 attachments : MSTeamsAttachmentLike [ ] | undefined ,
175191 limits ?: { maxInlineBytes ?: number ; maxInlineTotalBytes ?: number } ,
@@ -181,7 +197,10 @@ export function resolveMSTeamsInboundAttachmentPresentation(
181197 const fileAttachments = list . filter ( isAdvertisedFileAttachment ) ;
182198 const inlinePlaceholderCount = countDistinctInlineCandidates ( list , limits ) ;
183199 const inlineExpectedCount = countDistinctInlineImages ( list ) ;
184- const htmlAttachmentCount = extractMSTeamsHtmlAttachmentIds ( list ) . length ;
200+ // Teams HTML uses <attachment> tags as references. A matching attachment
201+ // entry is the same resource (and may be a card), so count only unmatched
202+ // IDs that need the Graph/Bot Framework hosted-content fallback.
203+ const htmlAttachmentCount = countUnrepresentedHtmlAttachmentIds ( list ) ;
185204 const expectedMediaCount = fileAttachments . length + inlineExpectedCount + htmlAttachmentCount ;
186205 if ( expectedMediaCount === 0 ) {
187206 return { placeholder : "" , expectedMediaCount : 0 } ;
0 commit comments