π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Handle cast revocation review feedback
ashil-pilot309b646314b6
diff --git a/mobile/apps/photos/lib/ui/cast/cast.dart b/mobile/apps/photos/lib/ui/cast/cast.dartindex b708e83d9d..63d62c3288 100644--- a/mobile/apps/photos/lib/ui/cast/cast.dart+++ b/mobile/apps/photos/lib/ui/cast/cast.dart@@ -28,38 +28,35 @@ Future<void> showCastSheet(final showAutoPair = service.isSupported;final logger = Logger("showCastSheet");if (!flagService.enableMultiCast) {- if (service.getActiveSessions().isNotEmpty) {+ final shouldStop = service.getActiveSessions().isNotEmpty;+ if (shouldStop) {final result = await showChoiceDialog(context,title: l10n.stopCastingTitle,body: l10n.stopCastingBody,firstButtonLabel: l10n.yes,secondButtonLabel: l10n.no,- firstButtonOnTap: () async {- await gw.revokeAllTokens();- await service.closeActiveCasts();- },);- if (result?.action == ButtonAction.error && context.mounted) {- await showGenericErrorDialog(- context: context,- error: result?.exception,- );+ if (result?.action != ButtonAction.first || !context.mounted) {+ return;}- return;}final dialog = createProgressDialog(context, l10n.pleaseWait);await dialog.show();try {await gw.revokeAllTokens();+ if (shouldStop) {+ await service.closeActiveCasts();+ }await dialog.hide();} catch (e, s) {await dialog.hide();- logger.severe("Failed to revoke cast tokens before pairing", e, s);+ logger.severe("Failed to revoke or stop cast sessions", e, s);if (!context.mounted) return;await showGenericErrorDialog(context: context, error: e);return;}+ if (shouldStop) return;}List<CastInfo> sessions = [];if (flagService.enableMultiCast) {diff --git a/mobile/apps/photos/lib/ui/cast/pair_with_code.dart b/mobile/apps/photos/lib/ui/cast/pair_with_code.dartindex 117baa2ec6..c4ae6b9196 100644--- a/mobile/apps/photos/lib/ui/cast/pair_with_code.dart+++ b/mobile/apps/photos/lib/ui/cast/pair_with_code.dart@@ -20,9 +20,6 @@ Future<void> _pairWithCode(String code,) async {final gw = CastGateway(NetworkClient.instance.enteDio);- if (!flagService.enableMultiCast) {- await gw.revokeAllTokens();- }final publicKeys = await gw.getPublicKeys(code);if (publicKeys == null) {throw const _DeviceNotFoundException();@@ -40,6 +37,7 @@ Future<void> _pairWithCode();}+// The parent cast sheet revokes old single-cast sessions before offering pairing.Future<bool?> showPairWithCodeSheet(BuildContext context,Collection collection,diff --git a/mobile/apps/photos/test/ui/cast/cast_test.dart b/mobile/apps/photos/test/ui/cast/cast_test.dartindex 497129a01f..3438c37657 100644--- a/mobile/apps/photos/test/ui/cast/cast_test.dart+++ b/mobile/apps/photos/test/ui/cast/cast_test.dart@@ -4,6 +4,7 @@ import "package:ente_strings/ente_strings.dart";import "package:flutter/material.dart";import "package:flutter_test/flutter_test.dart";import "package:package_info_plus/package_info_plus.dart";+import "package:photos/core/network/network.dart";import "package:photos/ente_theme_data.dart";import "package:photos/gateways/cast/cast_gateway.dart";import "package:photos/models/collection/collection.dart";@@ -41,14 +42,29 @@ void main() {final transport = _FakeCastService(hasActiveSession: true);await _pumpCastButton(tester, requests, transport);+ await tester.tap(find.text("Cast"));+ await tester.pumpAndSettle();+ await tester.tap(find.text("No"));+ await tester.pumpAndSettle();+ expect(requests.pending, isEmpty);+ expect(transport.closeCount, 0);+await tester.tap(find.text("Cast"));await tester.pumpAndSettle();await tester.tap(find.text("Yes"));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));await tester.pump(const Duration(seconds: 1));expect(requests.pending, hasLength(1));expect(transport.closeCount, 0);- expect(find.text("Stop casting"), findsOneWidget);+ expect(find.text("No"), findsNothing);+ expect(find.text("Please wait..."), findsOneWidget);++ await tester.binding.handlePopRoute();+ await tester.tapAt(const Offset(10, 10));+ await tester.pump(const Duration(milliseconds: 300));+ expect(find.text("Please wait..."), findsOneWidget);requests.fail();await tester.pumpAndSettle();@@ -60,6 +76,8 @@ void main() {await tester.tap(find.text("Cast"));await tester.pumpAndSettle();await tester.tap(find.text("Yes"));+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));await tester.pump(const Duration(seconds: 1));expect(transport.closeCount, 0);@@ -99,6 +117,21 @@ void main() {expect(find.text("Auto pair"), findsOneWidget);expect(find.text("Pair using code"), findsOneWidget);expect(transport.closeCount, 0);++ await tester.tap(find.text("Pair using code"));+ await tester.pumpAndSettle();+ await tester.enterText(find.byType(TextField), "ABC123");+ await tester.tap(find.text("Pair"));+ await tester.pump(const Duration(seconds: 1));+ expect(requests.pending, hasLength(1));+ expect(requests.pending.single.$1.method, "GET");+ expect(requests.pending.single.$1.path, "/cast/device-info/ABC123");+ requests.fail();+ await tester.pump();+ await tester.pump(const Duration(milliseconds: 300));+ expect(find.text("Error"), findsOneWidget);+ await tester.tap(find.text("OK"));+ await tester.pumpAndSettle();});}@@ -107,6 +140,9 @@ Future<void> _pumpCastButton(_RevocationRequests requests,CastService transport,) async {+ final originalNetworkClient = NetworkClient.instance;+ NetworkClient.instance = _FakeNetworkClient(requests.dio);+ addTearDown(() => NetworkClient.instance = originalNetworkClient);await tester.pumpWidget(MaterialApp(theme: lightThemeData,@@ -137,8 +173,6 @@ class _RevocationRequests {dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) {- expect(options.method, "DELETE");- expect(options.path, "/cast/revoke-all-tokens");pending.add((options, handler));},),@@ -182,3 +216,10 @@ class _FakeCastService extends Fake implements CastService {}class _FakeCollection extends Fake implements Collection {}++class _FakeNetworkClient extends Fake implements NetworkClient {+ @override+ final Dio enteDio;++ _FakeNetworkClient(this.enteDio);+}