Skip to content

Commit

Permalink
Merge pull request #161 from pangeachat/matrix-account-data
Browse files Browse the repository at this point in the history
Save certain user data in matrix profile
  • Loading branch information
ggurdin authored May 6, 2024
2 parents eb08ccd + e891ab1 commit be5cbbc
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 198 deletions.
1 change: 0 additions & 1 deletion lib/pangea/constants/local.key.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class PLocalKey {
static const String user = 'user';
static const String matrixProfile = 'matrixProfile';

static const String classes = 'classes';

Expand Down
4 changes: 3 additions & 1 deletion lib/pangea/controllers/class_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class ClassController extends BaseController {
final String? classCode = _pangeaController.pStoreService.read(
PLocalKey.cachedClassCodeToJoin,
addClientIdToKey: false,
local: true,
);

if (classCode != null) {
_pangeaController.pStoreService.delete(
await _pangeaController.pStoreService.delete(
PLocalKey.cachedClassCodeToJoin,
addClientIdToKey: false,
local: true,
);
await joinClasswithCode(
context,
Expand Down
13 changes: 9 additions & 4 deletions lib/pangea/controllers/message_analytics_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class AnalyticsController extends BaseController {

TimeSpan get currentAnalyticsTimeSpan {
try {
final String? str =
_pangeaController.pStoreService.read(_analyticsTimeSpanKey);
final String? str = _pangeaController.pStoreService.read(
_analyticsTimeSpanKey,
local: true,
);
return str != null
? TimeSpan.values.firstWhere((e) {
final spanString = e.toString();
Expand All @@ -48,8 +50,11 @@ class AnalyticsController extends BaseController {
}

Future<void> setCurrentAnalyticsTimeSpan(TimeSpan timeSpan) async {
await _pangeaController.pStoreService
.save(_analyticsTimeSpanKey, timeSpan.toString());
await _pangeaController.pStoreService.save(
_analyticsTimeSpanKey,
timeSpan.toString(),
local: true,
);
}

Future<List<ChartAnalyticsModel?>> allClassAnalytics() async {
Expand Down
5 changes: 4 additions & 1 deletion lib/pangea/controllers/permissions_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:fluffychat/pangea/controllers/base_controller.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
import 'package:fluffychat/pangea/models/class_model.dart';
import 'package:fluffychat/pangea/models/user_model.dart';
import 'package:fluffychat/pangea/utils/p_extension.dart';
import 'package:matrix/matrix.dart';

Expand Down Expand Up @@ -31,7 +32,9 @@ class PermissionsController extends BaseController {

/// Returns false if user is null
bool isUser18() {
final dob = _pangeaController.userController.matrixProfile?.dateOfBirth;
final dob = _pangeaController.pStoreService.read(
MatrixProfile.dateOfBirth.title,
);
return dob != null
? DateTime.parse(dob).isAtLeastYearsOld(AgeLimits.toAccessFeatures)
: false;
Expand Down
38 changes: 29 additions & 9 deletions lib/pangea/controllers/subscription_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:fluffychat/pangea/controllers/base_controller.dart';
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
import 'package:fluffychat/pangea/models/base_subscription_info.dart';
import 'package:fluffychat/pangea/models/mobile_subscriptions.dart';
import 'package:fluffychat/pangea/models/user_model.dart';
import 'package:fluffychat/pangea/models/web_subscriptions.dart';
import 'package:fluffychat/pangea/network/requests.dart';
import 'package:fluffychat/pangea/network/urls.dart';
Expand Down Expand Up @@ -78,9 +79,13 @@ class SubscriptionController extends BaseController {
} else {
final bool? beganWebPayment = _pangeaController.pStoreService.read(
PLocalKey.beganWebPayment,
local: true,
);
if (beganWebPayment ?? false) {
_pangeaController.pStoreService.delete(PLocalKey.beganWebPayment);
await _pangeaController.pStoreService.delete(
PLocalKey.beganWebPayment,
local: true,
);
if (_pangeaController.subscriptionController.isSubscribed) {
subscriptionStream.add(true);
}
Expand Down Expand Up @@ -116,9 +121,10 @@ class SubscriptionController extends BaseController {
selectedSubscription.duration!,
isPromo: isPromo,
);
_pangeaController.pStoreService.save(
await _pangeaController.pStoreService.save(
PLocalKey.beganWebPayment,
true,
local: true,
);
setState();
launchUrlString(
Expand Down Expand Up @@ -160,12 +166,18 @@ class SubscriptionController extends BaseController {

bool get _activatedNewUserTrial =>
_pangeaController.userController.inTrialWindow &&
(_pangeaController.pStoreService.read(PLocalKey.activatedTrialKey) ??
(_pangeaController.pStoreService.read(
MatrixProfile.activatedFreeTrial.title,
) ??
false);

void activateNewUserTrial() {
_pangeaController.pStoreService.save(PLocalKey.activatedTrialKey, true);
setNewUserTrial();
_pangeaController.pStoreService
.save(
MatrixProfile.activatedFreeTrial.title,
true,
)
.then((_) => setNewUserTrial());
}

void setNewUserTrial() {
Expand Down Expand Up @@ -206,6 +218,7 @@ class SubscriptionController extends BaseController {
DateTime? get _lastDismissedPaywall {
final lastDismissed = _pangeaController.pStoreService.read(
PLocalKey.dismissedPaywall,
local: true,
);
if (lastDismissed == null) return null;
return DateTime.tryParse(lastDismissed);
Expand All @@ -214,6 +227,7 @@ class SubscriptionController extends BaseController {
int? get _paywallBackoff {
final backoff = _pangeaController.pStoreService.read(
PLocalKey.paywallBackoff,
local: true,
);
if (backoff == null) return null;
return backoff;
Expand All @@ -227,18 +241,24 @@ class SubscriptionController extends BaseController {
(24 * (_paywallBackoff ?? 1)));
}

void dismissPaywall() {
_pangeaController.pStoreService.save(
void dismissPaywall() async {
await _pangeaController.pStoreService.save(
PLocalKey.dismissedPaywall,
DateTime.now().toString(),
local: true,
);

if (_paywallBackoff == null) {
_pangeaController.pStoreService.save(PLocalKey.paywallBackoff, 1);
await _pangeaController.pStoreService.save(
PLocalKey.paywallBackoff,
1,
local: true,
);
} else {
_pangeaController.pStoreService.save(
await _pangeaController.pStoreService.save(
PLocalKey.paywallBackoff,
_paywallBackoff! + 1,
local: true,
);
}
}
Expand Down
Loading

0 comments on commit be5cbbc

Please sign in to comment.