Skip to content

Commit

Permalink
Added backwards compatibility;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Jan 31, 2025
1 parent 89a04e9 commit 3effee5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
8 changes: 8 additions & 0 deletions packages/mobile/src/hooks/chat/useConversationMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ChatDrive,
ConversationMetadata,
UnifiedConversation,
uploadConversationMetadata,
} from '../../provider/chat/ConversationProvider';
import { useConversation } from './useConversation';
import { insertNewConversation } from './useConversations';
Expand All @@ -25,6 +26,13 @@ export const useConversationMetadata = (props?: { conversationId?: string | unde
conversation: HomebaseFile<UnifiedConversation, ConversationMetadata>;
newMetadata: ConversationMetadata;
}) => {
// Add saving to the conversation metadata file to allow slow migration of the RN app:
try {
await uploadConversationMetadata(dotYouClient, newMetadata);
} catch {
// It's a backwards-compatible change, so we can ignore errors
}

return await uploadLocalMetadataContent(dotYouClient, ChatDrive, conversation, {
...conversation.fileMetadata.localAppData,
content: newMetadata,
Expand Down
57 changes: 47 additions & 10 deletions packages/mobile/src/provider/chat/ConversationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,52 @@ export interface ConversationMetadata {
lastReadTime?: number;
}

export const JOIN_CONVERSATION_COMMAND = 100;
export const JOIN_GROUP_CONVERSATION_COMMAND = 110;
// export const UPDATE_GROUP_CONVERSATION_COMMAND = 111;
/**
* @deprecated Use localAppData instead
*/
export const uploadConversationMetadata = async (
dotYouClient: DotYouClient,
conversation: ConversationMetadata,
onVersionConflict?: () => void
) => {
const serverConversationMetadataFile = await getConversationMetadata(
dotYouClient,
conversation.conversationId
);
if (!serverConversationMetadataFile) {
return;
}

export interface JoinConversationRequest {
conversationId: string;
title: string;
}
const uploadInstructions: UploadInstructionSet = {
storageOptions: {
drive: ChatDrive,
overwriteFileId: serverConversationMetadataFile.fileId,
},
};

export interface JoinGroupConversationRequest extends JoinConversationRequest {
recipients: string[];
}
const payloadJson: string = jsonStringify64({ ...conversation, version: 1 });
const uploadMetadata: UploadFileMetadata = {
versionTag: serverConversationMetadataFile?.fileMetadata.versionTag,
allowDistribution: false,
appData: {
tags: serverConversationMetadataFile.fileMetadata.appData.tags,
uniqueId: serverConversationMetadataFile.fileMetadata.appData.uniqueId,
fileType: CHAT_CONVERSATION_LOCAL_METADATA_FILE_TYPE,
content: payloadJson,
},
isEncrypted: true,
accessControlList: {
requiredSecurityGroup: SecurityGroupType.Owner,
},
};

return await uploadFile(
dotYouClient,
uploadInstructions,
uploadMetadata,
undefined,
undefined,
undefined,
onVersionConflict
);
};

0 comments on commit 3effee5

Please sign in to comment.