commit
bfdacbf3ad
8 changed files with 87 additions and 15 deletions
|
|
@ -1,5 +1,6 @@
|
|||
class PLocalKey {
|
||||
static const String user = 'user';
|
||||
static const String matrixProfile = 'matrixProfile';
|
||||
|
||||
static const String classes = 'classes';
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,6 @@ class PangeaEventTypes {
|
|||
|
||||
static const audio = "p.audio";
|
||||
static const botOptions = "pangea.bot_options";
|
||||
|
||||
static const userAge = "pangea.user_age";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/age_limits.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||
|
|
@ -7,6 +5,7 @@ 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/utils/p_extension.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class PermissionsController extends BaseController {
|
||||
late PangeaController _pangeaController;
|
||||
|
|
@ -32,8 +31,7 @@ class PermissionsController extends BaseController {
|
|||
|
||||
/// Returns false if user is null
|
||||
bool isUser18() {
|
||||
final dob =
|
||||
_pangeaController.userController.userModel?.profile?.dateOfBirth;
|
||||
final dob = _pangeaController.userController.matrixProfile?.dateOfBirth;
|
||||
return dob != null
|
||||
? DateTime.parse(dob).isAtLeastYearsOld(AgeLimits.toAccessFeatures)
|
||||
: false;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'dart:developer';
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/constants/language_keys.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/base_controller.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
@ -36,6 +37,11 @@ class UserController extends BaseController {
|
|||
|
||||
if (newUserModel != null) {
|
||||
_savePUserModel(newUserModel);
|
||||
if (newUserModel.profile!.dateOfBirth != null) {
|
||||
await setMatrixProfile(newUserModel.profile!.dateOfBirth!);
|
||||
}
|
||||
final MatrixProfile? matrixProfile = await getMatrixProfile();
|
||||
_saveMatrixProfile(matrixProfile);
|
||||
}
|
||||
_completeCompleter();
|
||||
|
||||
|
|
@ -46,6 +52,29 @@ class UserController extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> setMatrixProfile(String dob) async {
|
||||
await _pangeaController.matrixState.client.setAccountData(
|
||||
userId!,
|
||||
PangeaEventTypes.userAge,
|
||||
{ModelKey.userDateOfBirth: dob},
|
||||
);
|
||||
final MatrixProfile? matrixProfile = await getMatrixProfile();
|
||||
_saveMatrixProfile(matrixProfile);
|
||||
}
|
||||
|
||||
Future<MatrixProfile?> getMatrixProfile() async {
|
||||
try {
|
||||
final Map<String, dynamic> accountData =
|
||||
await _pangeaController.matrixState.client.getAccountData(
|
||||
userId!,
|
||||
PangeaEventTypes.userAge,
|
||||
);
|
||||
return MatrixProfile.fromJson(accountData);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void _completeCompleter() {
|
||||
if (!_completer.isCompleted) {
|
||||
_completer.complete(null);
|
||||
|
|
@ -92,6 +121,11 @@ class UserController extends BaseController {
|
|||
return data != null ? PUserModel.fromJson(data) : null;
|
||||
}
|
||||
|
||||
MatrixProfile? get matrixProfile {
|
||||
final data = _pangeaController.pStoreService.read(PLocalKey.matrixProfile);
|
||||
return data != null ? MatrixProfile.fromJson(data) : null;
|
||||
}
|
||||
|
||||
Future<bool> get isPUserDataAvailable async {
|
||||
try {
|
||||
final PUserModel? toCheck = userModel ?? (await fetchUserModel());
|
||||
|
|
@ -103,8 +137,10 @@ class UserController extends BaseController {
|
|||
|
||||
Future<bool> get isUserDataAvailableAndDateOfBirthSet async {
|
||||
try {
|
||||
final PUserModel? toCheck = userModel ?? (await fetchUserModel());
|
||||
return toCheck?.profile?.dateOfBirth != null ? true : false;
|
||||
if (matrixProfile == null) {
|
||||
await fetchUserModel();
|
||||
}
|
||||
return matrixProfile?.dateOfBirth != null ? true : false;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -148,6 +184,16 @@ class UserController extends BaseController {
|
|||
FluffyChatApp.router.go("/rooms/user_age");
|
||||
}
|
||||
|
||||
_saveMatrixProfile(MatrixProfile? matrixProfile) {
|
||||
if (matrixProfile != null) {
|
||||
_pangeaController.pStoreService.save(
|
||||
PLocalKey.matrixProfile,
|
||||
matrixProfile.toJson(),
|
||||
);
|
||||
setState(data: matrixProfile);
|
||||
}
|
||||
}
|
||||
|
||||
_savePUserModel(PUserModel? pUserModel) {
|
||||
if (pUserModel == null) {
|
||||
ErrorHandler.logError(e: "trying to save null userModel");
|
||||
|
|
@ -204,16 +250,21 @@ class UserController extends BaseController {
|
|||
profile: updatedUserProfile,
|
||||
),
|
||||
);
|
||||
|
||||
if (dateOfBirth != null) {
|
||||
await setMatrixProfile(dateOfBirth);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createPangeaUser({required String dob}) async {
|
||||
final PUserModel newUserModel = await PUserRepo.repoCreatePangeaUser(
|
||||
userID: userId!,
|
||||
dateOfBirth: dob,
|
||||
fullName: fullname,
|
||||
matrixAccessToken: _matrixAccessToken!,
|
||||
);
|
||||
await _savePUserModel(newUserModel);
|
||||
|
||||
await setMatrixProfile(dob);
|
||||
}
|
||||
|
||||
String? get _matrixAccessToken =>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:country_picker/country_picker.dart';
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/model_keys.dart';
|
||||
import '../constants/language_keys.dart';
|
||||
import 'language_model.dart';
|
||||
|
||||
|
|
@ -40,6 +39,24 @@ class PUserModel {
|
|||
}
|
||||
}
|
||||
|
||||
class MatrixProfile {
|
||||
String dateOfBirth;
|
||||
|
||||
MatrixProfile({
|
||||
required this.dateOfBirth,
|
||||
});
|
||||
|
||||
factory MatrixProfile.fromJson(Map<String, dynamic> json) => MatrixProfile(
|
||||
dateOfBirth: json[ModelKey.userDateOfBirth],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data[ModelKey.userDateOfBirth] = dateOfBirth;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class Profile {
|
||||
// i'm considering removing this field because it's duplicating info in the
|
||||
// matrix database
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class PUserAgeController extends State<PUserAge> {
|
|||
loading = true;
|
||||
});
|
||||
|
||||
final String date = DateFormat('MM-dd-yyyy').format(selectedDate!);
|
||||
final String date = DateFormat('yyyy-MM-dd').format(selectedDate!);
|
||||
|
||||
if (pangeaController.userController.userModel?.access == null) {
|
||||
await pangeaController.userController.createPangeaUser(dob: date);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import '../network/urls.dart';
|
|||
class PUserRepo {
|
||||
static Future<PUserModel> repoCreatePangeaUser({
|
||||
required String userID,
|
||||
required String dateOfBirth,
|
||||
required fullName,
|
||||
required String matrixAccessToken,
|
||||
}) async {
|
||||
|
|
@ -25,7 +24,6 @@ class PUserRepo {
|
|||
final Map<String, dynamic> body = {
|
||||
ModelKey.userFullName: fullName,
|
||||
ModelKey.userPangeaUserId: userID,
|
||||
ModelKey.userDateOfBirth: dateOfBirth,
|
||||
};
|
||||
final Response res = await req.post(
|
||||
url: PApiUrls.createUser,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:fluffychat/pangea/config/environment.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -35,7 +36,11 @@ class ErrorHandler {
|
|||
options.dsn = Environment.sentryDsn;
|
||||
options.tracesSampleRate = 0.1;
|
||||
options.debug = kDebugMode;
|
||||
options.environment = Environment.isStaging ? "staging" : "productionC";
|
||||
options.environment = kDebugMode
|
||||
? "debug"
|
||||
: Environment.isStaging
|
||||
? "staging"
|
||||
: "productionC";
|
||||
// options.beforeSend = (event, {hint}) {
|
||||
// debugger(when: kDebugMode);
|
||||
// return null;
|
||||
|
|
@ -45,7 +50,7 @@ class ErrorHandler {
|
|||
|
||||
// Error handling
|
||||
FlutterError.onError = (FlutterErrorDetails details) async {
|
||||
if (!kDebugMode) {
|
||||
if (!kDebugMode || PlatformInfos.isMobile) {
|
||||
Sentry.captureException(
|
||||
details.exception,
|
||||
stackTrace: details.stack ?? StackTrace.current,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue