Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "File Sharing",
"comment": "Add Chat Attachments in Live Messages",
"packageName": "@azure/communication-react",
"email": "109105353+jpeng-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "File Sharing",
"comment": "Add Chat Attachments in Live Messages",
"packageName": "@azure/communication-react",
"email": "109105353+jpeng-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useMemo } from 'react';
import { useLocale } from '../localization';
import { _AttachmentCard } from './AttachmentCard';
import { _AttachmentCardGroup } from './AttachmentCardGroup';
/* @conditional-compile-remove(attachment-download) */
import { getAttachmentCountLiveMessage } from './ChatMessage/ChatMessageContent';
import { _formatString } from '@internal/acs-ui-common';
import { AttachmentMenuAction, AttachmentMetadata } from '../types/Attachment';
import { ChatMessage } from '../types';
Expand Down Expand Up @@ -102,15 +104,12 @@ export const _AttachmentDownloadCards = (props: _AttachmentDownloadCardsProps):

const attachmentCardGroupDescription = useMemo(
() => () => {
const attachmentGroupLocaleString =
props.strings?.attachmentCardGroupMessage ?? localeStrings.attachmentCardGroupMessage;
/* @conditional-compile-remove(attachment-download) @conditional-compile-remove(attachment-upload) */
return _formatString(attachmentGroupLocaleString, {
attachmentCount: `${attachments?.length ?? 0}`
});
return _formatString(attachmentGroupLocaleString, {
attachmentCount: `${attachments?.length ?? 0}`
});
/* @conditional-compile-remove(attachment-download) */
return getAttachmentCountLiveMessage(
attachments ?? [],
props.strings?.attachmentCardGroupMessage ?? localeStrings.attachmentCardGroupMessage
);
return '';
},
[props.strings?.attachmentCardGroupMessage, localeStrings.attachmentCardGroupMessage, attachments]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import LiveMessage from '../Announcer/LiveMessage';
/* @conditional-compile-remove(mention) */
import { defaultOnMentionRender } from './MentionRenderer';
import DOMPurify from 'dompurify';
import { _AttachmentDownloadCardsStrings } from '../AttachmentDownloadCards';
Copy link
Copy Markdown
Member

@Leah-Xia-Microsoft Leah-Xia-Microsoft Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily related to this PR but for @JoshuaLai to confirm, do we still need the type of _AttachmentDownloadCardsStrings and the function of useLocaleStringsTrampoline?

/* @conditional-compile-remove(attachment-download) */
import { AttachmentMetadata } from '../../types';

type ChatMessageContentProps = {
message: ChatMessage;
Expand Down Expand Up @@ -164,9 +167,12 @@ export const BlockedMessageContent = (props: BlockedMessageContentProps): JSX.El
};

const extractContentForAllyMessage = (props: ChatMessageContentProps): string => {
if (props.message.content) {
let attachments = undefined;
/* @conditional-compile-remove(attachment-download) */
attachments = props.message.attachments;
if (props.message.content || attachments) {
Comment thread
jimchou-dev marked this conversation as resolved.
// Replace all <img> tags with 'image' for aria.
const parsedContent = DOMPurify.sanitize(props.message.content, {
const parsedContent = DOMPurify.sanitize(props.message.content ?? '', {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because line 170

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like sanitize can take undefined?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't, it takes string | Node

ALLOWED_TAGS: ['img'],
RETURN_DOM_FRAGMENT: true
});
Expand All @@ -180,6 +186,16 @@ const extractContentForAllyMessage = (props: ChatMessageContentProps): string =>
parsedContent.replaceChild(imageTextNode, child);
});

// Inject attachment names for aria.
if (attachments) {
Comment thread
jpeng-ms marked this conversation as resolved.
let attachmentList = '';
/* @conditional-compile-remove(attachment-download) */
attachmentList = attachmentCardGroupDescription(props);
const attachmentTextNode = document.createElement('div');
attachmentTextNode.innerHTML = ` ${attachmentList} `;
parsedContent.appendChild(attachmentTextNode);
}
Comment thread
jpeng-ms marked this conversation as resolved.

// Strip all html tags from the content for aria.
const message = DOMPurify.sanitize(parsedContent, { ALLOWED_TAGS: [] });
return message;
Expand Down Expand Up @@ -207,6 +223,29 @@ const messageContentAriaText = (props: ChatMessageContentProps): string | undefi
});
};

/* @conditional-compile-remove(attachment-download) */
const attachmentCardGroupDescription = (props: ChatMessageContentProps): string => {
const attachments = props.message.attachments;
return getAttachmentCountLiveMessage(attachments ?? [], props.strings.attachmentCardGroupMessage);
};

/* @conditional-compile-remove(attachment-download) */
/**
* @private
*/
export const getAttachmentCountLiveMessage = (
attachments: AttachmentMetadata[],
attachmentCardGroupMessage: string
): string => {
if (attachments.length === 0) {
return '';
}
return _formatString(attachmentCardGroupMessage, {
attachmentCount: `${attachments.length}`
});
return '';
};

const defaultOnRenderInlineImage = (inlineImage: InlineImage): JSX.Element => {
return (
<img
Expand Down