remove matrix widget reference from pangea controller
This commit is contained in:
parent
3ac8339817
commit
25bae8baf6
24 changed files with 241 additions and 246 deletions
|
|
@ -42,6 +42,7 @@ import '../../widgets/matrix.dart';
|
|||
import 'package:fluffychat/utils/tor_stub.dart'
|
||||
if (dart.library.html) 'package:tor_detector_web/tor_detector_web.dart';
|
||||
|
||||
|
||||
enum PopupMenuAction {
|
||||
settings,
|
||||
invite,
|
||||
|
|
@ -565,8 +566,10 @@ class ChatListController extends State<ChatList>
|
|||
_checkTorBrowser();
|
||||
|
||||
//#Pangea
|
||||
_invitedSpaceSubscription = MatrixState
|
||||
.pangeaController.matrixState.client.onSync.stream
|
||||
_invitedSpaceSubscription = Matrix.of(context)
|
||||
.client
|
||||
.onSync
|
||||
.stream
|
||||
.where((event) => event.rooms?.invite != null)
|
||||
.listen((event) async {
|
||||
for (final inviteEntry in event.rooms!.invite!.entries) {
|
||||
|
|
@ -584,10 +587,9 @@ class ChatListController extends State<ChatList>
|
|||
|
||||
if (isSpace) {
|
||||
final spaceId = inviteEntry.key;
|
||||
final space =
|
||||
MatrixState.pangeaController.matrixState.client.getRoomById(
|
||||
spaceId,
|
||||
);
|
||||
final space = Matrix.of(context).client.getRoomById(
|
||||
spaceId,
|
||||
);
|
||||
|
||||
if (space?.classCode?.toLowerCase() ==
|
||||
SpaceCodeRepo.recentCode?.toLowerCase()) {
|
||||
|
|
@ -603,8 +605,8 @@ class ChatListController extends State<ChatList>
|
|||
}
|
||||
|
||||
if (isAnalytics) {
|
||||
final analyticsRoom = MatrixState.pangeaController.matrixState.client
|
||||
.getRoomById(inviteEntry.key);
|
||||
final analyticsRoom =
|
||||
Matrix.of(context).client.getRoomById(inviteEntry.key);
|
||||
try {
|
||||
await analyticsRoom?.join();
|
||||
} catch (err, s) {
|
||||
|
|
@ -626,7 +628,7 @@ class ChatListController extends State<ChatList>
|
|||
// 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
|
||||
// reload any rooms that have been added / removed
|
||||
final client = MatrixState.pangeaController.matrixState.client;
|
||||
final client = Matrix.of(context).client;
|
||||
|
||||
// listen for room join events and leave room if over capacity
|
||||
_roomCapacitySubscription ??= client.onSync.stream
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/login/pages/login_options_view.dart';
|
||||
import 'package:fluffychat/pangea/login/pages/pangea_login_view.dart';
|
||||
import 'package:fluffychat/pangea/login/widgets/p_sso_button.dart';
|
||||
import 'package:fluffychat/pangea/user/utils/p_login.dart';
|
||||
import 'package:fluffychat/pangea/user/p_login.dart';
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
|
||||
|
|
@ -46,7 +46,6 @@ class LoginController extends State<Login> {
|
|||
bool loadingAppleSSO = false;
|
||||
bool loadingGoogleSSO = false;
|
||||
|
||||
final PangeaController pangeaController = MatrixState.pangeaController;
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
Client? client;
|
||||
|
|
@ -61,7 +60,7 @@ class LoginController extends State<Login> {
|
|||
// TODO: implement initState
|
||||
super.initState();
|
||||
loadingSignIn = true;
|
||||
pangeaController.checkHomeServerAction().then((client) {
|
||||
checkHomeServerAction().then((client) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
loadingSignIn = false;
|
||||
|
|
@ -234,6 +233,30 @@ class LoginController extends State<Login> {
|
|||
// if (mounted) setState(() {});
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<Client> checkHomeServerAction() async {
|
||||
final client = await Matrix.of(context).getLoginClient();
|
||||
if (client.homeserver != null) {
|
||||
await Future.delayed(Duration.zero);
|
||||
return client;
|
||||
}
|
||||
|
||||
final String homeServer =
|
||||
AppConfig.defaultHomeserver.trim().toLowerCase().replaceAll(' ', '-');
|
||||
var homeserver = Uri.parse(homeServer);
|
||||
if (homeserver.scheme.isEmpty) {
|
||||
homeserver = Uri.https(homeServer, '');
|
||||
}
|
||||
|
||||
try {
|
||||
await client.register();
|
||||
Matrix.of(context).loginRegistrationSupported = true;
|
||||
} on MatrixException catch (e) {
|
||||
Matrix.of(context).loginRegistrationSupported =
|
||||
e.requireAdditionalAuthentication;
|
||||
}
|
||||
return client;
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
void passwordForgotten() async {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import 'package:image_picker/image_picker.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/user/utils/p_logout.dart';
|
||||
import 'package:fluffychat/pangea/user/p_logout.dart';
|
||||
import 'package:fluffychat/utils/file_selector.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ class AnalyticsDownloadDialogState extends State<AnalyticsDownloadDialog> {
|
|||
return;
|
||||
}
|
||||
|
||||
final client = Matrix.of(context).client;
|
||||
try {
|
||||
if (_downloadType == DownloadType.csv) {
|
||||
final vocabContent = _getCSVFileContent(
|
||||
|
|
@ -96,10 +97,10 @@ class AnalyticsDownloadDialogState extends State<AnalyticsDownloadDialog> {
|
|||
);
|
||||
|
||||
final vocabFileName =
|
||||
"analytics_vocab_${MatrixState.pangeaController.matrixState.client.userID?.localpart}_${DateFormat('yyyy-MM-dd-hh:mm:ss').format(DateTime.now())}.csv";
|
||||
"analytics_vocab_${client.userID?.localpart}_${DateFormat('yyyy-MM-dd-hh:mm:ss').format(DateTime.now())}.csv";
|
||||
|
||||
final morphFileName =
|
||||
"analytics_morph_${MatrixState.pangeaController.matrixState.client.userID?.localpart}_${DateFormat('yyyy-MM-dd-hh:mm:ss').format(DateTime.now())}.csv";
|
||||
"analytics_morph_${client.userID?.localpart}_${DateFormat('yyyy-MM-dd-hh:mm:ss').format(DateTime.now())}.csv";
|
||||
|
||||
final futures = [
|
||||
DownloadUtil.downloadFile(
|
||||
|
|
@ -122,7 +123,7 @@ class AnalyticsDownloadDialogState extends State<AnalyticsDownloadDialog> {
|
|||
});
|
||||
|
||||
final fileName =
|
||||
"analytics_${MatrixState.pangeaController.matrixState.client.userID?.localpart}_${DateFormat('yyyy-MM-dd-hh:mm:ss').format(DateTime.now())}.xlsx'}";
|
||||
"analytics_${client.userID?.localpart}_${DateFormat('yyyy-MM-dd-hh:mm:ss').format(DateTime.now())}.xlsx'}";
|
||||
|
||||
await DownloadUtil.downloadFile(
|
||||
content,
|
||||
|
|
@ -263,8 +264,8 @@ class AnalyticsDownloadDialogState extends State<AnalyticsDownloadDialog> {
|
|||
final List<PangeaMessageEvent> examples = [];
|
||||
for (final OneConstructUse use in allUses) {
|
||||
if (use.metadata.roomId == null) continue;
|
||||
final Room? room = MatrixState.pangeaController.matrixState.client
|
||||
.getRoomById(use.metadata.roomId!);
|
||||
final client = Matrix.of(context).client;
|
||||
final Room? room = client.getRoomById(use.metadata.roomId!);
|
||||
if (room == null) continue;
|
||||
|
||||
if (use.useType.skillsEnumType != LearningSkillsEnum.writing ||
|
||||
|
|
@ -287,12 +288,11 @@ class AnalyticsDownloadDialogState extends State<AnalyticsDownloadDialog> {
|
|||
|
||||
final Event? event = await room.getEventById(use.metadata.eventId!);
|
||||
|
||||
if (event == null || event.senderId != room.client.userID) continue;
|
||||
if (event == null || event.senderId != client.userID) continue;
|
||||
final PangeaMessageEvent pangeaMessageEvent = PangeaMessageEvent(
|
||||
event: event,
|
||||
timeline: timeline!,
|
||||
ownMessage: event.senderId ==
|
||||
MatrixState.pangeaController.matrixState.client.userID,
|
||||
ownMessage: event.senderId == client.userID,
|
||||
);
|
||||
examples.add(pangeaMessageEvent);
|
||||
if (examples.length >= 5) break;
|
||||
|
|
|
|||
|
|
@ -379,8 +379,8 @@ class GetAnalyticsController extends BaseController {
|
|||
// this function gets called soon after login, so first
|
||||
// make sure that the user's l2 is loaded, if the user has set their l2
|
||||
if (_client.userID != null && _l2 == null) {
|
||||
if (_pangeaController.matrixState.client.prevBatch == null) {
|
||||
await _pangeaController.matrixState.client.onSync.stream.first;
|
||||
if (_client.prevBatch == null) {
|
||||
await _client.onSync.stream.first;
|
||||
}
|
||||
if (_l2 == null) return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,6 @@ class LevelUpBannerState extends State<LevelUpBanner>
|
|||
_loadConstructSummary();
|
||||
|
||||
LevelUpManager.instance.preloadAnalytics(
|
||||
context,
|
||||
widget.level,
|
||||
widget.prevLevel,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/analytics_misc/client_analytics_extension.dart';
|
||||
|
|
@ -27,7 +25,6 @@ class LevelUpManager {
|
|||
bool shouldAutoPopup = false;
|
||||
|
||||
Future<void> preloadAnalytics(
|
||||
BuildContext context,
|
||||
int level,
|
||||
int prevLevel,
|
||||
) async {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class PutAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
/// If analytics haven't been updated in the last day, update them
|
||||
Future<void> _refreshAnalyticsIfOutdated() async {
|
||||
// don't set anything is the user is not logged in
|
||||
if (_pangeaController.matrixState.client.userID == null) return;
|
||||
if (_client.userID == null) return;
|
||||
try {
|
||||
// if lastUpdated hasn't been set yet, set it
|
||||
lastUpdated ??=
|
||||
|
|
@ -359,7 +359,7 @@ class PutAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
onLogout = false,
|
||||
LanguageModel? l2Override,
|
||||
}) async {
|
||||
if (_pangeaController.matrixState.client.userID == null) return;
|
||||
if (_client.userID == null) return;
|
||||
if (_pangeaController.getAnalytics.messagesSinceUpdate.isEmpty) return;
|
||||
|
||||
if (!(_updateCompleter?.isCompleted ?? true)) {
|
||||
|
|
@ -417,7 +417,7 @@ class PutAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
}
|
||||
|
||||
Future<void> sendActivityAnalytics(String roomId) async {
|
||||
if (_pangeaController.matrixState.client.userID == null) return;
|
||||
if (_client.userID == null) return;
|
||||
if (_pangeaController.userController.userL2 == null) return;
|
||||
|
||||
final Room? analyticsRoom = await _client.getMyAnalyticsRoom(
|
||||
|
|
@ -435,7 +435,7 @@ class PutAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
}
|
||||
|
||||
Future<void> removeActivityAnalytics(String roomId) async {
|
||||
if (_pangeaController.matrixState.client.userID == null) return;
|
||||
if (_client.userID == null) return;
|
||||
if (_pangeaController.userController.userL2 == null) return;
|
||||
|
||||
final Room? analyticsRoom = await _client.getMyAnalyticsRoom(
|
||||
|
|
|
|||
|
|
@ -53,4 +53,23 @@ extension BotClientExtension on Client {
|
|||
),
|
||||
],
|
||||
);
|
||||
|
||||
Future<void> updateBotOptions() async {
|
||||
if (!isLogged() || botDM == null) return;
|
||||
|
||||
final targetLanguage =
|
||||
MatrixState.pangeaController.userController.userL2?.langCode;
|
||||
final cefrLevel = MatrixState
|
||||
.pangeaController.userController.profile.userSettings.cefrLevel;
|
||||
final updateBotOptions = botDM!.botOptions ?? BotOptionsModel();
|
||||
|
||||
if (updateBotOptions.targetLanguage == targetLanguage &&
|
||||
updateBotOptions.languageLevel == cefrLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateBotOptions.targetLanguage = targetLanguage;
|
||||
updateBotOptions.languageLevel = cefrLevel;
|
||||
await botDM!.setBotOptions(updateBotOptions);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,20 +7,16 @@ import 'package:matrix/matrix.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/analytics_misc/get_analytics_controller.dart';
|
||||
import 'package:fluffychat/pangea/analytics_misc/put_analytics_controller.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/chat_settings/models/bot_options_model.dart';
|
||||
import 'package:fluffychat/pangea/chat_settings/utils/bot_client_extension.dart';
|
||||
import 'package:fluffychat/pangea/events/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/guard/p_vguard.dart';
|
||||
import 'package:fluffychat/pangea/languages/locale_provider.dart';
|
||||
import 'package:fluffychat/pangea/languages/p_language_store.dart';
|
||||
import 'package:fluffychat/pangea/subscription/controllers/subscription_controller.dart';
|
||||
import 'package:fluffychat/pangea/text_to_speech/tts_controller.dart';
|
||||
import 'package:fluffychat/pangea/user/controllers/user_controller.dart';
|
||||
import 'package:fluffychat/pangea/user/pangea_push_rules_extension.dart';
|
||||
import 'package:fluffychat/pangea/user/user_controller.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../utils/firebase_analytics.dart';
|
||||
|
||||
|
|
@ -38,16 +34,15 @@ class PangeaController {
|
|||
StreamSubscription? _settingsSubscription;
|
||||
|
||||
///Matrix Variables
|
||||
MatrixState matrixState;
|
||||
Matrix matrix;
|
||||
final MatrixState matrixState;
|
||||
|
||||
PangeaController({required this.matrix, required this.matrixState}) {
|
||||
PangeaController({required this.matrixState}) {
|
||||
userController = UserController(this);
|
||||
getAnalytics = GetAnalyticsController(this);
|
||||
putAnalytics = PutAnalyticsController(this);
|
||||
subscriptionController = SubscriptionController(this);
|
||||
PAuthGaurd.pController = this;
|
||||
_setSettingsSubscriptions();
|
||||
_registerSubscriptions();
|
||||
}
|
||||
|
||||
/// Initializes various controllers and settings.
|
||||
|
|
@ -57,17 +52,115 @@ class PangeaController {
|
|||
void initControllers() {
|
||||
_initAnalyticsControllers();
|
||||
subscriptionController.initialize();
|
||||
setPangeaPushRules();
|
||||
matrixState.client.setPangeaPushRules();
|
||||
TtsController.setAvailableLanguages();
|
||||
}
|
||||
|
||||
void _logOutfromPangea(BuildContext context) {
|
||||
debugPrint("Pangea logout");
|
||||
void _onLogin(BuildContext context) {
|
||||
initControllers();
|
||||
_registerSubscriptions();
|
||||
|
||||
userController.reinitialize().then((_) {
|
||||
final l1 = userController.profile.userSettings.sourceLanguage;
|
||||
Provider.of<LocaleProvider>(context, listen: false).setLocale(l1);
|
||||
});
|
||||
subscriptionController.reinitialize();
|
||||
}
|
||||
|
||||
void _onLogout(BuildContext context) {
|
||||
_disposeAnalyticsControllers();
|
||||
userController.clear();
|
||||
_languageSubscription?.cancel();
|
||||
_settingsSubscription?.cancel();
|
||||
_languageSubscription = null;
|
||||
_settingsSubscription = null;
|
||||
|
||||
GoogleAnalytics.logout();
|
||||
clearCache();
|
||||
_clearCache();
|
||||
Provider.of<LocaleProvider>(context, listen: false).setLocale(null);
|
||||
}
|
||||
|
||||
void handleLoginStateChange(
|
||||
LoginState state,
|
||||
String? userID,
|
||||
BuildContext context,
|
||||
) {
|
||||
switch (state) {
|
||||
case LoginState.loggedOut:
|
||||
case LoginState.softLoggedOut:
|
||||
_onLogout(context);
|
||||
break;
|
||||
case LoginState.loggedIn:
|
||||
_onLogin(context);
|
||||
break;
|
||||
}
|
||||
|
||||
Sentry.configureScope(
|
||||
(scope) => scope.setUser(
|
||||
SentryUser(
|
||||
id: userID,
|
||||
name: userID,
|
||||
),
|
||||
),
|
||||
);
|
||||
GoogleAnalytics.analyticsUserUpdate(userID);
|
||||
}
|
||||
|
||||
void _disposeAnalyticsControllers() {
|
||||
putAnalytics.dispose();
|
||||
getAnalytics.dispose();
|
||||
}
|
||||
|
||||
void _registerSubscriptions() {
|
||||
_languageSubscription?.cancel();
|
||||
_languageSubscription =
|
||||
userController.languageStream.stream.listen(_onLanguageUpdate);
|
||||
|
||||
_settingsSubscription?.cancel();
|
||||
_settingsSubscription = userController.settingsUpdateStream.stream
|
||||
.listen((_) => matrixState.client.updateBotOptions());
|
||||
}
|
||||
|
||||
Future<void> _clearCache({List<String> exclude = const []}) async {
|
||||
final List<Future<void>> futures = [];
|
||||
for (final key in _storageKeys) {
|
||||
if (exclude.contains(key)) continue;
|
||||
futures.add(GetStorage(key).erase());
|
||||
}
|
||||
await Future.wait(futures);
|
||||
}
|
||||
|
||||
Future<void> _initAnalyticsControllers() async {
|
||||
putAnalytics.initialize();
|
||||
await getAnalytics.initialize();
|
||||
}
|
||||
|
||||
Future<void> resetAnalytics() async {
|
||||
_disposeAnalyticsControllers();
|
||||
await _initAnalyticsControllers();
|
||||
}
|
||||
|
||||
Future<void> _onLanguageUpdate(LanguageUpdate update) async {
|
||||
final exclude = [
|
||||
'analytics_storage',
|
||||
'course_location_media_storage',
|
||||
'course_location_storage',
|
||||
'course_media_storage',
|
||||
];
|
||||
|
||||
// only clear course data if the base language has changed
|
||||
if (update.prevBaseLang == update.baseLang) {
|
||||
exclude.addAll([
|
||||
'course_storage',
|
||||
'course_topic_storage',
|
||||
'course_activity_storage',
|
||||
]);
|
||||
}
|
||||
|
||||
_clearCache(exclude: exclude);
|
||||
matrixState.client.updateBotOptions();
|
||||
}
|
||||
|
||||
static final List<String> _storageKeys = [
|
||||
'mode_list_storage',
|
||||
'activity_plan_storage',
|
||||
|
|
@ -96,186 +189,4 @@ class PangeaController {
|
|||
'course_location_media_storage',
|
||||
'language_mismatch',
|
||||
];
|
||||
|
||||
Future<void> clearCache({List<String> exclude = const []}) async {
|
||||
final List<Future<void>> futures = [];
|
||||
for (final key in _storageKeys) {
|
||||
if (exclude.contains(key)) continue;
|
||||
futures.add(GetStorage(key).erase());
|
||||
}
|
||||
await Future.wait(futures);
|
||||
}
|
||||
|
||||
Future<Client> checkHomeServerAction() async {
|
||||
final client = await matrixState.getLoginClient();
|
||||
if (client.homeserver != null) {
|
||||
await Future.delayed(Duration.zero);
|
||||
return client;
|
||||
}
|
||||
|
||||
final String homeServer =
|
||||
AppConfig.defaultHomeserver.trim().toLowerCase().replaceAll(' ', '-');
|
||||
var homeserver = Uri.parse(homeServer);
|
||||
if (homeserver.scheme.isEmpty) {
|
||||
homeserver = Uri.https(homeServer, '');
|
||||
}
|
||||
|
||||
try {
|
||||
await client.register();
|
||||
matrixState.loginRegistrationSupported = true;
|
||||
} on MatrixException catch (e) {
|
||||
matrixState.loginRegistrationSupported =
|
||||
e.requireAdditionalAuthentication;
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
/// check user information if not found then redirect to Date of birth page
|
||||
void handleLoginStateChange(
|
||||
LoginState state,
|
||||
String? userID,
|
||||
BuildContext context,
|
||||
) {
|
||||
switch (state) {
|
||||
case LoginState.loggedOut:
|
||||
case LoginState.softLoggedOut:
|
||||
// Reset cached analytics data
|
||||
_disposeAnalyticsControllers();
|
||||
userController.clear();
|
||||
_languageSubscription?.cancel();
|
||||
_settingsSubscription?.cancel();
|
||||
_languageSubscription = null;
|
||||
_settingsSubscription = null;
|
||||
_logOutfromPangea(context);
|
||||
break;
|
||||
case LoginState.loggedIn:
|
||||
// Initialize analytics data
|
||||
initControllers();
|
||||
_setSettingsSubscriptions();
|
||||
|
||||
userController.reinitialize().then((_) {
|
||||
final l1 = userController.profile.userSettings.sourceLanguage;
|
||||
Provider.of<LocaleProvider>(context, listen: false).setLocale(l1);
|
||||
});
|
||||
subscriptionController.reinitialize();
|
||||
break;
|
||||
}
|
||||
|
||||
Sentry.configureScope(
|
||||
(scope) => scope.setUser(
|
||||
SentryUser(
|
||||
id: userID,
|
||||
name: userID,
|
||||
),
|
||||
),
|
||||
);
|
||||
GoogleAnalytics.analyticsUserUpdate(userID);
|
||||
}
|
||||
|
||||
Future<void> _initAnalyticsControllers() async {
|
||||
putAnalytics.initialize();
|
||||
await getAnalytics.initialize();
|
||||
}
|
||||
|
||||
void _disposeAnalyticsControllers() {
|
||||
putAnalytics.dispose();
|
||||
getAnalytics.dispose();
|
||||
}
|
||||
|
||||
Future<void> resetAnalytics() async {
|
||||
_disposeAnalyticsControllers();
|
||||
await _initAnalyticsControllers();
|
||||
}
|
||||
|
||||
void _setSettingsSubscriptions() {
|
||||
_languageSubscription?.cancel();
|
||||
_languageSubscription =
|
||||
userController.languageStream.stream.listen(_onLanguageUpdate);
|
||||
_settingsSubscription?.cancel();
|
||||
_settingsSubscription = userController.settingsUpdateStream.stream
|
||||
.listen((_) => _updateBotOptions());
|
||||
}
|
||||
|
||||
Future<void> _onLanguageUpdate(LanguageUpdate update) async {
|
||||
final exclude = [
|
||||
'analytics_storage',
|
||||
'course_location_media_storage',
|
||||
'course_location_storage',
|
||||
'course_media_storage',
|
||||
];
|
||||
|
||||
// only clear course data if the base language has changed
|
||||
if (update.prevBaseLang == update.baseLang) {
|
||||
exclude.addAll([
|
||||
'course_storage',
|
||||
'course_topic_storage',
|
||||
'course_activity_storage',
|
||||
]);
|
||||
}
|
||||
|
||||
clearCache(exclude: exclude);
|
||||
_updateBotOptions();
|
||||
}
|
||||
|
||||
Future<void> _updateBotOptions() async {
|
||||
if (!matrixState.client.isLogged()) return;
|
||||
final botDM = matrixState.client.botDM;
|
||||
if (botDM == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final targetLanguage = userController.userL2?.langCode;
|
||||
final cefrLevel = userController.profile.userSettings.cefrLevel;
|
||||
final updateBotOptions = botDM.botOptions ?? BotOptionsModel();
|
||||
|
||||
if (updateBotOptions.targetLanguage == targetLanguage &&
|
||||
updateBotOptions.languageLevel == cefrLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateBotOptions.targetLanguage = targetLanguage;
|
||||
updateBotOptions.languageLevel = cefrLevel;
|
||||
await botDM.setBotOptions(updateBotOptions);
|
||||
}
|
||||
|
||||
Future<void> setPangeaPushRules() async {
|
||||
if (!matrixState.client.isLogged()) return;
|
||||
final List<Room> analyticsRooms =
|
||||
matrixState.client.rooms.where((room) => room.isAnalyticsRoom).toList();
|
||||
|
||||
for (final Room room in analyticsRooms) {
|
||||
final pushRule = room.pushRuleState;
|
||||
if (pushRule != PushRuleState.dontNotify) {
|
||||
await room.setPushRuleState(PushRuleState.dontNotify);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(matrixState.client.globalPushRules?.override?.any(
|
||||
(element) => element.ruleId == PangeaEventTypes.textToSpeechRule,
|
||||
) ??
|
||||
false)) {
|
||||
await matrixState.client.setPushRule(
|
||||
PushRuleKind.override,
|
||||
PangeaEventTypes.textToSpeechRule,
|
||||
[PushRuleAction.dontNotify],
|
||||
conditions: [
|
||||
PushCondition(
|
||||
kind: 'event_match',
|
||||
key: 'content.msgtype',
|
||||
pattern: MessageTypes.Audio,
|
||||
),
|
||||
PushCondition(
|
||||
kind: 'event_match',
|
||||
key: 'content.transcription.lang_code',
|
||||
pattern: '*',
|
||||
),
|
||||
PushCondition(
|
||||
kind: 'event_match',
|
||||
key: 'content.transcription.text',
|
||||
pattern: '*',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import 'package:fluffychat/pangea/learning_settings/language_level_type_enum.dar
|
|||
import 'package:fluffychat/pangea/learning_settings/settings_learning_view.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/tool_settings_enum.dart';
|
||||
import 'package:fluffychat/pangea/text_to_speech/tts_controller.dart';
|
||||
import 'package:fluffychat/pangea/user/models/user_model.dart';
|
||||
import 'package:fluffychat/pangea/user/user_model.dart';
|
||||
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import 'package:fluffychat/pangea/space_analytics/space_analytics_download_enum.
|
|||
import 'package:fluffychat/pangea/space_analytics/space_analytics_inactive_dialog.dart';
|
||||
import 'package:fluffychat/pangea/space_analytics/space_analytics_request_dialog.dart';
|
||||
import 'package:fluffychat/pangea/space_analytics/space_analytics_view.dart';
|
||||
import 'package:fluffychat/pangea/user/models/analytics_profile_model.dart';
|
||||
import 'package:fluffychat/pangea/user/analytics_profile_model.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import 'package:matrix/matrix.dart';
|
|||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/bot/utils/bot_name.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/user/models/analytics_profile_model.dart';
|
||||
import 'package:fluffychat/pangea/user/analytics_profile_model.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class LoadParticipantsBuilder extends StatefulWidget {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import 'package:fluffychat/pangea/subscription/repo/subscription_management_repo
|
|||
import 'package:fluffychat/pangea/subscription/repo/subscription_repo.dart';
|
||||
import 'package:fluffychat/pangea/subscription/utils/subscription_app_id.dart';
|
||||
import 'package:fluffychat/pangea/subscription/widgets/subscription_paywall.dart';
|
||||
import 'package:fluffychat/pangea/user/controllers/user_controller.dart';
|
||||
import 'package:fluffychat/pangea/user/user_controller.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/subscription/widgets/subscription_options.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class SubscriptionPaywall extends StatelessWidget {
|
||||
final PangeaController pangeaController;
|
||||
|
|
@ -30,7 +31,7 @@ class SubscriptionPaywall extends StatelessWidget {
|
|||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (pangeaController.matrixState.client.rooms.length > 1) ...[
|
||||
if (Matrix.of(context).client.rooms.length > 1) ...[
|
||||
Text(
|
||||
L10n.of(context).welcomeBack,
|
||||
textAlign: TextAlign.center,
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class MessageSelectionPositionerState extends State<MessageSelectionPositioner>
|
|||
_reactionSubscription?.cancel();
|
||||
_contentChangedSubscription?.cancel();
|
||||
scrollController?.dispose();
|
||||
MatrixState.pangeaController.matrixState.audioPlayer
|
||||
Matrix.of(context).audioPlayer
|
||||
?..stop()
|
||||
..dispose();
|
||||
super.dispose();
|
||||
|
|
|
|||
47
lib/pangea/user/pangea_push_rules_extension.dart
Normal file
47
lib/pangea/user/pangea_push_rules_extension.dart
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/events/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension.dart';
|
||||
|
||||
extension PangeaPushRulesExtension on Client {
|
||||
Future<void> setPangeaPushRules() async {
|
||||
if (!isLogged()) return;
|
||||
final List<Room> analyticsRooms =
|
||||
rooms.where((room) => room.isAnalyticsRoom).toList();
|
||||
|
||||
for (final Room room in analyticsRooms) {
|
||||
final pushRule = room.pushRuleState;
|
||||
if (pushRule != PushRuleState.dontNotify) {
|
||||
await room.setPushRuleState(PushRuleState.dontNotify);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(globalPushRules?.override?.any(
|
||||
(element) => element.ruleId == PangeaEventTypes.textToSpeechRule,
|
||||
) ??
|
||||
false)) {
|
||||
await setPushRule(
|
||||
PushRuleKind.override,
|
||||
PangeaEventTypes.textToSpeechRule,
|
||||
[PushRuleAction.dontNotify],
|
||||
conditions: [
|
||||
PushCondition(
|
||||
kind: 'event_match',
|
||||
key: 'content.msgtype',
|
||||
pattern: MessageTypes.Audio,
|
||||
),
|
||||
PushCondition(
|
||||
kind: 'event_match',
|
||||
key: 'content.transcription.lang_code',
|
||||
pattern: '*',
|
||||
),
|
||||
PushCondition(
|
||||
kind: 'event_match',
|
||||
key: 'content.transcription.text',
|
||||
pattern: '*',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,9 +17,9 @@ import 'package:fluffychat/pangea/languages/language_model.dart';
|
|||
import 'package:fluffychat/pangea/languages/language_service.dart';
|
||||
import 'package:fluffychat/pangea/languages/p_language_store.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/tool_settings_enum.dart';
|
||||
import 'package:fluffychat/pangea/user/models/activities_profile_model.dart';
|
||||
import 'package:fluffychat/pangea/user/models/analytics_profile_model.dart';
|
||||
import '../models/user_model.dart';
|
||||
import 'package:fluffychat/pangea/user/activities_profile_model.dart';
|
||||
import 'package:fluffychat/pangea/user/analytics_profile_model.dart';
|
||||
import 'user_model.dart';
|
||||
|
||||
class LanguageUpdate {
|
||||
final LanguageModel? prevBaseLang;
|
||||
|
|
@ -370,8 +370,7 @@ class UserController {
|
|||
baseLanguage ??= _pangeaController.userController.userL1;
|
||||
if (targetLanguage == null || analyticsProfile == null) return;
|
||||
|
||||
final analyticsRoom =
|
||||
_pangeaController.matrixState.client.analyticsRoomLocal(targetLanguage);
|
||||
final analyticsRoom = client.analyticsRoomLocal(targetLanguage);
|
||||
|
||||
if (analyticsProfile!.targetLanguage == targetLanguage &&
|
||||
analyticsProfile!.baseLanguage == baseLanguage &&
|
||||
|
|
@ -396,8 +395,7 @@ class UserController {
|
|||
|
||||
Future<void> _addAnalyticsRoomIdsToPublicProfile() async {
|
||||
if (analyticsProfile?.languageAnalytics == null) return;
|
||||
final analyticsRooms =
|
||||
_pangeaController.matrixState.client.allMyAnalyticsRooms;
|
||||
final analyticsRooms = client.allMyAnalyticsRooms;
|
||||
|
||||
if (analyticsRooms.isEmpty) return;
|
||||
for (final analyticsRoom in analyticsRooms) {
|
||||
|
|
@ -434,9 +432,7 @@ class UserController {
|
|||
analyticsProfile!.addXPOffset(
|
||||
targetLanguage,
|
||||
offset,
|
||||
_pangeaController.matrixState.client
|
||||
.analyticsRoomLocal(targetLanguage)
|
||||
?.id,
|
||||
client.analyticsRoomLocal(targetLanguage)?.id,
|
||||
);
|
||||
await _savePublicProfileUpdate(
|
||||
PangeaEventTypes.profileAnalytics,
|
||||
|
|
@ -6,7 +6,7 @@ import 'package:fluffychat/pangea/instructions/instruction_settings.dart';
|
|||
import 'package:fluffychat/pangea/learning_settings/language_level_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/tool_settings_enum.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../languages/language_model.dart';
|
||||
import '../languages/language_model.dart';
|
||||
|
||||
/// The user's settings learning settings.
|
||||
class UserSettings {
|
||||
|
|
@ -273,7 +273,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
),
|
||||
),
|
||||
);
|
||||
pangeaController = PangeaController(matrix: widget, matrixState: this);
|
||||
pangeaController = PangeaController(matrixState: this);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_setAppLanguage();
|
||||
_setLanguageListener();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue