commit
39e765b57a
9 changed files with 41 additions and 27 deletions
|
|
@ -205,7 +205,7 @@ class ChatListItem extends StatelessWidget {
|
|||
// Future.value(L10n.of(context)!.emptyChat),
|
||||
future: room.lastEvent != null
|
||||
? GetChatListItemSubtitle().getSubtitle(
|
||||
context,
|
||||
L10n.of(context)!,
|
||||
room.lastEvent,
|
||||
MatrixState.pangeaController,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ enum CanSendStatus {
|
|||
class SubscriptionController extends BaseController {
|
||||
late PangeaController _pangeaController;
|
||||
SubscriptionInfo? subscription;
|
||||
|
||||
bool initialized = false;
|
||||
final StreamController subscriptionStream = StreamController.broadcast();
|
||||
|
||||
SubscriptionController(PangeaController pangeaController) : super() {
|
||||
|
|
@ -46,7 +44,28 @@ class SubscriptionController extends BaseController {
|
|||
(subscription!.currentSubscriptionId != null ||
|
||||
subscription!.currentSubscription != null);
|
||||
|
||||
bool _isInitializing = false;
|
||||
Completer<void> initialized = Completer<void>();
|
||||
|
||||
Future<void> initialize() async {
|
||||
if (initialized.isCompleted) return;
|
||||
if (_isInitializing) {
|
||||
await initialized.future;
|
||||
return;
|
||||
}
|
||||
_isInitializing = true;
|
||||
await _initialize();
|
||||
_isInitializing = false;
|
||||
initialized.complete();
|
||||
}
|
||||
|
||||
Future<void> reinitialize() async {
|
||||
initialized = Completer<void>();
|
||||
_isInitializing = false;
|
||||
await initialize();
|
||||
}
|
||||
|
||||
Future<void> _initialize() async {
|
||||
try {
|
||||
if (_pangeaController.matrixState.client.userID == null) {
|
||||
debugPrint(
|
||||
|
|
@ -64,8 +83,6 @@ class SubscriptionController extends BaseController {
|
|||
setNewUserTrial();
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
if (!kIsWeb) {
|
||||
Purchases.addCustomerInfoUpdateListener(
|
||||
(CustomerInfo info) async {
|
||||
|
|
@ -198,6 +215,9 @@ class SubscriptionController extends BaseController {
|
|||
}
|
||||
|
||||
Future<void> updateCustomerInfo() async {
|
||||
if (!initialized.isCompleted) {
|
||||
await initialize();
|
||||
}
|
||||
if (subscription == null) {
|
||||
ErrorHandler.logError(
|
||||
m: "Null subscription info in subscription settings",
|
||||
|
|
@ -234,7 +254,7 @@ class SubscriptionController extends BaseController {
|
|||
}
|
||||
|
||||
bool get _shouldShowPaywall {
|
||||
return initialized &&
|
||||
return initialized.isCompleted &&
|
||||
!isSubscribed &&
|
||||
(_lastDismissedPaywall == null ||
|
||||
DateTime.now().difference(_lastDismissedPaywall!).inHours >
|
||||
|
|
@ -265,7 +285,7 @@ class SubscriptionController extends BaseController {
|
|||
|
||||
Future<void> showPaywall(BuildContext context) async {
|
||||
try {
|
||||
if (!initialized) {
|
||||
if (!initialized.isCompleted) {
|
||||
await initialize();
|
||||
}
|
||||
if (subscription?.availableSubscriptions.isEmpty ?? true) {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:purchases_flutter/purchases_flutter.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/pangea/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/pangea/models/base_subscription_info.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:purchases_flutter/purchases_flutter.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
class MobileSubscriptionInfo extends SubscriptionInfo {
|
||||
MobileSubscriptionInfo({required super.pangeaController}) : super();
|
||||
|
|
@ -119,11 +117,11 @@ class MobileSubscriptionInfo extends SubscriptionInfo {
|
|||
Future<void> setCustomerInfo() async {
|
||||
if (allProducts == null) {
|
||||
ErrorHandler.logError(
|
||||
m: "Null appProducts in setCustomerInfo",
|
||||
m: "Null allProducts in setCustomerInfo",
|
||||
s: StackTrace.current,
|
||||
);
|
||||
debugPrint(
|
||||
"Null appProducts in setCustomerInfo",
|
||||
"Null allProducts in setCustomerInfo",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,6 @@ class PangeaMessageEvent {
|
|||
BuildContext context,
|
||||
) async {
|
||||
final String text = (await representationByLanguageGlobal(
|
||||
context: context,
|
||||
langCode: langCode,
|
||||
))
|
||||
?.text ??
|
||||
|
|
@ -399,7 +398,6 @@ class PangeaMessageEvent {
|
|||
}
|
||||
|
||||
Future<PangeaRepresentation?> representationByLanguageGlobal({
|
||||
required BuildContext context,
|
||||
required String langCode,
|
||||
}) async {
|
||||
// try {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
if (!subscriptionController.initialized) {
|
||||
if (!subscriptionController.initialized.isCompleted) {
|
||||
subscriptionController.initialize().then((_) => setState(() {}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
|||
import 'package:fluffychat/pangea/models/class_model.dart';
|
||||
import 'package:fluffychat/pangea/models/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
|
|
@ -12,16 +11,17 @@ import '../../utils/matrix_sdk_extensions/matrix_locals.dart';
|
|||
|
||||
class GetChatListItemSubtitle {
|
||||
Future<String> getSubtitle(
|
||||
BuildContext context,
|
||||
L10n l10n,
|
||||
Event? event,
|
||||
PangeaController pangeaController,
|
||||
) async {
|
||||
if (event == null) return L10n.of(context)!.emptyChat;
|
||||
if (event == null) return l10n.emptyChat;
|
||||
try {
|
||||
String? eventContextId = event.eventId;
|
||||
if (!event.eventId.isValidMatrixId || event.eventId.sigil != '\$') {
|
||||
eventContextId = null;
|
||||
}
|
||||
|
||||
final Timeline timeline =
|
||||
await event.room.getTimeline(eventContextId: eventContextId);
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ class GetChatListItemSubtitle {
|
|||
!pangeaController.permissionsController
|
||||
.isToolEnabled(ToolSetting.immersionMode, event.room)) {
|
||||
return event.calcLocalizedBody(
|
||||
MatrixLocals(L10n.of(context)!),
|
||||
MatrixLocals(l10n),
|
||||
hideReply: true,
|
||||
hideEdit: true,
|
||||
plaintextBody: true,
|
||||
|
|
@ -71,14 +71,13 @@ class GetChatListItemSubtitle {
|
|||
|
||||
final String? text =
|
||||
(await pangeaMessageEvent.representationByLanguageGlobal(
|
||||
context: context,
|
||||
langCode: l2Code,
|
||||
))
|
||||
?.text;
|
||||
|
||||
final i18n = MatrixLocals(L10n.of(context)!);
|
||||
final i18n = MatrixLocals(l10n);
|
||||
|
||||
if (text == null) return L10n.of(context)!.emptyChat;
|
||||
if (text == null) return l10n.emptyChat;
|
||||
|
||||
if (!event.room.isDirectChat ||
|
||||
event.room.directChatMatrixID != event.room.lastEvent?.senderId) {
|
||||
|
|
@ -95,7 +94,7 @@ class GetChatListItemSubtitle {
|
|||
} catch (e, s) {
|
||||
// debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: e, s: s);
|
||||
return event?.body ?? L10n.of(context)!.emptyChat;
|
||||
return event?.body ?? l10n.emptyChat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
|
||||
if (repEvent == null && mounted) {
|
||||
repEvent = await widget.messageEvent.representationByLanguageGlobal(
|
||||
context: context,
|
||||
langCode: langCode,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ class PangeaRichTextState extends State<PangeaRichText> {
|
|||
|
||||
widget.pangeaMessageEvent
|
||||
.representationByLanguageGlobal(
|
||||
context: context,
|
||||
langCode: widget.pangeaMessageEvent.messageDisplayLangCode,
|
||||
)
|
||||
.onError((error, stackTrace) => ErrorHandler.logError())
|
||||
|
|
|
|||
|
|
@ -344,6 +344,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
// #Pangea
|
||||
if (state == LoginState.loggedIn) {
|
||||
await (await pangeaController.userController.completer).future;
|
||||
await pangeaController.subscriptionController.reinitialize();
|
||||
}
|
||||
String routeDestination;
|
||||
if (state == LoginState.loggedIn) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue