Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ggurdin committed Dec 11, 2023
2 parents e3e859c + 710ed42 commit 3f44ced
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 65 deletions.
4 changes: 3 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3951,5 +3951,7 @@
},
"freeTrialDesc": "New users recieve a one week free trial of Pangea Chat",
"activateTrial": "Activate Trial",
"inNoSpaces": "You are not a member of any classes or exchanges"
"inNoSpaces": "You are not a member of any classes or exchanges",
"successfullySubscribed": "You have successfully subscribed!",
"clickToManageSubscription": "Click here to manage your subscription."
}
38 changes: 24 additions & 14 deletions lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:uni_links/uni_links.dart';

// Project imports:
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat_list/chat_list_view.dart';
Expand All @@ -24,20 +14,30 @@ import 'package:fluffychat/pangea/utils/add_to_space.dart';
import 'package:fluffychat/pangea/utils/chat_list_handle_space_tap.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/utils/firebase_analytics.dart';
import 'package:fluffychat/pangea/widgets/subscription/subscription_snackbar.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/tor_stub.dart'
if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:uni_links/uni_links.dart';

import '../../../utils/account_bundles.dart';
import '../../utils/matrix_sdk_extensions/matrix_file_extension.dart';
import '../../utils/url_launcher.dart';
import '../../utils/voip/callkeep_manager.dart';
import '../../widgets/fluffy_chat_app.dart';
import '../../widgets/matrix.dart';

import 'package:fluffychat/utils/tor_stub.dart'
if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart';

enum SelectMode {
normal,
share,
Expand Down Expand Up @@ -445,6 +445,7 @@ class ChatListController extends State<ChatList>
//#Pangea
StreamSubscription? classStream;
StreamSubscription? _invitedSpaceSubscription;
StreamSubscription? _subscriptionStatusStream;
//Pangea#

@override
Expand Down Expand Up @@ -502,6 +503,14 @@ class ChatListController extends State<ChatList>
}
}
});

_subscriptionStatusStream = pangeaController
.subscriptionController.subscriptionStream.stream
.listen((event) {
if (mounted) {
showSubscribedSnackbar(context);
}
});
//Pangea#

super.initState();
Expand All @@ -515,6 +524,7 @@ class ChatListController extends State<ChatList>
//#Pangea
classStream?.cancel();
_invitedSpaceSubscription?.cancel();
_subscriptionStatusStream?.cancel();
//Pangea#
scrollController.removeListener(_onScroll);
super.dispose();
Expand Down
11 changes: 8 additions & 3 deletions lib/pangea/controllers/subscription_controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';

// Package imports:
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/controllers/base_controller.dart';
Expand All @@ -15,7 +14,6 @@ import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:fluffychat/pangea/utils/firebase_analytics.dart';
import 'package:fluffychat/pangea/widgets/subscription/subscription_paywall.dart';
import 'package:fluffychat/utils/platform_infos.dart';
// Project imports:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand All @@ -29,6 +27,7 @@ class SubscriptionController extends BaseController {

//convert this logic to use completer
bool initialized = false;
final StreamController subscriptionStream = StreamController.broadcast();

SubscriptionController(PangeaController pangeaController) : super() {
_pangeaController = pangeaController;
Expand Down Expand Up @@ -67,7 +66,13 @@ class SubscriptionController extends BaseController {

if (!kIsWeb) {
Purchases.addCustomerInfoUpdateListener(
(CustomerInfo info) => updateCustomerInfo(),
(CustomerInfo info) async {
final bool wasSubscribed = isSubscribed;
await updateCustomerInfo();
if (!wasSubscribed && isSubscribed) {
subscriptionStream.add(true);
}
},
);
}
setState();
Expand Down
12 changes: 12 additions & 0 deletions lib/pangea/pages/settings_subscription/settings_subscription.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import 'dart:async';

// Project imports:
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/config/environment.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
import 'package:fluffychat/pangea/pages/settings_subscription/settings_subscription_view.dart';
import 'package:fluffychat/pangea/utils/subscription_app_id.dart';
import 'package:fluffychat/pangea/widgets/subscription/subscription_snackbar.dart';
import 'package:fluffychat/widgets/matrix.dart';
// Project imports:
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
// Package imports:
import 'package:url_launcher/url_launcher_string.dart';

class SubscriptionManagement extends StatefulWidget {
Expand All @@ -23,6 +27,7 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {
final PangeaController pangeaController = MatrixState.pangeaController;
SubscriptionDetails? selectedSubscription;
late StreamSubscription _settingsSubscription;
StreamSubscription? _subscriptionStatusStream;

@override
void initState() {
Expand All @@ -39,6 +44,7 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {
void dispose() {
super.dispose();
_settingsSubscription.cancel();
_subscriptionStatusStream?.cancel();
}

bool get currentSubscriptionAvailable =>
Expand Down Expand Up @@ -119,6 +125,12 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {

@override
Widget build(BuildContext context) {
_subscriptionStatusStream ??= pangeaController
.subscriptionController.subscriptionStream.stream
.listen((_) {
showSubscribedSnackbar(context);
context.go('/rooms');
});
return SettingsSubscriptionView(this);
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/pangea/widgets/subscription/subscription_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
import 'package:flutter/material.dart';
// Package imports:
import 'package:flutter_gen/gen_l10n/l10n.dart';

class SubscriptionOptions extends StatelessWidget {
Expand Down Expand Up @@ -75,7 +76,11 @@ class SubscriptionCard extends StatelessWidget {
OutlinedButton(
onPressed: () {
pangeaController.subscriptionController
.submitSubscriptionChange(subscription, context);
.submitSubscriptionChange(
subscription,
context,
);
Navigator.of(context).pop();
},
child: Text(L10n.of(context)!.subscribe),
),
Expand Down
34 changes: 34 additions & 0 deletions lib/pangea/widgets/subscription/subscription_snackbar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:fluffychat/config/app_config.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';

void showSubscribedSnackbar(BuildContext context) {
final Widget text = RichText(
text: TextSpan(
children: [
TextSpan(
text: L10n.of(context)!.successfullySubscribed,
style: TextStyle(
color: Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.black,
),
),
const TextSpan(text: " "),
TextSpan(
text: L10n.of(context)!.clickToManageSubscription,
style: const TextStyle(color: AppConfig.primaryColor),
recognizer: TapGestureRecognizer()
..onTap = () => context.go('/rooms/settings/subscription'),
),
],
),
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: text,
),
);
}
Loading

0 comments on commit 3f44ced

Please sign in to comment.