[mob] Add method to join public collection

This commit is contained in:
Neeraj Gupta
2025-01-06 11:59:37 +05:30
parent 4d5b44a4c1
commit c38947c14c

View File

@@ -1139,6 +1139,42 @@ class CollectionsService {
}
}
Future<void> joinPublicCollection(
BuildContext context,
int collectionID,
) async {
try {
final authToken = await getSharedPublicAlbumToken(collectionID);
final jwtToken = await getSharedPublicAlbumTokenJWT(collectionID);
final key = await getSharedPublicAlbumKey(collectionID);
if (key.isEmpty) {
throw Exception("Collection key not found");
}
final encryptedKey = CryptoUtil.sealSync(
getCollectionKey(collectionID),
CryptoUtil.base642bin(
Configuration.instance.getKeyAttributes()!.publicKey,
),
);
await _enteDio.post(
"/collections/join-link",
data: {
"collectionID": collectionID,
"encryptedKey": CryptoUtil.bin2base64(encryptedKey),
},
options: Options(
headers: {
"X-Auth-Access-Token": authToken,
"X-Auth-JWT-Token": jwtToken,
},
),
);
} catch (e) {
_logger.warning("Failed to join public collection $e");
await showGenericErrorDialog(context: context, error: e);
}
}
Future<String> getSharedPublicAlbumKey(int collectionID) async {
if (_cachedPublicAlbumKey.containsKey(collectionID)) {
return _cachedPublicAlbumKey[collectionID]!;