Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -149,7 +149,6 @@ export type AreTypeEqual<A, B> = A extends B ? (B extends A ? true : false) : fa

// @beta
export interface AttachmentDownloadResult {
attachmentId: string;
blobUrl: string;
}

Expand Down Expand Up @@ -990,8 +989,8 @@ export interface CallWithChatAdapterManagement {
disposeStreamView(remoteUserId?: string, options?: VideoStreamOptions): Promise<void>;
// (undocumented)
downloadAttachments: (options: {
attachmentUrls: Record<string, string>;
}) => Promise<AttachmentDownloadResult[]>;
attachmentUrl: string;
}) => Promise<AttachmentDownloadResult>;
fetchInitialData(): Promise<void>;
// @beta
holdCall: () => Promise<void>;
Expand Down Expand Up @@ -1604,8 +1603,8 @@ export interface ChatAdapterThreadManagement {
deleteMessage(messageId: string): Promise<void>;
// (undocumented)
downloadAttachments: (options: {
attachmentUrls: Record<string, string>;
}) => Promise<AttachmentDownloadResult[]>;
attachmentUrl: string;
}) => Promise<AttachmentDownloadResult>;
fetchInitialData(): Promise<void>;
loadPreviousChatMessages(messagesToLoad: number): Promise<boolean>;
removeParticipant(userId: string): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export type AnnouncerProps = {

// @beta
export interface AttachmentDownloadResult {
Comment thread
emlynmac marked this conversation as resolved.
attachmentId: string;
blobUrl: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ export type AttachmentMetadata =
* @beta
*/
export interface AttachmentDownloadResult {
/**
* Unique ID of the attachment.
*/
attachmentId: string;
/**
* Blob URL for the attachment.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@ export interface CallWithChatAdapterManagement {
disposeStreamView(remoteUserId?: string, options?: VideoStreamOptions): Promise<void>;
// (undocumented)
downloadAttachments: (options: {
attachmentUrls: Record<string, string>;
}) => Promise<AttachmentDownloadResult[]>;
attachmentUrl: string;
}) => Promise<AttachmentDownloadResult>;
fetchInitialData(): Promise<void>;
// @beta
holdCall: () => Promise<void>;
Expand Down Expand Up @@ -1118,8 +1118,8 @@ export interface ChatAdapterThreadManagement {
deleteMessage(messageId: string): Promise<void>;
// (undocumented)
downloadAttachments: (options: {
attachmentUrls: Record<string, string>;
}) => Promise<AttachmentDownloadResult[]>;
attachmentUrl: string;
}) => Promise<AttachmentDownloadResult>;
fetchInitialData(): Promise<void>;
loadPreviousChatMessages(messagesToLoad: number): Promise<boolean>;
removeParticipant(userId: string): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class AzureCommunicationCallWithChatAdapter implements CallWithChatAdapte
this.chatAdapter.updateFileUploadMetadata(id, metadata);
};
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
async downloadAttachments(options: { attachmentUrls: Record<string, string> }): Promise<AttachmentDownloadResult[]> {
async downloadAttachments(options: { attachmentUrl: string }): Promise<AttachmentDownloadResult> {
Comment thread
emlynmac marked this conversation as resolved.
Outdated
return await this.chatAdapter.downloadAttachments(options);
}
/* @conditional-compile-remove(PSTN-calls) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export interface CallWithChatAdapterManagement {
/** @beta */
updateFileUploadMetadata: (id: string, metadata: AttachmentMetadata) => void;
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
downloadAttachments: (options: { attachmentUrls: Record<string, string> }) => Promise<AttachmentDownloadResult[]>;
downloadAttachments: (options: { attachmentUrl: string }) => Promise<AttachmentDownloadResult>;
Comment thread
emlynmac marked this conversation as resolved.
Outdated
/* @conditional-compile-remove(PSTN-calls) */
/**
* Puts the Call in a Localhold.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ export class CallWithChatBackedChatAdapter implements ChatAdapter {
};

/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
public async downloadAttachments(options: {
attachmentUrls: Record<string, string>;
}): Promise<AttachmentDownloadResult[]> {
public async downloadAttachments(options: { attachmentUrl: string }): Promise<AttachmentDownloadResult> {
return await this.callWithChatAdapter.downloadAttachments(options);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ export const ChatScreen = (props: ChatScreenProps): JSX.Element => {

if (attachment.attachmentType === 'inlineImage' && attachment.url) {
// TBD: Need to begin investigating how to download HQ images.
const blob = await adapter.downloadAttachments({ attachmentUrls: { [attachment.id]: attachment.url } });
if (blob[0]) {
const blobUrl = blob[0].blobUrl;
const blob = await adapter.downloadAttachments({ attachmentUrl: attachment.url });
if (blob) {
const blobUrl = blob.blobUrl;
setFullSizeAttachments((prev) => ({ ...prev, [attachment.id]: blobUrl }));
setGalleryImages([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('Error is reflected in state and events', () => {
const adapter = await createChatAdapterWithStubs(new StubChatClient(threadClient));
const errorListener = new ErrorListener(adapter);

await expect(adapter.downloadAttachments({ attachmentUrls: { ['somefakeid']: 'somefakeurl' } })).rejects.toThrow();
await expect(adapter.downloadAttachments({ attachmentUrl: 'somefakeurl' })).rejects.toThrow();
expect(errorListener.errors.length).toBe(1);
expect(errorListener.errors[0].target).toBe('ChatThreadClient.getMessage');
expect(errorListener.errors[0].innerError.message).toBe('AccessToken is null');
Expand All @@ -192,9 +192,7 @@ describe('Error is reflected in state and events', () => {
const adapter = await createChatAdapterWithStubs(new StubChatClient(threadClient), fakeToken);
const errorListener = new ErrorListener(adapter);
{
await expect(
adapter.downloadAttachments({ attachmentUrls: { ['somefakeid']: 'somefakeurl' } })
).rejects.toThrow();
await expect(adapter.downloadAttachments({ attachmentUrl: 'somefakeurl' })).rejects.toThrow();
expect(errorListener.errors.length).toBe(1);
expect(errorListener.errors[0].target).toBe('ChatThreadClient.getMessage');
expect(errorListener.errors[0].innerError.message).toBe('fetch is not defined');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class AzureCommunicationChatAdapter implements ChatAdapter {
}

/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
async downloadAttachments(options: { attachmentUrls: Record<string, string> }): Promise<AttachmentDownloadResult[]> {
async downloadAttachments(options: { attachmentUrl: string }): Promise<AttachmentDownloadResult> {
return this.asyncTeeErrorToEventEmitter(async () => {
if (this.credential === undefined) {
throw new ChatError('ChatThreadClient.getMessage', new Error('AccessToken is null'));
Expand All @@ -348,8 +348,8 @@ export class AzureCommunicationChatAdapter implements ChatAdapter {
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
private async downloadAuthenticatedFile(
accessToken: string,
options: { attachmentUrls: Record<string, string> }
): Promise<AttachmentDownloadResult[]> {
options: { attachmentUrl: string }
): Promise<AttachmentDownloadResult> {
async function fetchWithAuthentication(url: string, token: string): Promise<Response> {
const headers = new Headers();
headers.append('Authorization', `Bearer ${token}`);
Expand All @@ -360,14 +360,10 @@ export class AzureCommunicationChatAdapter implements ChatAdapter {
}
}

const attachmentDownloadResults: AttachmentDownloadResult[] = [];
for (const id in options.attachmentUrls) {
const response = await fetchWithAuthentication(options.attachmentUrls[id], accessToken);
const blob = await response.blob();
attachmentDownloadResults.push({ attachmentId: id, blobUrl: URL.createObjectURL(blob) });
}
const response = await fetchWithAuthentication(options.attachmentUrl, accessToken);
Comment thread
emlynmac marked this conversation as resolved.
const blob = await response.blob();

return attachmentDownloadResults;
return { blobUrl: URL.createObjectURL(blob) };
}

private messageReceivedListener(event: ChatMessageReceivedEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface ChatAdapterThreadManagement {
*/
loadPreviousChatMessages(messagesToLoad: number): Promise<boolean>;
/* @conditional-compile-remove(teams-inline-images-and-file-sharing) */
downloadAttachments: (options: { attachmentUrls: Record<string, string> }) => Promise<AttachmentDownloadResult[]>;
downloadAttachments: (options: { attachmentUrl: string }) => Promise<AttachmentDownloadResult>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ const MessageThreadStory = (args): JSX.Element => {
return Promise.resolve();
};

const onFetchAttachments = async (attachments: AttachmentMetadata[]): Promise<AttachmentDownloadResult[]> => {
const onFetchAttachments = async (attachments: AttachmentMetadata[]): Promise<AttachmentDownloadResult> => {
Comment thread
JoshuaLai marked this conversation as resolved.
Outdated
// Mocking promise
const delay = (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 3000));
return await delay().then(() => {
Expand Down