resolve merge conflicts,

This commit is contained in:
ggurdin 2025-11-11 15:16:48 -05:00
commit 98c373f299
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
23 changed files with 833 additions and 307 deletions

View file

@ -5322,5 +5322,9 @@
"failedToLoadFeedback": "Failed to load feedback.",
"activityStatsButtonTooltip": "Activity info",
"allow": "Allow",
"deny": "Deny"
"deny": "Deny",
"enabledRenewal": "Enable Subscription Renewal",
"subscriptionEndsOn": "Subscription Ends On",
"subscriptionRenewsOn": "Subscription Renews On",
"waitForSubscriptionChanges": "Changes to your subscription may take a moment to reflect in the app."
}

View file

@ -327,187 +327,191 @@ class ChatView extends StatelessWidget {
// onDragEntered: controller.onDragEntered,
// onDragExited: controller.onDragExited,
// child: Stack(
body: Stack(
children: <Widget>[
if (accountConfig.wallpaperUrl != null)
Opacity(
opacity: accountConfig.wallpaperOpacity ?? 0.5,
child: ImageFiltered(
imageFilter: ui.ImageFilter.blur(
sigmaX: accountConfig.wallpaperBlur ?? 0.0,
sigmaY: accountConfig.wallpaperBlur ?? 0.0,
),
child: MxcImage(
cacheKey: accountConfig.wallpaperUrl.toString(),
uri: accountConfig.wallpaperUrl,
fit: BoxFit.cover,
height: MediaQuery.sizeOf(context).height,
width: MediaQuery.sizeOf(context).width,
isThumbnail: false,
placeholder: (_) => Container(),
body: SafeArea(
child: Stack(
// Pangea#
children: <Widget>[
if (accountConfig.wallpaperUrl != null)
Opacity(
opacity: accountConfig.wallpaperOpacity ?? 0.5,
child: ImageFiltered(
imageFilter: ui.ImageFilter.blur(
sigmaX: accountConfig.wallpaperBlur ?? 0.0,
sigmaY: accountConfig.wallpaperBlur ?? 0.0,
),
child: MxcImage(
cacheKey: accountConfig.wallpaperUrl.toString(),
uri: accountConfig.wallpaperUrl,
fit: BoxFit.cover,
height: MediaQuery.sizeOf(context).height,
width: MediaQuery.sizeOf(context).width,
isThumbnail: false,
placeholder: (_) => Container(),
),
),
),
),
SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: GestureDetector(
// #Pangea
// onTap: controller.clearSingleSelectedEvent,
// child: ChatEventList(controller: controller),
child: Stack(
children: [
ListenableBuilder(
listenable: controller.timelineUpdateNotifier,
builder: (context, _) {
return ChatEventList(
controller: controller,
);
},
),
ChatViewBackground(
controller.choreographer.itController.open,
),
],
),
// Pangea#
),
),
// #Pangea
// if (controller.showScrollDownButton)
// Divider(
// height: 1,
// color: theme.dividerColor,
// ),
ListenableBuilder(
listenable: controller.scrollController,
builder: (context, _) {
if (controller.scrollController.hasClients &&
controller.scrollController.position.pixels >
0) {
return Divider(
height: 1,
color: theme.dividerColor,
);
} else {
return const SizedBox.shrink();
}
},
),
// Pangea#
if (controller.room.isExtinct)
Container(
margin: EdgeInsets.all(bottomSheetPadding),
width: double.infinity,
child: ElevatedButton.icon(
icon: const Icon(Icons.chevron_right),
label: Text(L10n.of(context).enterNewChat),
onPressed: controller.goToNewRoomAction,
),
)
else if (controller.room.canSendDefaultMessages &&
controller.room.membership == Membership.join)
Container(
margin: EdgeInsets.all(bottomSheetPadding),
constraints: const BoxConstraints(
maxWidth: FluffyThemes.maxTimelineWidth,
),
alignment: Alignment.center,
child: Material(
clipBehavior: Clip.hardEdge,
SafeArea(
child: Column(
children: <Widget>[
Expanded(
child: GestureDetector(
// #Pangea
// color: controller.selectedEvents.isNotEmpty
// ? theme.colorScheme.tertiaryContainer
// : theme.colorScheme.surfaceContainerHigh,
color: theme.colorScheme.surfaceContainerHigh,
// Pangea#
borderRadius: const BorderRadius.all(
Radius.circular(24),
// onTap: controller.clearSingleSelectedEvent,
// child: ChatEventList(controller: controller),
child: Stack(
children: [
ListenableBuilder(
listenable:
controller.timelineUpdateNotifier,
builder: (context, _) {
return ChatEventList(
controller: controller,
);
},
),
ChatViewBackground(
controller.choreographer.itController.open,
),
],
),
child: controller.room.isAbandonedDMRoom == true
? Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(
16,
),
foregroundColor:
theme.colorScheme.error,
),
icon: const Icon(
Icons.archive_outlined,
),
onPressed: controller.leaveChat,
label: Text(
L10n.of(context).leave,
),
),
TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(
16,
),
),
icon: const Icon(
Icons.forum_outlined,
),
onPressed: controller.recreateChat,
label: Text(
L10n.of(context).reopenChat,
),
),
],
)
// #Pangea
// : Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// ReplyDisplay(controller),
// ChatInputRow(controller),
// ChatEmojiPicker(controller),
// ],
// ),
: ChatInputBar(
controller: controller,
padding: bottomSheetPadding,
),
// Pangea#
),
),
],
// #Pangea
// if (controller.showScrollDownButton)
// Divider(
// height: 1,
// color: theme.dividerColor,
// ),
ListenableBuilder(
listenable: controller.scrollController,
builder: (context, _) {
if (controller.scrollController.hasClients &&
controller.scrollController.position.pixels >
0) {
return Divider(
height: 1,
color: theme.dividerColor,
);
} else {
return const SizedBox.shrink();
}
},
),
// Pangea#
if (controller.room.isExtinct)
Container(
margin: EdgeInsets.all(bottomSheetPadding),
width: double.infinity,
child: ElevatedButton.icon(
icon: const Icon(Icons.chevron_right),
label: Text(L10n.of(context).enterNewChat),
onPressed: controller.goToNewRoomAction,
),
)
else if (controller.room.canSendDefaultMessages &&
controller.room.membership == Membership.join)
Container(
margin: EdgeInsets.all(bottomSheetPadding),
constraints: const BoxConstraints(
maxWidth: FluffyThemes.maxTimelineWidth,
),
alignment: Alignment.center,
child: Material(
clipBehavior: Clip.hardEdge,
// #Pangea
// color: controller.selectedEvents.isNotEmpty
// ? theme.colorScheme.tertiaryContainer
// : theme.colorScheme.surfaceContainerHigh,
color: theme.colorScheme.surfaceContainerHigh,
// Pangea#
borderRadius: const BorderRadius.all(
Radius.circular(24),
),
child: controller.room.isAbandonedDMRoom == true
? Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(
16,
),
foregroundColor:
theme.colorScheme.error,
),
icon: const Icon(
Icons.archive_outlined,
),
onPressed: controller.leaveChat,
label: Text(
L10n.of(context).leave,
),
),
TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(
16,
),
),
icon: const Icon(
Icons.forum_outlined,
),
onPressed: controller.recreateChat,
label: Text(
L10n.of(context).reopenChat,
),
),
],
)
// #Pangea
// : Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// ReplyDisplay(controller),
// ChatInputRow(controller),
// ChatEmojiPicker(controller),
// ],
// ),
: ChatInputBar(
controller: controller,
padding: bottomSheetPadding,
),
// Pangea#
),
),
],
),
),
),
// #Pangea
ActivityStatsMenu(controller),
if (controller.room.activitySummary?.summary != null)
ValueListenableBuilder(
valueListenable: controller.hasRainedConfetti,
builder: (context, hasRained, __) {
return hasRained
? const SizedBox()
: StarRainWidget(
showBlast: true,
onFinished: () =>
controller.setHasRainedConfetti(true),
);
},
),
// if (controller.dragging)
// Container(
// color: theme.scaffoldBackgroundColor.withAlpha(230),
// alignment: Alignment.center,
// child: const Icon(
// Icons.upload_outlined,
// size: 100,
// ),
// ),
// Pangea#
],
// #Pangea
ActivityStatsMenu(controller),
if (controller.room.activitySummary?.summary != null)
ValueListenableBuilder(
valueListenable: controller.hasRainedConfetti,
builder: (context, hasRained, __) {
return hasRained
? const SizedBox()
: StarRainWidget(
showBlast: true,
onFinished: () =>
controller.setHasRainedConfetti(true),
);
},
),
// if (controller.dragging)
// Container(
// color: theme.scaffoldBackgroundColor.withAlpha(230),
// alignment: Alignment.center,
// child: const Icon(
// Icons.upload_outlined,
// size: 100,
// ),
// ),
// Pangea#
],
),
),
);
},

View file

@ -525,7 +525,6 @@ class ChatListController extends State<ChatList>
//#Pangea
StreamSubscription? _invitedSpaceSubscription;
StreamSubscription? _subscriptionStatusStream;
StreamSubscription? _roomCapacitySubscription;
//Pangea#
@ -613,13 +612,8 @@ class ChatListController extends State<ChatList>
}
});
_subscriptionStatusStream ??= MatrixState
.pangeaController.subscriptionController.subscriptionStream.stream
.listen((event) {
if (mounted) {
showSubscribedSnackbar(context);
}
});
MatrixState.pangeaController.subscriptionController.subscriptionNotifier
.addListener(_onSubscribe);
// listen for space child updates for any space that is not the active space
// so that when the user navigates to the space that was updated, it will
@ -673,6 +667,10 @@ class ChatListController extends State<ChatList>
}
// #Pangea
void _onSubscribe() {
if (mounted) showSubscribedSnackbar(context);
}
Future<void> _joinInvitedSpaces() async {
final invitedSpaces = Matrix.of(context).client.rooms.where(
(r) => r.isSpace && r.membership == Membership.invite,
@ -691,8 +689,9 @@ class ChatListController extends State<ChatList>
_intentUriStreamSubscription?.cancel();
//#Pangea
_invitedSpaceSubscription?.cancel();
_subscriptionStatusStream?.cancel();
_roomCapacitySubscription?.cancel();
MatrixState.pangeaController.subscriptionController.subscriptionNotifier
.removeListener(_onSubscribe);
//Pangea#
scrollController.removeListener(_onScroll);
super.dispose();

View file

@ -138,7 +138,11 @@ class ButtonControlledCarouselView extends StatelessWidget {
Flexible(
child: SingleChildScrollView(
child: Text(
p.feedback,
p.displayFeedback(
user?.calcDisplayname() ??
p.participantId.localpart ??
p.participantId,
),
style: const TextStyle(fontSize: 12.0),
),
),

View file

@ -29,6 +29,9 @@ class ParticipantSummaryModel {
'superlatives': superlatives,
};
}
String displayFeedback(String displayName) =>
feedback.replaceAll(participantId, displayName);
}
class ActivitySummaryResponseModel {

View file

@ -243,7 +243,14 @@ class GetAnalyticsController extends BaseController {
}
void _onUnlockMorphLemmas(Set<ConstructIdentifier> unlocked) {
setState({'unlocked_constructs': unlocked});
const excludedLemmas = {'not_proper'};
final filtered = {
for (final id in unlocked)
if (!excludedLemmas.contains(id.lemma.toLowerCase())) id,
};
setState({'unlocked_constructs': filtered});
}
/// A local cache of eventIds and construct uses for messages sent since the last update.

View file

@ -224,6 +224,8 @@ class Choreographer extends ChangeNotifier {
EditTypeEnum.igc,
);
_stopLoading();
igcController.fetchAllSpanDetails().catchError((e) => clearMatches(e));
}
Future<PangeaMessageContentModel> getMessageContent(String message) async {

View file

@ -114,11 +114,6 @@ class IgcController {
matches: response.matches,
);
_isFetching = false;
if (_igcTextData != null) {
for (final match in _igcTextData!.openMatches) {
fetchSpanDetails(match: match).catchError((e) {});
}
}
}
Future<void> fetchSpanDetails({
@ -154,4 +149,13 @@ class IgcController {
_igcTextData?.setSpanData(match, response.result!.span);
}
Future<void> fetchAllSpanDetails() async {
if (_igcTextData == null) return;
final fetches = <Future>[];
for (final match in _igcTextData!.openMatches) {
fetches.add(fetchSpanDetails(match: match));
}
await Future.wait(fetches);
}
}

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:fluffychat/l10n/l10n.dart';
@ -36,8 +35,6 @@ class SpanCardState extends State<SpanCard> {
bool _loadingChoices = true;
final _feedbackModel = FeedbackModel<String>();
SpanChoice? _latestSelectedChoice;
final ScrollController scrollController = ScrollController();
@override
@ -56,10 +53,7 @@ class SpanCardState extends State<SpanCard> {
List<SpanChoice>? get _choices => widget.match.updatedMatch.match.choices;
SpanChoice? get _selectedChoice =>
widget.match.updatedMatch.match.selectedChoice ??
widget.match.updatedMatch.match.choices?.firstWhereOrNull(
(c) => c.value == _latestSelectedChoice?.value,
);
widget.match.updatedMatch.match.selectedChoice;
String? get _selectedFeedback => _selectedChoice?.feedback;
@ -120,7 +114,6 @@ class SpanCardState extends State<SpanCard> {
void _onChoiceSelect(int index) {
final selected = _choices![index];
widget.match.selectChoice(index);
_latestSelectedChoice = selected;
_feedbackModel.setState(
selected.feedback != null
? FeedbackLoaded<String>(selected.feedback!)

View file

@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:diacritic/diacritic.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
import 'package:fluffychat/pangea/choreographer/igc/text_normalization_util.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'span_choice_type_enum.dart';
import 'span_data_type_enum.dart';
@ -136,34 +136,13 @@ class SpanData {
final errorSpan = fullText.characters.skip(offset).take(length).toString();
final l2Code =
MatrixState.pangeaController.languageController.userL2?.langCodeShort;
return correctChoice != null &&
_normalizeString(correctChoice) == _normalizeString(errorSpan);
}
String _normalizeString(String input) {
try {
// Step 1: Remove diacritics (accents)
String normalized = removeDiacritics(input);
normalized = normalized.replaceAll(RegExp(r'[^\x00-\x7F]'), '');
// Step 2: Remove punctuation
normalized = normalized.replaceAll(RegExp(r'[^\w\s]'), '');
// Step 3: Convert to lowercase
normalized = normalized.toLowerCase();
// Step 4: Trim and normalize whitespace
normalized = normalized.replaceAll(RegExp(r'\s+'), ' ').trim();
return normalized.isEmpty ? input : normalized;
} catch (e, s) {
ErrorHandler.logError(
e: e,
s: s,
data: {'input': input},
);
return input;
}
l2Code != null &&
normalizeString(correctChoice, l2Code) ==
normalizeString(errorSpan, l2Code);
}
@override

View file

@ -0,0 +1,112 @@
import 'package:diacritic/diacritic.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
// The intention of this function is to normalize text for comparison purposes.
// It removes diacritics, punctuation, converts to lowercase, and trims whitespace.
// We would like esta = está, hello! = Hello, etc.
String normalizeString(String input, String languageCode) {
try {
// Step 1: Convert to lowercase (works for all Unicode scripts)
String normalized = input.toLowerCase();
// Step 2: Apply language-specific normalization rules
normalized = _applyLanguageSpecificNormalization(normalized, languageCode);
// Step 3: Replace hyphens and other dash-like characters with spaces
normalized = normalized.replaceAll(
RegExp(r'[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]'),
' ',
);
// Step 4: Remove punctuation (including Unicode punctuation)
// This removes ASCII and Unicode punctuation while preserving letters, numbers, and spaces
normalized = normalized.replaceAll(
RegExp(r'[\p{P}\p{S}]', unicode: true),
'',
);
// Step 5: Normalize whitespace (collapse multiple spaces, trim)
return normalized.replaceAll(RegExp(r'\s+'), ' ').trim();
} catch (e, s) {
ErrorHandler.logError(
e: e,
s: s,
data: {'input': input},
);
return input;
}
}
// Apply language-specific normalization rules
String _applyLanguageSpecificNormalization(String text, String languageCode) {
// Apply normalization based on provided language code
switch (languageCode) {
case 'de': // German
String normalized = removeDiacritics(text);
// Handle German ß -> ss conversion
normalized = normalized.replaceAll('ß', 'ss');
return normalized;
case 'da': // Danish
case 'no': // Norwegian
case 'nb': // Norwegian Bokmål
case 'sv': // Swedish
// Some Nordic tests expect characters to be preserved
return text; // Keep æøå intact for now
case 'el': // Greek
// Greek needs accent removal
return _removeGreekAccents(text);
case 'ca': // Catalan
// Catalan expects some characters preserved
return text; // Keep òç etc intact
case 'ar': // Arabic
case 'he': // Hebrew
case 'fa': // Persian/Farsi
case 'ur': // Urdu
case 'ja': // Japanese
case 'ko': // Korean
case 'zh': // Chinese
case 'zh-CN': // Chinese Simplified
case 'zh-TW': // Chinese Traditional
case 'hi': // Hindi
case 'bn': // Bengali
case 'gu': // Gujarati
case 'kn': // Kannada
case 'mr': // Marathi
case 'pa': // Punjabi
case 'ru': // Russian
case 'bg': // Bulgarian
case 'uk': // Ukrainian
case 'sr': // Serbian
case 'am': // Amharic
// Keep original for non-Latin scripts
return text;
default:
// Default Latin script handling
return removeDiacritics(text);
}
}
// Remove Greek accents specifically
String _removeGreekAccents(String text) {
return text
.replaceAll('ά', 'α')
.replaceAll('έ', 'ε')
.replaceAll('ή', 'η')
.replaceAll('ί', 'ι')
.replaceAll('ό', 'ο')
.replaceAll('ύ', 'υ')
.replaceAll('ώ', 'ω')
.replaceAll('Ά', 'Α')
.replaceAll('Έ', 'Ε')
.replaceAll('Ή', 'Η')
.replaceAll('Ί', 'Ι')
.replaceAll('Ό', 'Ο')
.replaceAll('Ύ', 'Υ')
.replaceAll('Ώ', 'Ω');
}

View file

@ -4,6 +4,7 @@ class PLocalKey {
static const String beganWebPayment = "beganWebPayment";
static const String dismissedPaywall = 'dismissedPaywall';
static const String paywallBackoff = 'paywallBackoff';
static const String clickedCancelSubscription = 'clickedCancelSubscription';
static const String messagesSinceUpdate = 'messagesSinceLastUpdate';
static const String completedActivities = 'completedActivities';
static const String justInputtedCode = 'justInputtedCode';

View file

@ -12,7 +12,6 @@ import 'package:url_launcher/url_launcher_string.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/pangea/common/config/environment.dart';
import 'package:fluffychat/pangea/common/controllers/base_controller.dart';
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/common/network/requests.dart';
import 'package:fluffychat/pangea/common/network/urls.dart';
@ -36,13 +35,13 @@ enum SubscriptionStatus {
shouldShowPaywall,
}
class SubscriptionController extends BaseController {
class SubscriptionController with ChangeNotifier {
late PangeaController _pangeaController;
CurrentSubscriptionInfo? currentSubscriptionInfo;
AvailableSubscriptionsInfo? availableSubscriptionInfo;
final StreamController subscriptionStream = StreamController.broadcast();
final ValueNotifier<bool> subscriptionNotifier = ValueNotifier<bool>(false);
SubscriptionController(PangeaController pangeaController) : super() {
_pangeaController = pangeaController;
@ -120,22 +119,20 @@ class SubscriptionController extends BaseController {
(CustomerInfo info) async {
final bool? wasSubscribed = isSubscribed;
await updateCustomerInfo();
if (wasSubscribed != null &&
!wasSubscribed &&
(isSubscribed != null && isSubscribed!)) {
subscriptionStream.add(true);
if (wasSubscribed == false && isSubscribed == true) {
subscriptionNotifier.value = true;
}
},
);
} else {
if (SubscriptionManagementRepo.getBeganWebPayment()) {
await SubscriptionManagementRepo.removeBeganWebPayment();
if (isSubscribed != null && isSubscribed!) {
subscriptionStream.add(true);
if (isSubscribed == true) {
subscriptionNotifier.value = true;
}
}
}
setState(null);
notifyListeners();
} catch (e, s) {
debugPrint("Failed to initialize subscription controller");
ErrorHandler.logError(
@ -198,7 +195,6 @@ class SubscriptionController extends BaseController {
isPromo: isPromo,
);
await SubscriptionManagementRepo.setBeganWebPayment();
setState(null);
launchUrlString(
paymentLink,
webOnlyWindowName: "_self",
@ -235,7 +231,7 @@ class SubscriptionController extends BaseController {
Future<void> updateCustomerInfo() async {
await currentSubscriptionInfo?.setCurrentSubscription();
setState(null);
notifyListeners();
}
/// if the user is subscribed, returns subscribed

View file

@ -11,6 +11,7 @@ class CurrentSubscriptionInfo {
final AvailableSubscriptionsInfo availableSubscriptionInfo;
DateTime? expirationDate;
DateTime? unsubscribeDetectedAt;
String? currentSubscriptionId;
CurrentSubscriptionInfo({
@ -59,6 +60,9 @@ class CurrentSubscriptionInfo {
(currentSubscription?.appId ==
availableSubscriptionInfo.appIds?.currentAppId);
DateTime? get subscriptionEndDate =>
unsubscribeDetectedAt == null ? null : expirationDate;
void resetSubscription() => currentSubscriptionId = null;
Future<void> setCurrentSubscription() async {}
}

View file

@ -104,10 +104,10 @@ class MobileSubscriptionInfo extends CurrentSubscriptionInfo {
expirationDate = activeEntitlement.expirationDate != null
? DateTime.parse(activeEntitlement.expirationDate!)
: null;
unsubscribeDetectedAt = activeEntitlement.unsubscribeDetectedAt != null
? DateTime.parse(activeEntitlement.unsubscribeDetectedAt!)
: null;
if (activeEntitlement.periodType == PeriodType.trial) {
// We dont use actual trials as it would require adding a CC on devices
}
if (currentSubscriptionId != null && currentSubscription == null) {
Sentry.addBreadcrumb(
Breadcrumb(message: "mismatch of productIds and currentSubscriptionID"),

View file

@ -21,7 +21,16 @@ class WebSubscriptionInfo extends CurrentSubscriptionInfo {
);
currentSubscriptionId = rcResponse.currentSubscriptionId;
expirationDate = rcResponse.expirationDate;
final currentSubscription =
rcResponse.allSubscriptions?[currentSubscriptionId];
if (currentSubscription != null) {
expirationDate = DateTime.tryParse(currentSubscription.expiresDate);
unsubscribeDetectedAt =
currentSubscription.unsubscribeDetectedAt != null
? DateTime.parse(currentSubscription.unsubscribeDetectedAt!)
: null;
}
} catch (err) {
currentSubscriptionId = AppConfig.errorSubscriptionId;
}

View file

@ -171,21 +171,20 @@ class ChangeSubscription extends StatelessWidget {
ElevatedButton(
onPressed: () => controller
.submitChange(subscription),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
controller.loading
? const CircularProgressIndicator
.adaptive()
: Text(
child: controller.loading
? const LinearProgressIndicator()
: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
subscription.isTrial
? L10n.of(context)
.activateTrial
: L10n.of(context).pay,
),
],
),
],
),
),
],
),

View file

@ -2,16 +2,16 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pangea/common/config/environment.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
import 'package:fluffychat/pangea/subscription/controllers/subscription_controller.dart';
import 'package:fluffychat/pangea/subscription/pages/settings_subscription_view.dart';
import 'package:fluffychat/pangea/subscription/repo/subscription_management_repo.dart';
import 'package:fluffychat/pangea/subscription/utils/subscription_app_id.dart';
import 'package:fluffychat/pangea/subscription/widgets/subscription_snackbar.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
class SubscriptionManagement extends StatefulWidget {
@ -27,37 +27,25 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {
MatrixState.pangeaController.subscriptionController;
SubscriptionDetails? selectedSubscription;
StreamSubscription? _subscriptionStatusStream;
bool loading = false;
late StreamSubscription _settingsSubscription;
@override
void initState() {
if (!subscriptionController.initCompleter.isCompleted) {
subscriptionController.initialize().then((_) => setState(() {}));
}
_settingsSubscription = subscriptionController.stateStream.listen((event) {
debugPrint("stateStream event in subscription settings");
setState(() {});
});
_subscriptionStatusStream ??=
subscriptionController.subscriptionStream.stream.listen((_) {
showSubscribedSnackbar(context);
context.go('/rooms');
});
subscriptionController.addListener(_onSubscriptionUpdate);
subscriptionController.subscriptionNotifier.addListener(_onSubscribe);
subscriptionController.updateCustomerInfo();
super.initState();
}
@override
void dispose() {
subscriptionController.subscriptionNotifier.removeListener(_onSubscribe);
subscriptionController.removeListener(_onSubscriptionUpdate);
super.dispose();
_settingsSubscription.cancel();
_subscriptionStatusStream?.cancel();
}
bool get subscriptionsAvailable =>
@ -106,29 +94,46 @@ class SubscriptionManagementController extends State<SubscriptionManagement> {
.currentSubscriptionInfo!.currentPlatformMatchesPurchasePlatform;
}
DateTime? get expirationDate =>
subscriptionController.currentSubscriptionInfo?.expirationDate;
DateTime? get subscriptionEndDate =>
subscriptionController.currentSubscriptionInfo?.subscriptionEndDate;
void _onSubscriptionUpdate() => setState(() {});
void _onSubscribe() => showSubscribedSnackbar(context);
Future<void> submitChange(
SubscriptionDetails subscription, {
bool isPromo = false,
}) async {
setState(() => loading = true);
await showFutureLoadingDialog(
context: context,
future: () async => subscriptionController.submitSubscriptionChange(
try {
await subscriptionController.submitSubscriptionChange(
subscription,
context,
isPromo: isPromo,
),
onError: (error, s) {
setState(() => loading = false);
return null;
},
);
if (mounted && loading) {
setState(() => loading = false);
);
} catch (e, s) {
ErrorHandler.logError(
e: e,
s: s,
data: {
"subscription_id": subscription.id,
"is_promo": isPromo,
},
);
} finally {
if (mounted) setState(() => loading = false);
}
}
Future<void> onClickCancelSubscription() async {
await SubscriptionManagementRepo.setClickedCancelSubscription();
await launchMangementUrl(ManagementOption.cancel);
if (mounted) setState(() {});
}
Future<void> launchMangementUrl(ManagementOption option) async {
String managementUrl = Environment.stripeManagementUrl;
final String? email =

View file

@ -7,6 +7,7 @@ import 'package:intl/intl.dart';
import 'package:fluffychat/l10n/l10n.dart';
import 'package:fluffychat/pangea/subscription/pages/change_subscription.dart';
import 'package:fluffychat/pangea/subscription/pages/settings_subscription.dart';
import 'package:fluffychat/pangea/subscription/repo/subscription_management_repo.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
class SettingsSubscriptionView extends StatelessWidget {
@ -25,12 +26,18 @@ class SettingsSubscriptionView extends StatelessWidget {
Column(
children: [
ListTile(
title: Text(L10n.of(context).cancelSubscription),
enabled: controller.showManagementOptions,
onTap: () => controller.launchMangementUrl(
ManagementOption.cancel,
title: Text(
controller.subscriptionEndDate == null
? L10n.of(context).cancelSubscription
: L10n.of(context).enabledRenewal,
),
enabled: controller.showManagementOptions,
onTap: controller.onClickCancelSubscription,
trailing: Icon(
controller.subscriptionEndDate == null
? Icons.cancel_outlined
: Icons.refresh_outlined,
),
trailing: const Icon(Icons.cancel_outlined),
),
const Divider(height: 1),
ListTile(
@ -49,6 +56,42 @@ class SettingsSubscriptionView extends StatelessWidget {
),
enabled: controller.showManagementOptions,
),
if (controller.expirationDate != null) ...[
const Divider(height: 1),
ListTile(
title: Text(
controller.subscriptionEndDate != null
? L10n.of(context).subscriptionEndsOn
: L10n.of(context).subscriptionRenewsOn,
),
subtitle: Text(
DateFormat.yMMMMd().format(
controller.expirationDate!.toLocal(),
),
),
),
if (SubscriptionManagementRepo.getClickedCancelSubscription())
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
spacing: 8.0,
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.info_outline,
size: 20,
),
Flexible(
child: Text(
L10n.of(context).waitForSubscriptionChanges,
textAlign: TextAlign.center,
style: const TextStyle(fontStyle: FontStyle.italic),
),
),
],
),
),
],
],
),
];
@ -68,16 +111,15 @@ class SettingsSubscriptionView extends StatelessWidget {
child: Column(
children: [
if (isSubscribed == null)
const Center(child: CircularProgressIndicator.adaptive()),
if (isSubscribed != null &&
isSubscribed &&
!controller.showManagementOptions)
const Center(child: CircularProgressIndicator.adaptive())
else if (isSubscribed && !controller.showManagementOptions)
ManagementNotAvailableWarning(
controller: controller,
),
if (isSubscribed != null && !isSubscribed)
)
else if (isSubscribed && controller.showManagementOptions)
...managementButtons
else
ChangeSubscription(controller: controller),
if (controller.showManagementOptions) ...managementButtons,
],
),
),

View file

@ -69,4 +69,22 @@ class SubscriptionManagementRepo {
final int backoff = _getPaywallBackoff() + 1;
await _cache.write(PLocalKey.paywallBackoff, backoff);
}
static Future<void> setClickedCancelSubscription() async {
await _cache.write(
PLocalKey.clickedCancelSubscription,
DateTime.now().toIso8601String(),
);
}
static bool getClickedCancelSubscription() {
final entry = _cache.read(PLocalKey.clickedCancelSubscription);
if (entry == null) return false;
final val = DateTime.tryParse(entry);
return val != null && DateTime.now().difference(val).inSeconds < 60;
}
static Future<void> removeClickedCancelSubscription() async {
await _cache.remove(PLocalKey.clickedCancelSubscription);
}
}

View file

@ -151,7 +151,6 @@ class RCProductsResponseModel {
class RCSubscriptionResponseModel {
String? currentSubscriptionId;
SubscriptionDetails? currentSubscription;
DateTime? expirationDate;
List<String>? allEntitlements;
Map<String, RCSubscription>? allSubscriptions;
@ -159,7 +158,6 @@ class RCSubscriptionResponseModel {
this.currentSubscriptionId,
this.currentSubscription,
this.allEntitlements,
this.expirationDate,
this.allSubscriptions,
});
@ -188,14 +186,6 @@ class RCSubscriptionResponseModel {
}
final String currentSubscriptionId = activeEntitlements[0];
final Map<String, dynamic> currentSubscriptionMetadata =
json['subscriptions'][currentSubscriptionId];
final DateTime expirationDate = DateTime.parse(
currentSubscriptionMetadata['expires_date'],
);
final SubscriptionDetails? currentSubscription =
allProducts?.firstWhereOrNull(
(SubscriptionDetails sub) =>
@ -206,7 +196,6 @@ class RCSubscriptionResponseModel {
return RCSubscriptionResponseModel(
currentSubscription: currentSubscription,
currentSubscriptionId: currentSubscriptionId,
expirationDate: expirationDate,
allEntitlements: activeEntitlements,
allSubscriptions: history,
);

View file

@ -6,7 +6,7 @@ description: Learn a language while texting your friends.
# Pangea#
publish_to: none
# On version bump also increase the build number for F-Droid
version: 4.1.15+4
version: 4.1.15+5
environment:
sdk: ">=3.0.0 <4.0.0"

View file

@ -0,0 +1,352 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:matrix/matrix_api_lite/utils/logs.dart';
import 'package:fluffychat/pangea/choreographer/igc/text_normalization_util.dart';
final List<Map<String, String>> normalizeTestCases = [
// 1. Amharic (am) - beta
{"input": "ሰላም!", "expected": "ሰላም"},
{"input": "ተማሪ።", "expected": "ተማሪ"},
{"input": "ኢትዮጵያ...", "expected": "ኢትዮጵያ"},
// 2. Arabic (ar) - beta
{"input": "السلام عليكم!", "expected": "السلام عليكم"},
{"input": "مرحباً", "expected": "مرحباً"},
{"input": "القاهرة.", "expected": "القاهرة"},
{"input": "مدرسة؟", "expected": "مدرسة"},
// 3. Bengali (bn) - beta
{"input": "নমস্কার!", "expected": "নমস্কার"},
{"input": "ভালো আছেন?", "expected": "ভালো আছেন"},
{"input": "ঢাকা।", "expected": "ঢাকা"},
// 4. Bulgarian (bg) - beta
{"input": "Здравей!", "expected": "здравей"},
{"input": "България", "expected": "българия"},
{"input": "София.", "expected": "софия"},
// 5. Catalan (ca) - full
{"input": "Hola!", "expected": "hola"},
{"input": "França", "expected": "franca"},
{"input": "Barcelòna...", "expected": "barcelòna"},
{"input": "això", "expected": "això"},
// 6. Czech (cs) - beta
{"input": "Dobrý den!", "expected": "dobry den"},
{"input": "Děkuji", "expected": "dekuji"},
{"input": "Praha.", "expected": "praha"},
{"input": "škola?", "expected": "skola"},
// 7. Danish (da) - beta
{"input": "Hej!", "expected": "hej"},
{"input": "København", "expected": "kobenhavn"},
{"input": "Danskе.", "expected": "danske"},
{"input": "æøå", "expected": "æøå"},
// 8. German (de) - full
{"input": "Guten Tag!", "expected": "guten tag"},
{"input": "Schöne Grüße", "expected": "schone grusse"},
{"input": "München.", "expected": "munchen"},
{"input": "Straße?", "expected": "strasse"},
{"input": "Hörst du mich?", "expected": "horst du mich"},
// 9. Greek (el) - beta
{"input": "Γεια σας!", "expected": "γεια σας"},
{"input": "Αθήνα", "expected": "αθηνα"},
{"input": "ελληνικά.", "expected": "ελληνικα"},
// 10. English (en) - full
{"input": "Hello world!", "expected": "hello world"},
{"input": "It's a beautiful day.", "expected": "its a beautiful day"},
{"input": "Don't worry, be happy!", "expected": "dont worry be happy"},
{"input": "café", "expected": "cafe"},
{"input": "résumé", "expected": "resume"},
// 11. Spanish (es) - full
{"input": "¡Hola mundo!", "expected": "hola mundo"},
{"input": "Adiós", "expected": "adios"},
{"input": "España.", "expected": "espana"},
{"input": "niño", "expected": "nino"},
{"input": "¿Cómo estás?", "expected": "como estas"},
// 12. Estonian (et) - beta
{"input": "Tere!", "expected": "tere"},
{"input": "Tallinn", "expected": "tallinn"},
{"input": "Eesti.", "expected": "eesti"},
// 13. Basque (eu) - beta
{"input": "Kaixo!", "expected": "kaixo"},
{"input": "Euskera", "expected": "euskera"},
{"input": "Bilbo.", "expected": "bilbo"},
// 14. Finnish (fi) - beta
{"input": "Hei!", "expected": "hei"},
{"input": "Helsinki", "expected": "helsinki"},
{"input": "Suomi.", "expected": "suomi"},
{"input": "Käännös", "expected": "kaannos"},
// 15. French (fr) - full
{"input": "Bonjour!", "expected": "bonjour"},
{"input": "À bientôt", "expected": "a bientot"},
{"input": "Paris.", "expected": "paris"},
{"input": "Français?", "expected": "francais"},
{"input": "C'est magnifique!", "expected": "cest magnifique"},
// 16. Galician (gl) - beta
{"input": "Ola!", "expected": "ola"},
{"input": "Galicia", "expected": "galicia"},
{"input": "Santiago.", "expected": "santiago"},
// 17. Gujarati (gu) - beta
{"input": "નમસ્તે!", "expected": "નમસ્તે"},
{"input": "ગુજરાત", "expected": "ગુજરાત"},
{"input": "અમદાવાદ.", "expected": "અમદાવાદ"},
// 18. Hindi (hi) - beta
{"input": "नमस्ते!", "expected": "नमस्ते"},
{"input": "भारत", "expected": "भारत"},
{"input": "दिल्ली.", "expected": "दिल्ली"},
{"input": "शिक्षा?", "expected": "शिक्षा"},
// 19. Hungarian (hu) - beta
{"input": "Szia!", "expected": "szia"},
{"input": "Budapest", "expected": "budapest"},
{"input": "Magyar.", "expected": "magyar"},
{"input": "köszönöm", "expected": "koszonom"},
// 20. Indonesian (id) - beta
{"input": "Halo!", "expected": "halo"},
{"input": "Jakarta", "expected": "jakarta"},
{"input": "Indonesia.", "expected": "indonesia"},
{"input": "selamat pagi", "expected": "selamat pagi"},
// 21. Italian (it) - full
{"input": "Ciao!", "expected": "ciao"},
{"input": "Arrivederci", "expected": "arrivederci"},
{"input": "Roma.", "expected": "roma"},
{"input": "perché?", "expected": "perche"},
{"input": "È bellissimo!", "expected": "e bellissimo"},
// 22. Japanese (ja) - full
{"input": "こんにちは!", "expected": "こんにちは"},
{"input": "東京", "expected": "東京"},
{"input": "ありがとう。", "expected": "ありがとう"},
{"input": "さようなら?", "expected": "さようなら"},
// 23. Kannada (kn) - beta
{"input": "ನಮಸ್ತೆ!", "expected": "ನಮಸ್ತೆ"},
{"input": "ಬೆಂಗಳೂರು", "expected": "ಬೆಂಗಳೂರು"},
{"input": "ಕರ್ನಾಟಕ.", "expected": "ಕರ್ನಾಟಕ"},
// 24. Korean (ko) - full
{"input": "안녕하세요!", "expected": "안녕하세요"},
{"input": "서울", "expected": "서울"},
{"input": "한국어.", "expected": "한국어"},
{"input": "감사합니다?", "expected": "감사합니다"},
// 25. Lithuanian (lt) - beta
{"input": "Labas!", "expected": "labas"},
{"input": "Vilnius", "expected": "vilnius"},
{"input": "Lietuva.", "expected": "lietuva"},
{"input": "ačiū", "expected": "aciu"},
// 26. Latvian (lv) - beta
{"input": "Sveiki!", "expected": "sveiki"},
{"input": "Rīga", "expected": "riga"},
{"input": "Latvija.", "expected": "latvija"},
// 27. Malay (ms) - beta
{"input": "Selamat pagi!", "expected": "selamat pagi"},
{"input": "Kuala Lumpur", "expected": "kuala lumpur"},
{"input": "Malaysia.", "expected": "malaysia"},
// 28. Mongolian (mn) - beta
{"input": "Сайн байна уу!", "expected": "сайн байна уу"},
{"input": "Улаанбаатар", "expected": "улаанбаатар"},
{"input": "Монгол.", "expected": "монгол"},
// 29. Marathi (mr) - beta
{"input": "नमस्कार!", "expected": "नमस्कार"},
{"input": "मुंबई", "expected": "मुंबई"},
{"input": "महाराष्ट्र.", "expected": "महाराष्ट्र"},
// 30. Dutch (nl) - beta
{"input": "Hallo!", "expected": "hallo"},
{"input": "Amsterdam", "expected": "amsterdam"},
{"input": "Nederland.", "expected": "nederland"},
{"input": "dankjewel", "expected": "dankjewel"},
// 31. Punjabi (pa) - beta
{"input": "ਸਤਿ ਸ਼੍ਰੀ ਅਕਾਲ!", "expected": "ਸਤਿ ਸ਼੍ਰੀ ਅਕਾਲ"},
{"input": "ਪੰਜਾਬ", "expected": "ਪੰਜਾਬ"},
{"input": "ਅੰਮ੍ਰਿਤਸਰ.", "expected": "ਅੰਮ੍ਰਿਤਸਰ"},
// 32. Polish (pl) - beta
{"input": "Cześć!", "expected": "czesc"},
{"input": "Warszawa", "expected": "warszawa"},
{"input": "Polska.", "expected": "polska"},
{"input": "dziękuję", "expected": "dziekuje"},
// 33. Portuguese (pt) - full
{"input": "Olá!", "expected": "ola"},
{"input": "Obrigado", "expected": "obrigado"},
{"input": "São Paulo.", "expected": "sao paulo"},
{"input": "coração", "expected": "coracao"},
{"input": "não?", "expected": "nao"},
// 34. Romanian (ro) - beta
{"input": "Salut!", "expected": "salut"},
{"input": "București", "expected": "bucuresti"},
{"input": "România.", "expected": "romania"},
{"input": "mulțumesc", "expected": "multumesc"},
// 35. Russian (ru) - full
{"input": "Привет!", "expected": "привет"},
{"input": "Москва", "expected": "москва"},
{"input": "Россия.", "expected": "россия"},
{"input": "спасибо?", "expected": "спасибо"},
{"input": "магазин", "expected": "магазин"},
{"input": "магазин.", "expected": "магазин"},
// 36. Slovak (sk) - beta
{"input": "Ahoj!", "expected": "ahoj"},
{"input": "Bratislava", "expected": "bratislava"},
{"input": "Slovensko.", "expected": "slovensko"},
{"input": "ďakujem", "expected": "dakujem"},
// 37. Serbian (sr) - beta
{"input": "Здраво!", "expected": "здраво"},
{"input": "Београд", "expected": "београд"},
{"input": "Србија.", "expected": "србија"},
// 38. Ukrainian (uk) - beta
{"input": "Привіт!", "expected": "привіт"},
{"input": "Київ", "expected": "київ"},
{"input": "Україна.", "expected": "україна"},
// 39. Urdu (ur) - beta
{"input": "السلام علیکم!", "expected": "السلام علیکم"},
{"input": "کراچی", "expected": "کراچی"},
{"input": "پاکستان.", "expected": "پاکستان"},
// 40. Vietnamese (vi) - full
{"input": "Xin chào!", "expected": "xin chao"},
{"input": "Hà Nội", "expected": "ha noi"},
{"input": "Việt Nam.", "expected": "viet nam"},
{"input": "cảm ơn?", "expected": "cam on"},
// 41. Cantonese (yue) - beta
{"input": "你好!", "expected": "你好"},
{"input": "香港", "expected": "香港"},
{"input": "廣東話.", "expected": "廣東話"},
// 42. Chinese Simplified (zh-CN) - full
{"input": "你好!", "expected": "你好"},
{"input": "北京", "expected": "北京"},
{"input": "中国.", "expected": "中国"},
{"input": "谢谢?", "expected": "谢谢"},
// 43. Chinese Traditional (zh-TW) - full
{"input": "您好!", "expected": "您好"},
{"input": "台北", "expected": "台北"},
{"input": "台灣.", "expected": "台灣"},
// Edge cases and special scenarios
// Mixed script and punctuation
{"input": "Hello世界!", "expected": "hello世界"},
{"input": "café-restaurant", "expected": "cafe restaurant"},
// Multiple spaces and whitespace normalization
{"input": " hello world ", "expected": "hello world"},
{"input": "test\t\n text", "expected": "test text"},
// Numbers and alphanumeric
{"input": "test123!", "expected": "test123"},
{"input": "COVID-19", "expected": "covid 19"},
{"input": "2023年", "expected": "2023年"},
// Empty and whitespace only
{"input": "", "expected": ""},
{"input": " ", "expected": ""},
{"input": "!!!", "expected": ""},
// Special punctuation combinations
{"input": "What?!?", "expected": "what"},
{"input": "Well...", "expected": "well"},
{"input": "Hi---there", "expected": "hi there"},
// Diacritics and accents across languages
{"input": "café résumé naïve", "expected": "cafe resume naive"},
{"input": "piñata jalapeño", "expected": "pinata jalapeno"},
{"input": "Zürich Müller", "expected": "zurich muller"},
{"input": "François Böhm", "expected": "francois bohm"},
// Currency and symbols
{"input": "\$100 €50 ¥1000", "expected": "100 50 1000"},
{"input": "@username #hashtag", "expected": "username hashtag"},
{"input": "50% off!", "expected": "50 off"},
// Quotation marks and brackets
{"input": "\"Hello\"", "expected": "hello"},
{"input": "(test)", "expected": "test"},
{"input": "[important]", "expected": "important"},
{"input": "{data}", "expected": "data"},
// Apostrophes and contractions
{"input": "don't can't won't", "expected": "dont cant wont"},
{"input": "it's they're we've", "expected": "its theyre weve"},
// Hyphenated words
{"input": "twenty-one", "expected": "twenty one"},
{"input": "state-of-the-art", "expected": "state of the art"},
{"input": "re-enter", "expected": "re enter"},
];
// Helper function to run all normalization tests
void runNormalizationTests() {
int passed = 0;
final int total = normalizeTestCases.length;
for (int i = 0; i < normalizeTestCases.length; i++) {
final testCase = normalizeTestCases[i];
final input = testCase['input']!;
final expected = testCase['expected']!;
final actual = normalizeString(input, 'en'); // Default to English for tests
if (actual == expected) {
passed++;
Logs().i('✓ Test ${i + 1} PASSED: "$input" → "$actual"');
} else {
Logs().i(
'✗ Test ${i + 1} FAILED: "$input" → "$actual" (expected: "$expected")',
);
}
}
Logs().i(
'\nTest Results: $passed/$total tests passed (${(passed / total * 100).toStringAsFixed(1)}%)',
);
}
// Main function to run the tests when executed directly
// flutter test lib/pangea/choreographer/utils/normalize_text.dart
void main() {
group('Normalize String Tests', () {
for (int i = 0; i < normalizeTestCases.length; i++) {
final testCase = normalizeTestCases[i];
final input = testCase['input']!;
final expected = testCase['expected']!;
test('Test ${i + 1}: "$input" should normalize to "$expected"', () {
final actual =
normalizeString(input, 'en'); // Default to English for tests
expect(
actual,
equals(expected),
reason: 'Input: "$input" → Got: "$actual" → Expected: "$expected"',
);
});
}
});
}