Skip to content

Commit

Permalink
Better handle fast editing of a sent message;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Jan 7, 2025
1 parent 8f3801d commit 8eeaf2a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const useCommunityPeerWebsocket = (
return;
}
isDebug && console.debug('[PeerCommunityWebsocket] Got notification', notification);

if (
(notification.notificationType === 'fileAdded' ||
notification.notificationType === 'fileModified' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export const useCommunityMessage = (props?: {

newChat.fileMetadata.appData.previewThumbnail = uploadResult.previewThumbnail;
newChat.fileMetadata.appData.content.deliveryStatus = CommunityDeliveryStatus.Sent;
// We force set the keyHeader as it's returned from the upload, and needed for fast saves afterwards
// eslint-disable-next-line @typescript-eslint/no-explicit-any
newChat.sharedSecretEncryptedKeyHeader = uploadResult.keyHeader as any;

return newChat;
};
Expand Down Expand Up @@ -268,6 +271,7 @@ export const useCommunityMessage = (props?: {
},
payloads: msg?.fileMetadata.payloads,
},
sharedSecretEncryptedKeyHeader: newMessage.sharedSecretEncryptedKeyHeader,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export const useArticleComposer = ({
},
versionTag: (uploadResult as UploadResult).newVersionTag,
},
// We force set the keyHeader as it's returned from the server, and needed for fast saves afterwards
// We force set the keyHeader as it's returned from the upload, and needed for fast saves afterwards
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sharedSecretEncryptedKeyHeader: (uploadResult as UploadResult).keyHeader as any,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/libs/js-lib/src/peer/peerData/PeerTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ScheduleOptions,
TransferUploadStatus,
} from '../../core/DriveData/Upload/DriveUploadTypes';
import { TargetDrive } from '../../core/core';
import { KeyHeader, TargetDrive } from '../../core/core';

export interface TransitQueryBatchRequest {
queryParams: FileQueryParams;
Expand Down Expand Up @@ -34,4 +34,5 @@ export interface TransitUploadResult {
globalTransitId: string;
targetDrive: TargetDrive;
};
keyHeader: KeyHeader | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const uploadFileOverPeer = async (
aesKey?: Uint8Array | undefined;
axiosConfig?: AxiosRequestConfig;
}
) => {
): Promise<TransitUploadResult | void> => {
isDebug &&
console.debug(
'request',
Expand Down Expand Up @@ -95,7 +95,7 @@ export const uploadFileOverPeer = async (
},
};

const response = await client
const uploadResult = await client
.post<TransitUploadResult>(url, data, config)
.then((response) => {
const recipientStatus = response.data.recipientStatus;
Expand All @@ -116,10 +116,12 @@ export const uploadFileOverPeer = async (
console.debug(
'response',
new URL(`${dotYouClient.getEndpoint()}/transit/sender/files/send'`).pathname,
response
uploadResult
);

return response;
if (!uploadResult) return;
uploadResult.keyHeader = keyHeader;
return uploadResult;
};

export const uploadHeaderOverPeer = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const uploadPost = async <T extends PostContent>(
recipients: [odinId],
};

const result: TransitUploadResult = await uploadFileOverPeer(
const result = await uploadFileOverPeer(
dotYouClient,
transitInstructionSet,
metadata,
Expand Down

0 comments on commit 8eeaf2a

Please sign in to comment.