Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sentry updates #165

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pages/chat_list/chat_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
32 changes: 26 additions & 6 deletions lib/pangea/controllers/subscription_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(
Expand All @@ -64,8 +83,6 @@ class SubscriptionController extends BaseController {
setNewUserTrial();
}

initialized = true;

if (!kIsWeb) {
Purchases.addCustomerInfoUpdateListener(
(CustomerInfo info) async {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -234,7 +254,7 @@ class SubscriptionController extends BaseController {
}

bool get _shouldShowPaywall {
return initialized &&
return initialized.isCompleted &&
!isSubscribed &&
(_lastDismissedPaywall == null ||
DateTime.now().difference(_lastDismissedPaywall!).inHours >
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 5 additions & 7 deletions lib/pangea/models/mobile_subscriptions.dart
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/pangea/models/pangea_message_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class PangeaMessageEvent {
BuildContext context,
) async {
final String text = (await representationByLanguageGlobal(
context: context,
langCode: langCode,
))
?.text ??
Expand Down Expand Up @@ -399,7 +398,6 @@ class PangeaMessageEvent {
}

Future<PangeaRepresentation?> representationByLanguageGlobal({
required BuildContext context,
required String langCode,
}) async {
// try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {

@override
void initState() {
if (!subscriptionController.initialized) {
if (!subscriptionController.initialized.isCompleted) {
subscriptionController.initialize().then((_) => setState(() {}));
}

Expand Down
15 changes: 7 additions & 8 deletions lib/pangea/utils/get_chat_list_item_subtitle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ 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';

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);

Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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;
}
}
}
1 change: 0 additions & 1 deletion lib/pangea/widgets/chat/message_translation_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {

if (repEvent == null && mounted) {
repEvent = await widget.messageEvent.representationByLanguageGlobal(
context: context,
langCode: langCode,
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/pangea/widgets/igc/pangea_rich_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class PangeaRichTextState extends State<PangeaRichText> {

widget.pangeaMessageEvent
.representationByLanguageGlobal(
context: context,
langCode: widget.pangeaMessageEvent.messageDisplayLangCode,
)
.onError((error, stackTrace) => ErrorHandler.logError())
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading