Show appropriate error dialog for free users when sharing is disabled
This commit is contained in:
parent
18d293e5b6
commit
6fb07bab27
2 changed files with 58 additions and 14 deletions
|
@ -145,21 +145,27 @@ class CollectionsService {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> share(int collectionID, String email, String publicKey) {
|
||||
Future<void> share(int collectionID, String email, String publicKey) async {
|
||||
final encryptedKey = CryptoUtil.sealSync(
|
||||
getCollectionKey(collectionID), Sodium.base642bin(publicKey));
|
||||
return _dio
|
||||
.post(
|
||||
Configuration.instance.getHttpEndpoint() + "/collections/share",
|
||||
data: {
|
||||
"collectionID": collectionID,
|
||||
"email": email,
|
||||
"encryptedKey": Sodium.bin2base64(encryptedKey),
|
||||
},
|
||||
options: Options(
|
||||
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
)
|
||||
.then((value) => SyncService.instance.syncWithRemote(silently: true));
|
||||
try {
|
||||
await _dio.post(
|
||||
Configuration.instance.getHttpEndpoint() + "/collections/share",
|
||||
data: {
|
||||
"collectionID": collectionID,
|
||||
"email": email,
|
||||
"encryptedKey": Sodium.bin2base64(encryptedKey),
|
||||
},
|
||||
options: Options(
|
||||
headers: {"X-Auth-Token": Configuration.instance.getToken()}),
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
if (e.response.statusCode == 402) {
|
||||
throw SharingNotPermittedForFreeAccountsError();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
SyncService.instance.syncWithRemote(silently: true);
|
||||
}
|
||||
|
||||
Future<void> unshare(int collectionID, String email) {
|
||||
|
@ -434,3 +440,5 @@ class AddFilesRequest {
|
|||
@override
|
||||
int get hashCode => collectionID.hashCode ^ files.hashCode;
|
||||
}
|
||||
|
||||
class SharingNotPermittedForFreeAccountsError extends Error {}
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:photos/services/sync_service.dart';
|
|||
import 'package:photos/services/user_service.dart';
|
||||
import 'package:photos/ui/common_elements.dart';
|
||||
import 'package:photos/ui/loading_widget.dart';
|
||||
import 'package:photos/ui/subscription_page.dart';
|
||||
import 'package:photos/utils/dialog_util.dart';
|
||||
import 'package:photos/utils/email_util.dart';
|
||||
import 'package:photos/utils/share_util.dart';
|
||||
|
@ -212,7 +213,42 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
});
|
||||
} catch (e) {
|
||||
await dialog.hide();
|
||||
showGenericErrorDialog(context);
|
||||
if (e is SharingNotPermittedForFreeAccountsError) {
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text("sorry"),
|
||||
content: Text(
|
||||
"sharing is not permitted for free accounts, please subscribe"),
|
||||
actions: [
|
||||
FlatButton(
|
||||
child: Text("subscribe"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return SubscriptionPage();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text("ok"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
} else {
|
||||
showGenericErrorDialog(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue