diff --git a/mobile/lib/services/collections_service.dart b/mobile/lib/services/collections_service.dart index 38b54af8f0..0943e477cc 100644 --- a/mobile/lib/services/collections_service.dart +++ b/mobile/lib/services/collections_service.dart @@ -1139,6 +1139,42 @@ class CollectionsService { } } + Future 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 getSharedPublicAlbumKey(int collectionID) async { if (_cachedPublicAlbumKey.containsKey(collectionID)) { return _cachedPublicAlbumKey[collectionID]!;