Skip to content

Commit 82ed831

Browse files
[Chat] Remove AttachmentMetadata (#4217)
* Use resourceCache from adapter state for fullsize image src * Clean full size cache when ImageOverlay is closed * Change files * Duplicate change files for beta release * Update ChatScreen.tsx * Remove cc for stable * Remove the InlineImageMetadata type * Change files * Duplicate change files for beta release * Update storybook removing reference to inline image * Removing and cleaning up Storybook * Clean up storybook reference * Clean up commented code * Remove AttachmentMetadata * Change files * Duplicate change files for beta release * Rename FileMetadata to AttachmentMetadata * Fix stable * Remove attachmentType * Remove attachmentType arg --------- Co-authored-by: JoshuaLai <9044372+JoshuaLai@users.noreply.github.com>
1 parent a2e4e2e commit 82ed831

20 files changed

Lines changed: 97 additions & 126 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "minor",
3+
"area": "improvement",
4+
"workstream": "InlineImage",
5+
"comment": "Remove AttachmentMetadata",
6+
"packageName": "@azure/communication-react",
7+
"email": "107075081+Leah-Xia-Microsoft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "minor",
3+
"area": "improvement",
4+
"workstream": "InlineImage",
5+
"comment": "Remove AttachmentMetadata",
6+
"packageName": "@azure/communication-react",
7+
"email": "107075081+Leah-Xia-Microsoft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

packages/chat-component-bindings/src/messageThreadSelector.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { DEFAULT_DATA_LOSS_PREVENTION_POLICY_URL } from './utils/constants';
2929
import { ACSKnownMessageType } from './utils/constants';
3030
import { updateMessagesWithAttached } from './utils/updateMessagesWithAttached';
3131
/* @conditional-compile-remove(file-sharing) */
32-
import { FileMetadata } from '@internal/react-components';
32+
import { AttachmentMetadata } from '@internal/react-components';
3333
/* @conditional-compile-remove(file-sharing) */
3434
import { ChatAttachmentType } from '@azure/communication-chat';
3535
import { ChatAttachment } from '@azure/communication-chat';
@@ -63,7 +63,7 @@ const memoizedAllConvertChatMessage = memoizeFnAll(
6363
);
6464

6565
/* @conditional-compile-remove(file-sharing) */
66-
const extractAttachedFilesMetadata = (metadata: Record<string, string>): FileMetadata[] => {
66+
const extractAttachedFilesMetadata = (metadata: Record<string, string>): AttachmentMetadata[] => {
6767
const fileMetadata = metadata.fileSharingMetadata;
6868
if (!fileMetadata) {
6969
return [];
@@ -79,18 +79,17 @@ const extractAttachedFilesMetadata = (metadata: Record<string, string>): FileMet
7979
const extractTeamsAttachmentsMetadata = (
8080
attachments: ChatAttachment[]
8181
): {
82-
/* @conditional-compile-remove(file-sharing) */ files: FileMetadata[];
82+
/* @conditional-compile-remove(file-sharing) */ files: AttachmentMetadata[];
8383
} => {
8484
/* @conditional-compile-remove(file-sharing) */
85-
const files: FileMetadata[] = [];
85+
const files: AttachmentMetadata[] = [];
8686
attachments.forEach((attachment) => {
8787
const attachmentType = mapAttachmentType(attachment.attachmentType);
8888
/* @conditional-compile-remove(file-sharing) */
8989
const contentType = extractAttachmentContentTypeFromName(attachment.name);
9090
/* @conditional-compile-remove(file-sharing) */
9191
if (attachmentType === 'file') {
9292
files.push({
93-
attachmentType: attachmentType,
9493
id: attachment.id,
9594
name: attachment.name ?? '',
9695
extension: contentType ?? '',
@@ -140,9 +139,7 @@ const mapAttachmentType = (attachmentType: ChatAttachmentType): AttachmentType =
140139

141140
/* @conditional-compile-remove(file-sharing) */
142141
const extractAttachmentUrl = (attachment: ChatAttachment): string => {
143-
/* @conditional-compile-remove(file-sharing) */
144-
return attachment.attachmentType === 'file' && attachment.previewUrl ? attachment.previewUrl : attachment.url || '';
145-
return attachment.url || '';
142+
return attachment.previewUrl ? attachment.previewUrl : attachment.url || '';
146143
};
147144
const processChatMessageContent = (message: ChatMessageWithStatus): string | undefined => {
148145
let content = message.content?.message;
@@ -212,10 +209,10 @@ const extractAttachmentContentTypeFromName = (name?: string): string => {
212209
const extractAttachmentsMetadata = (
213210
message: ChatMessageWithStatus
214211
): {
215-
/* @conditional-compile-remove(file-sharing) */ files: FileMetadata[];
212+
/* @conditional-compile-remove(file-sharing) */ files: AttachmentMetadata[];
216213
} => {
217214
/* @conditional-compile-remove(file-sharing) */
218-
let files: FileMetadata[] = [];
215+
let files: AttachmentMetadata[] = [];
219216

220217
/* @conditional-compile-remove(file-sharing) */
221218
if (message.metadata) {

packages/communication-react/review/beta/communication-react.api.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,14 @@ export type AreParamEqual<A extends (props: any) => JSX.Element | undefined, B e
149149
export type AreTypeEqual<A, B> = A extends B ? (B extends A ? true : false) : false;
150150

151151
// @beta
152-
export type AttachmentMetadata = FileMetadata;
152+
export interface AttachmentMetadata {
153+
extension: string;
154+
id: string;
155+
name: string;
156+
// (undocumented)
157+
payload?: Record<string, string>;
158+
url: string;
159+
}
153160

154161
// @public
155162
export type AvatarPersonaData = {
@@ -1782,7 +1789,7 @@ export interface ChatMessage extends MessageCommon {
17821789
// (undocumented)
17831790
failureReason?: string;
17841791
// @beta
1785-
files?: FileMetadata[];
1792+
files?: AttachmentMetadata[];
17861793
// (undocumented)
17871794
messageType: 'chat';
17881795
metadata?: Record<string, string>;
@@ -2869,18 +2876,6 @@ export interface FileDownloadError {
28692876
// @beta
28702877
export type FileDownloadHandler = (userId: string, fileMetadata: AttachmentMetadata) => Promise<URL | FileDownloadError>;
28712878

2872-
// @beta
2873-
export interface FileMetadata {
2874-
// (undocumented)
2875-
attachmentType: 'file';
2876-
extension: string;
2877-
id: string;
2878-
name: string;
2879-
// (undocumented)
2880-
payload?: Record<string, string>;
2881-
url: string;
2882-
}
2883-
28842879
// @beta
28852880
export interface FileSharingOptions {
28862881
accept?: string;

packages/communication-react/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ export type {
335335
} from '../../react-components/src';
336336
/* @conditional-compile-remove(file-sharing) */
337337
export type { AttachmentMetadata } from '../../react-components/src';
338-
/* @conditional-compile-remove(file-sharing) */
339-
export type { FileMetadata } from '../../react-components/src';
340338
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
341339
export type { ChatAttachmentType } from '../../react-components/src';
342340
/* @conditional-compile-remove(image-overlay) */

packages/react-components/review/beta/react-components.api.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ export type AnnouncerProps = {
6666
};
6767

6868
// @beta
69-
export type AttachmentMetadata = FileMetadata;
69+
export interface AttachmentMetadata {
70+
extension: string;
71+
id: string;
72+
name: string;
73+
// (undocumented)
74+
payload?: Record<string, string>;
75+
url: string;
76+
}
7077

7178
// @internal
7279
export type _AudioIssue = 'NoLocalAudio' | 'NoRemoteAudio' | 'Echo' | 'AudioNoise' | 'LowVolume' | 'AudioStoppedUnexpectedly' | 'DistortedSpeech' | 'AudioInterruption' | 'OtherIssues';
@@ -467,7 +474,7 @@ export interface ChatMessage extends MessageCommon {
467474
// (undocumented)
468475
failureReason?: string;
469476
// @beta
470-
files?: FileMetadata[];
477+
files?: AttachmentMetadata[];
471478
// (undocumented)
472479
messageType: 'chat';
473480
metadata?: Record<string, string>;
@@ -488,7 +495,7 @@ export const ChatMessageComponentAsRichTextEditBox: (props: ChatMessageComponent
488495
export type ChatMessageComponentAsRichTextEditBoxProps = {
489496
onCancel?: (messageId: string) => void;
490497
onSubmit: (text: string, metadata?: Record<string, string>, options?: {
491-
attachmentMetadata?: FileMetadata[];
498+
attachmentMetadata?: AttachmentMetadata[];
492499
}) => void;
493500
message: ChatMessage;
494501
strings: MessageThreadStrings;
@@ -1198,18 +1205,6 @@ export interface FileDownloadError {
11981205
// @beta
11991206
export type FileDownloadHandler = (userId: string, fileMetadata: AttachmentMetadata) => Promise<URL | FileDownloadError>;
12001207

1201-
// @beta
1202-
export interface FileMetadata {
1203-
// (undocumented)
1204-
attachmentType: 'file';
1205-
extension: string;
1206-
id: string;
1207-
name: string;
1208-
// (undocumented)
1209-
payload?: Record<string, string>;
1210-
url: string;
1211-
}
1212-
12131208
// @internal
12141209
export interface _FileUploadCardsStrings {
12151210
removeFile: string;

packages/react-components/review/stable/react-components.api.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export type AnnouncerProps = {
5656
};
5757

5858
// @beta
59-
export type AttachmentMetadata = FileMetadata;
59+
export interface AttachmentMetadata {
60+
extension: string;
61+
name: string;
62+
url: string;
63+
}
6064

6165
// @public
6266
export interface BaseCustomStyles {
@@ -970,13 +974,6 @@ export interface FileDownloadError {
970974
// @beta
971975
export type FileDownloadHandler = (userId: string, fileMetadata: AttachmentMetadata) => Promise<URL | FileDownloadError>;
972976

973-
// @beta
974-
export interface FileMetadata {
975-
extension: string;
976-
name: string;
977-
url: string;
978-
}
979-
980977
// @internal
981978
export interface _FileUploadCardsStrings {
982979
removeFile: string;

packages/react-components/src/components/ChatMessage/ChatMessageComponentAsEditBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useChatMyMessageStyles } from '../styles/MessageThread.styles';
1515
import { ChatMessage } from '../../types';
1616
import { _FileUploadCards } from '../FileUploadCards';
1717
/* @conditional-compile-remove(file-sharing) */
18-
import { FileMetadata } from '../FileDownloadCards';
18+
import { AttachmentMetadata } from '../FileDownloadCards';
1919
import {
2020
chatMessageFailedTagStyle,
2121
editChatMessageFailedTagStyle,
@@ -38,7 +38,7 @@ export type ChatMessageComponentAsEditBoxProps = {
3838
metadata?: Record<string, string>,
3939
options?: {
4040
/* @conditional-compile-remove(file-sharing) */
41-
attachmentMetadata?: FileMetadata[];
41+
attachmentMetadata?: AttachmentMetadata[];
4242
}
4343
) => void;
4444
message: ChatMessage;

packages/react-components/src/components/ChatMessage/ChatMessageComponentAsRichTextEditBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useChatMyMessageStyles } from '../styles/MessageThread.styles';
1414
import { ChatMessage } from '../../types';
1515
import { _FileUploadCards } from '../FileUploadCards';
1616
/* @conditional-compile-remove(file-sharing) */
17-
import { FileMetadata } from '../FileDownloadCards';
17+
import { AttachmentMetadata } from '../FileDownloadCards';
1818
import { useChatMessageRichTextEditContainerStyles } from '../styles/ChatMessageComponent.styles';
1919
import { MAXIMUM_LENGTH_OF_MESSAGE } from '../utils/SendBoxUtils';
2020
import { getMessageState, onRenderCancelIcon, onRenderSubmitIcon } from '../utils/ChatMessageComponentAsEditBoxUtils';
@@ -34,7 +34,7 @@ export type ChatMessageComponentAsRichTextEditBoxProps = {
3434
metadata?: Record<string, string>,
3535
options?: {
3636
/* @conditional-compile-remove(file-sharing) */
37-
attachmentMetadata?: FileMetadata[];
37+
attachmentMetadata?: AttachmentMetadata[];
3838
}
3939
) => void;
4040
message: ChatMessage;

packages/react-components/src/components/FileDownloadCards.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import React from 'react';
55
import { AttachmentMetadata, _FileDownloadCards } from './FileDownloadCards';
6-
import { FileMetadata } from './FileDownloadCards';
76
import { render, screen } from '@testing-library/react';
87
import { registerIcons } from '@fluentui/react';
98

@@ -19,13 +18,13 @@ describe('FileDownloadCards should be rendered properly', () => {
1918
});
2019

2120
it('should render if it is FileSharingMetadata', async () => {
22-
const metadata = {
21+
const metadata: AttachmentMetadata = {
2322
name: 'MockFileCard',
2423
extension: 'docx',
2524
url: 'mockUrl',
26-
id: 'mockId',
27-
attachmentType: 'file'
28-
} as FileMetadata;
25+
/* @conditional-compile-remove(file-sharing) */
26+
id: 'mockId'
27+
};
2928

3029
const props = {
3130
userId: 'MockUserId',

0 commit comments

Comments
 (0)