Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6099188
Rename inlineImage / file card types as per internal reviews
emlynmac Nov 30, 2023
f93220a
Update API def
emlynmac Nov 30, 2023
7cb421f
Change files
emlynmac Nov 30, 2023
ad34525
Duplicate change files for beta release
emlynmac Nov 30, 2023
45e1dc4
Update Message object definition for beta
emlynmac Nov 30, 2023
b1341ff
Fix up rendering of inlineImages
emlynmac Nov 30, 2023
129d4eb
Fix up rendering
emlynmac Nov 30, 2023
2c781e7
Update storybook snippets
emlynmac Nov 30, 2023
38cc789
Update files storybook
emlynmac Nov 30, 2023
fb34297
Move file download cards behind feature flag
emlynmac Nov 30, 2023
d0c625b
Update hermetic chat tests
emlynmac Nov 30, 2023
478ced6
Update chat app tests
emlynmac Nov 30, 2023
09850f2
Further updates
emlynmac Nov 30, 2023
fa5a889
Update stable composites API
emlynmac Nov 30, 2023
0c588a8
Put file card test behind conditional compilation
emlynmac Nov 30, 2023
0104ac6
Revert some CC changes in MessageBubble
emlynmac Nov 30, 2023
0b9d923
Update storybook inline images message
emlynmac Nov 30, 2023
3267d14
Cleaner CC updates
emlynmac Nov 30, 2023
0600d9c
Revert to accessing files objects by orignal method
emlynmac Dec 1, 2023
a8feb21
Updates
emlynmac Dec 1, 2023
87fbc0f
Revert previous attempt
emlynmac Dec 1, 2023
4ccf842
Update chat composite renderer
emlynmac Dec 1, 2023
de0bfa1
Merge branch 'main' into emlyn/update-inline-image-names
emlynmac Dec 1, 2023
139388f
Update name of attachedFilesMetadata -> attachmentMetadata
emlynmac Dec 1, 2023
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": "prerelease",
"area": "improvement",
"workstream": "Inline Image and file sharing",
"comment": "Rename inlineImage / file card types as per internal reviews",
"packageName": "@azure/communication-react",
"email": "3941071+emlynmac@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "prerelease",
Comment thread
palatter marked this conversation as resolved.
"area": "improvement",
"workstream": "Inline Image and file sharing",
"comment": "Rename inlineImage / file card types as per internal reviews",
"packageName": "@azure/communication-react",
"email": "3941071+emlynmac@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import { ActiveErrorMessage } from '@internal/react-components';
import { AreEqual } from '@internal/acs-ui-common';
import { AttachmentMetadata } from '@internal/react-components';
import { ChatClientState } from '@internal/chat-stateful-client';
import { ChatThreadClient } from '@azure/communication-chat';
import { Common } from '@internal/acs-ui-common';
import { CommunicationParticipant } from '@internal/react-components';
import { ErrorBar } from '@internal/react-components';
import { FileMetadata } from '@internal/react-components';
import { Message } from '@internal/react-components';
import { MessageThread } from '@internal/react-components';
import { ParticipantList } from '@internal/react-components';
Expand Down Expand Up @@ -49,7 +49,7 @@ export type ChatHandlers = {
onLoadPreviousChatMessages: (messagesToLoad: number) => Promise<boolean>;
onUpdateMessage: (messageId: string, content: string, options?: {
metadata?: Record<string, string>;
attachedFilesMetadata?: FileMetadata[];
attachedFilesMetadata?: AttachmentMetadata[];
}) => Promise<void>;
onDeleteMessage: (messageId: string) => Promise<void>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Common, fromFlatCommunicationIdentifier } from '@internal/acs-ui-common
import { StatefulChatClient } from '@internal/chat-stateful-client';
import { ChatMessage, ChatMessageReadReceipt, ChatThreadClient, SendMessageOptions } from '@azure/communication-chat';
import memoizeOne from 'memoize-one';
import { FileMetadata } from '@internal/react-components';
import { AttachmentMetadata } from '@internal/react-components';

/**
* Object containing all the handlers required for chat components.
Expand All @@ -31,7 +31,7 @@ export type ChatHandlers = {
options?: {
/* @conditional-compile-remove(file-sharing) */
metadata?: Record<string, string>;
attachedFilesMetadata?: FileMetadata[];
attachedFilesMetadata?: AttachmentMetadata[];
}
) => Promise<void>;
onDeleteMessage: (messageId: string) => Promise<void>;
Expand Down Expand Up @@ -64,7 +64,7 @@ export const createDefaultChatHandlers = memoizeOne(
content: string,
options?: {
metadata?: Record<string, string>;
attachedFilesMetadata?: FileMetadata[];
attachedFilesMetadata?: AttachmentMetadata[];
}
) => {
const updatedMetadata = options?.metadata ? { ...options.metadata } : {};
Expand Down
44 changes: 27 additions & 17 deletions packages/chat-component-bindings/src/messageThreadSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { DEFAULT_DATA_LOSS_PREVENTION_POLICY_URL } from './utils/constants';
import { updateMessagesWithAttached } from './utils/updateMessagesWithAttached';

/* @conditional-compile-remove(file-sharing) @conditional-compile-remove(teams-inline-images-and-file-sharing) */
import { FileMetadata, FileMetadataAttachmentType } from '@internal/react-components';
import { FileMetadata, ChatAttachmentType, InlineImageMetadata } from '@internal/react-components';
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
import { AttachmentType, ChatAttachment } from '@azure/communication-chat';

Expand Down Expand Up @@ -74,21 +74,22 @@ const extractAttachedFilesMetadata = (metadata: Record<string, string>): FileMet
};

/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
const extractTeamsAttachmentsMetadata = (attachments: ChatAttachment[]): FileMetadata[] => {
const fileMetadata: FileMetadata[] = [];
const extractTeamsAttachmentsMetadata = (
attachments: ChatAttachment[]
): { files: FileMetadata[]; inlineImages: InlineImageMetadata[] } => {
const files: FileMetadata[] = [];
const inlineImages: InlineImageMetadata[] = [];
attachments.forEach((attachment) => {
const attachmentType = mapAttachmentType(attachment.attachmentType);
if (attachmentType === 'inlineImage') {
fileMetadata.push({
inlineImages.push({
attachmentType: attachmentType,
id: attachment.id,
name: attachment.name ?? '',
extension: attachment.contentType ?? '',
url: extractAttachmentUrl(attachment),
previewUrl: attachment.previewUrl
});
} else if (attachmentType === 'fileSharing') {
fileMetadata.push({
} else if (attachmentType === 'file') {
files.push({
attachmentType: attachmentType,
id: attachment.id,
name: attachment.name ?? '',
Expand All @@ -98,15 +99,15 @@ const extractTeamsAttachmentsMetadata = (attachments: ChatAttachment[]): FileMet
});
}
});
return fileMetadata;
return { files, inlineImages };
};

/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
const mapAttachmentType = (attachmentType: AttachmentType): FileMetadataAttachmentType => {
const mapAttachmentType = (attachmentType: AttachmentType): ChatAttachmentType => {
if (attachmentType === 'teamsImage' || attachmentType === 'teamsInlineImage') {
return 'inlineImage';
} else if (attachmentType === 'file') {
return 'fileSharing';
return 'file';
}
return 'unknown';
};
Expand Down Expand Up @@ -138,20 +139,25 @@ const generateImageAttachmentImgHtml = (attachment: ChatAttachment): string => {
};

/* @conditional-compile-remove(file-sharing) @conditional-compile-remove(teams-inline-images-and-file-sharing) */
const extractFilesMetadata = (message: ChatMessageWithStatus): FileMetadata[] => {
let fileMetadata: FileMetadata[] = [];
const extractAttachmentsMetadata = (
message: ChatMessageWithStatus
): { files: FileMetadata[]; inlineImages: InlineImageMetadata[] } => {
let files: FileMetadata[] = [];
let inlineImages: InlineImageMetadata[] = [];

/* @conditional-compile-remove(file-sharing) */
if (message.metadata) {
fileMetadata = fileMetadata.concat(extractAttachedFilesMetadata(message.metadata));
files = files.concat(extractAttachedFilesMetadata(message.metadata));
}

/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
if (message.content?.attachments) {
fileMetadata = fileMetadata.concat(extractTeamsAttachmentsMetadata(message.content?.attachments));
const teamsAttachments = extractTeamsAttachmentsMetadata(message.content?.attachments);
files = files.concat(teamsAttachments.files);
inlineImages = inlineImages.concat(teamsAttachments.inlineImages);
}

return fileMetadata;
return { files, inlineImages };
};

/* @conditional-compile-remove(data-loss-prevention) */
Expand Down Expand Up @@ -183,6 +189,8 @@ const convertToUiChatMessage = (
isLargeGroup: boolean
): ChatMessage => {
const messageSenderId = message.sender !== undefined ? toFlatCommunicationIdentifier(message.sender) : userId;
/* @conditional-compile-remove(file-sharing) @conditional-compile-remove(teams-inline-images-and-file-sharing) */
const { files, inlineImages } = extractAttachmentsMetadata(message);
return {
messageType: 'chat',
createdOn: message.createdOn,
Expand All @@ -198,7 +206,9 @@ const convertToUiChatMessage = (
mine: messageSenderId === userId,
metadata: message.metadata,
/* @conditional-compile-remove(file-sharing) @conditional-compile-remove(teams-inline-images-and-file-sharing) */
attachedFilesMetadata: extractFilesMetadata(message)
files,
/* @conditional-compile-remove(file-sharing) @conditional-compile-remove(teams-inline-images-and-file-sharing) */
inlineImages
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export interface AttachmentDownloadResult {
blobUrl: string;
}

// @beta
export type AttachmentMetadata = FileMetadata | /* @conditional-compile-remove(teams-inline-images-and-file-sharing) */ InlineImageMetadata;
Comment thread
emlynmac marked this conversation as resolved.

// @public
export type AvatarPersonaData = {
text?: string;
Expand Down Expand Up @@ -227,15 +230,6 @@ export interface BaseCustomStyles {
root?: IStyle;
}

// @beta
export interface BaseFileMetadata {
attachmentType: FileMetadataAttachmentType;
extension: string;
id: string;
name: string;
url: string;
}

// @beta
export interface BlockedMessage extends MessageCommon {
// (undocumented)
Expand Down Expand Up @@ -956,7 +950,7 @@ export interface CallWithChatAdapterManagement {
// @beta (undocumented)
registerActiveFileUploads: (files: File[]) => FileUploadManager[];
// @beta (undocumented)
registerCompletedFileUploads: (metadata: FileMetadata[]) => FileUploadManager[];
registerCompletedFileUploads: (metadata: AttachmentMetadata[]) => FileUploadManager[];
removeParticipant(userId: string): Promise<void>;
// @beta
removeParticipant(participant: CommunicationIdentifier): Promise<void>;
Expand Down Expand Up @@ -988,7 +982,7 @@ export interface CallWithChatAdapterManagement {
// @beta (undocumented)
updateFileUploadErrorMessage: (id: string, errorMessage: string) => void;
// @beta (undocumented)
updateFileUploadMetadata: (id: string, metadata: FileMetadata) => void;
updateFileUploadMetadata: (id: string, metadata: AttachmentMetadata) => void;
// @beta (undocumented)
updateFileUploadProgress: (id: string, progress: number) => void;
updateMessage(messageId: string, content: string, metadata?: Record<string, string>): Promise<void>;
Expand Down Expand Up @@ -1532,7 +1526,7 @@ export interface ChatAdapterThreadManagement {
sendTypingIndicator(): Promise<void>;
setTopic(topicName: string): Promise<void>;
updateMessage(messageId: string, content: string, metadata?: Record<string, string>, options?: {
attachedFilesMetadata?: FileMetadata[];
attachedFilesMetadata?: AttachmentMetadata[];
}): Promise<void>;
}

Expand All @@ -1542,6 +1536,9 @@ export type ChatAdapterUiState = {
fileUploads?: FileUploadsUiState;
};

// @beta
export type ChatAttachmentType = 'file' | /* @conditional-compile-remove(teams-inline-images-and-file-sharing) */ 'inlineImage' | 'unknown';

// @public
export type ChatBaseSelectorProps = {
threadId: string;
Expand Down Expand Up @@ -1649,7 +1646,7 @@ export type ChatHandlers = {
onLoadPreviousChatMessages: (messagesToLoad: number) => Promise<boolean>;
onUpdateMessage: (messageId: string, content: string, options?: {
metadata?: Record<string, string>;
attachedFilesMetadata?: FileMetadata[];
attachedFilesMetadata?: AttachmentMetadata[];
Comment thread
emlynmac marked this conversation as resolved.
Outdated
}) => Promise<void>;
onDeleteMessage: (messageId: string) => Promise<void>;
};
Expand All @@ -1658,8 +1655,6 @@ export type ChatHandlers = {
export interface ChatMessage extends MessageCommon {
// (undocumented)
attached?: MessageAttachedStatus;
// @beta
attachedFilesMetadata?: FileMetadata[];
// (undocumented)
clientMessageId?: string;
// (undocumented)
Expand All @@ -1672,6 +1667,10 @@ export interface ChatMessage extends MessageCommon {
editedOn?: Date;
// (undocumented)
failureReason?: string;
// @beta
files?: FileMetadata[];
// @beta
inlineImages?: InlineImageMetadata[];
// (undocumented)
messageType: 'chat';
metadata?: Record<string, string>;
Expand Down Expand Up @@ -2697,20 +2696,18 @@ export interface FileDownloadError {
}

// @beta
export type FileDownloadHandler = (userId: string, fileMetadata: FileMetadata) => Promise<URL | FileDownloadError>;
export type FileDownloadHandler = (userId: string, fileMetadata: AttachmentMetadata) => Promise<URL | FileDownloadError>;

// @beta
export type FileMetadata = FileSharingMetadata | /* @conditional-compile-remove(teams-inline-images-and-file-sharing) */ ImageFileMetadata;

// @beta (undocumented)
export type FileMetadataAttachmentType = 'fileSharing' | /* @conditional-compile-remove(teams-inline-images-and-file-sharing) */ 'inlineImage' | 'unknown';

// @beta
export interface FileSharingMetadata extends BaseFileMetadata {
export interface FileMetadata {
// (undocumented)
attachmentType: 'fileSharing';
attachmentType: 'file';
extension: string;
id: string;
name: string;
// (undocumented)
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.

Optional: Would be nice to add document of what this payload is about and what are the keys and values.

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.

payload?: Record<string, string>;
url: string;
}

// @beta
Expand All @@ -2730,11 +2727,11 @@ export interface FileUploadAdapter {
// (undocumented)
registerActiveFileUploads: (files: File[]) => FileUploadManager[];
// (undocumented)
registerCompletedFileUploads: (metadata: FileMetadata[]) => FileUploadManager[];
registerCompletedFileUploads: (metadata: AttachmentMetadata[]) => FileUploadManager[];
// (undocumented)
updateFileUploadErrorMessage: (id: string, errorMessage: string) => void;
// (undocumented)
updateFileUploadMetadata: (id: string, metadata: FileMetadata) => void;
updateFileUploadMetadata: (id: string, metadata: AttachmentMetadata) => void;
// (undocumented)
updateFileUploadProgress: (id: string, progress: number) => void;
}
Expand All @@ -2752,7 +2749,7 @@ export type FileUploadHandler = (userId: string, fileUploads: FileUploadManager[
export interface FileUploadManager {
file?: File;
id: string;
notifyUploadCompleted: (metadata: FileMetadata) => void;
notifyUploadCompleted: (metadata: AttachmentMetadata) => void;
notifyUploadFailed: (message: string) => void;
notifyUploadProgressChanged: (value: number) => void;
}
Expand All @@ -2762,7 +2759,7 @@ export interface FileUploadState {
error?: FileUploadError;
filename: string;
id: string;
metadata?: FileMetadata;
metadata?: AttachmentMetadata;
progress: number;
}

Expand Down Expand Up @@ -2871,14 +2868,6 @@ export interface _Identifiers {
videoTile: string;
}

// @beta
export interface ImageFileMetadata extends BaseFileMetadata {
// (undocumented)
attachmentType: 'inlineImage';
// (undocumented)
previewUrl?: string;
}

// @beta
export const ImageGallery: (props: ImageGalleryProps) => JSX.Element;

Expand Down Expand Up @@ -2921,6 +2910,16 @@ export interface IncomingCallState {
startTime: Date;
}

// @beta
export interface InlineImageMetadata {
// (undocumented)
attachmentType: 'inlineImage';
id: string;
// (undocumented)
previewUrl?: string;
url: string;
}

// @public
export type IsCaptionLanguageChangedListener = (event: {
activeCaptionLanguage: string;
Expand Down Expand Up @@ -3150,7 +3149,7 @@ export type MessageThreadProps = {
onLoadPreviousChatMessages?: (messagesToLoad: number) => Promise<boolean>;
onRenderMessage?: (messageProps: MessageProps, messageRenderer?: MessageRenderer) => JSX.Element;
onRenderFileDownloads?: (userId: string, message: ChatMessage) => JSX.Element;
onFetchAttachments?: (attachments: FileMetadata[]) => Promise<AttachmentDownloadResult[]>;
onFetchAttachments?: (attachments: AttachmentMetadata[]) => Promise<AttachmentDownloadResult[]>;
onUpdateMessage?: UpdateMessageCallback;
onCancelEditMessage?: CancelEditCallback;
onDeleteMessage?: (messageId: string) => Promise<void>;
Expand Down Expand Up @@ -4002,7 +4001,7 @@ export interface UnsupportedOperatingSystemStrings {
// @public
export type UpdateMessageCallback = (messageId: string, content: string, options?: {
metadata?: Record<string, string>;
attachedFilesMetadata?: FileMetadata[];
attachedFilesMetadata?: AttachmentMetadata[];
}) => Promise<void>;

// @public
Expand Down
9 changes: 4 additions & 5 deletions packages/communication-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,13 @@ export type {
FileDownloadError
} from '../../react-components/src';
/* @conditional-compile-remove(file-sharing) */ /* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
export type { FileMetadata } from '../../react-components/src';
export type { AttachmentMetadata } from '../../react-components/src';
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
export type {
BaseFileMetadata,
FileMetadataAttachmentType,
ChatAttachmentType,
AttachmentDownloadResult,
FileSharingMetadata,
ImageFileMetadata
FileMetadata,
InlineImageMetadata
} from '../../react-components/src';
/* @conditional-compile-remove(PSTN-calls) */
export type { HoldButtonProps, HoldButtonStrings, VideoTileStrings } from '../../react-components/src';
Expand Down
Loading