From aea0c9ccecd9cb53e4e4b5c67732a8a29a3ea7eb Mon Sep 17 00:00:00 2001 From: William Jordan-Cooley Date: Tue, 21 May 2024 17:44:09 -0400 Subject: [PATCH] added language detection controller, edited README, and removed some old code --- README.md | 66 ++-------- .../controllers/analytics_sender.dart | 24 ---- .../language_detection_controller.dart | 122 ++++++++++++++++++ lib/pangea/network/urls.dart | 7 +- lib/pangea/repo/message_service.repo.dart | 55 -------- needed-translations.txt | 99 ++++++++++++++ 6 files changed, 233 insertions(+), 140 deletions(-) delete mode 100644 lib/pangea/choreographer/controllers/analytics_sender.dart create mode 100644 lib/pangea/controllers/language_detection_controller.dart delete mode 100644 lib/pangea/repo/message_service.repo.dart diff --git a/README.md b/README.md index 7c4970e002..7c27b6e2e9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ -Pangea Chat Client Setup: +# Overview -* Download VSCode if you do not already have it installed +[Pangea Chat](https://pangea.chat) is a web and mobile platform which lets students ‘learn a language while texting their friends.’ Addressing the gap in communicative language teaching, especially for beginners lacking skill and confidence, Pangea Chat provides a low-stress, high-support environment for language learning through authentic conversations. By integrating human and artificial intelligence, the app enhances communicative abilities and supports educators. Pangea Chat has been grant funded by the National Science Foundation and Virginia Innovation Partnership Corporation based on its technical innovation and potential for broad social impact. Our mission is to build a global, decentralized learning network supporting intercultural learning and exchange. + +# Pangea Chat Client Setup + +* Download VSCode if you do not already have it installed. This is the preferred IDE for development with Pangea Chat. * Download flutter on your device using this guide: https://docs.flutter.dev/get-started/install * Test to make sure that flutter is properly installed by running “flutter –version” * You may need to add flutter to your path manually. Instructions can be found here: https://docs.flutter.dev/get-started/install/macos/mobile-ios?tab=download#add-flutter-to-your-path @@ -14,7 +18,7 @@ Pangea Chat Client Setup: * Run “brew install cocoapods” to install cocoapods * Run “flutter doctor” and for any missing components, follow the instructions from the print out to install / setup * Clone the client repo -* Copy the .env file (and the .env.prod file, if you want to run production builds), into the root folder of the client and the assets/ folder +* Copy the .env file (and the .env.prod file, if you want to run production builds), into the root folder of the client and the assets/ folder. Contact Gabby for a copy of this file. * Uncomment the lines in the pubspec.yaml file in the assets section with paths to .env file * To run on iOS: * Run “flutter precache --ios” @@ -25,62 +29,10 @@ Pangea Chat Client Setup: * On web, run `flutter run -d chrome –hot` * On mobile device or simulator, run `flutter run –hot -d ` -![Screenshot](https://github.com/krille-chan/fluffychat/blob/main/assets/banner_transparent.png?raw=true) - -[FluffyChat](https://fluffychat.im) is an open source, nonprofit and cute [[matrix](https://matrix.org)] client written in [Flutter](https://flutter.dev). The goal of the app is to create an easy to use instant messenger which is open source and accessible for everyone. - -### Links: - -- 🌐 [[Weblate] Translate FluffyChat into your language](https://hosted.weblate.org/projects/fluffychat/) -- 🌍 [[m] Join the community](https://matrix.to/#/#fluffychat:matrix.org) -- 📰 [[Mastodon] Get updates on social media](https://mastodon.art/@krille) -- 🖥️ [[Famedly] Server hosting and professional support](https://famedly.com/kontakt) -- 💝 [[Liberapay] Support FluffyChat development](https://de.liberapay.com/KrilleChritzelius) - -Buy Me a Coffee at ko-fi.com - -### Screenshots: - -![Screenshot](https://github.com/krille-chan/fluffychat/blob/main/docs/screenshots/product.jpeg?raw=true) - -# Features - -- 📩 Send all kinds of messages, images and files -- 🎙️ Voice messages -- 📍 Location sharing -- 🔔 Push notifications -- 💬 Unlimited private and public group chats -- 📣 Public channels with thousands of participants -- 🛠️ Feature rich group moderation including all matrix features -- 🔍 Discover and join public groups -- 🌙 Dark mode -- 🎨 Material You design -- 📟 Hides complexity of Matrix IDs behind simple QR codes -- 😄 Custom emotes and stickers -- 🌌 Spaces -- 🔄 Compatible with Element, Nheko, NeoChat and all other Matrix apps -- 🔐 End to end encryption -- 🔒 Encrypted chat backup -- 😀 Emoji verification & cross signing - -... and much more. - - -# Installation - -Please visit the website for installation instructions: - -- https://fluffychat.im - -# How to build - -Please visit the [Wiki](https://github.com/krille-chan/fluffychat/wiki) for build instructions: - -- https://github.com/krille-chan/fluffychat/wiki/How-To-Build - - # Special thanks +* Pangea Chat is a fork of [FluffyChat](https://fluffychat.im), is an open source, nonprofit and cute [[matrix](https://matrix.org)] client written in [Flutter](https://flutter.dev). The goal of FluffyChat is to create an easy to use instant messenger which is open source and accessible for everyone. You can [support the primary maker of FluffyChat directly here.](https://ko-fi.com/C1C86VN53) + * Fabiyamada is a graphics designer and has made the fluffychat logo and the banner. Big thanks for her great designs. * Advocatux has made the Spanish translation with great love and care. He always stands by my side and supports my work with great commitment. diff --git a/lib/pangea/choreographer/controllers/analytics_sender.dart b/lib/pangea/choreographer/controllers/analytics_sender.dart deleted file mode 100644 index fe4575f384..0000000000 --- a/lib/pangea/choreographer/controllers/analytics_sender.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:fluffychat/pangea/choreographer/controllers/it_controller.dart'; - -class MlController { - final ITController controller; - MlController(this.controller); - - // sendPayloads(String message, String messageId) async { - // final MessageServiceModel serviceModel = MessageServiceModel( - // classId: controller.state!.classId, - // roomId: controller.state!.roomId, - // message: message.toString(), - // messageId: messageId.toString(), - // payloadIds: controller.state!.payLoadIds, - // userId: controller.state!.userId!, - // l1Lang: controller.state!.sourceLangCode, - // l2Lang: controller.state!.targetLangCode!, - // ); - // try { - // await MessageServiceRepo.sendPayloads(serviceModel); - // } catch (err) { - // debugPrint('$err in sendPayloads'); - // } - // } -} diff --git a/lib/pangea/controllers/language_detection_controller.dart b/lib/pangea/controllers/language_detection_controller.dart new file mode 100644 index 0000000000..400cd44199 --- /dev/null +++ b/lib/pangea/controllers/language_detection_controller.dart @@ -0,0 +1,122 @@ +import 'dart:async'; +import 'dart:convert'; + +import 'package:fluffychat/pangea/config/environment.dart'; +import 'package:fluffychat/pangea/controllers/pangea_controller.dart'; +import 'package:fluffychat/pangea/network/urls.dart'; +import 'package:http/http.dart' as http; + +import '../network/requests.dart'; + +class LanguageDetectionRequest { + String fullText; + String userL1; + String userL2; + + LanguageDetectionRequest({ + required this.fullText, + this.userL1 = "", + required this.userL2, + }); + + Map toJson() => { + 'full_text': fullText, + 'user_l1': userL1, + 'user_l2': userL2, + }; + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + return other is LanguageDetectionRequest && + other.fullText == fullText && + other.userL1 == userL1 && + other.userL2 == userL2; + } + + @override + int get hashCode => fullText.hashCode ^ userL1.hashCode ^ userL2.hashCode; +} + +class LanguageDetectionResponse { + List> detections; + String fullText; + + LanguageDetectionResponse({ + required this.detections, + required this.fullText, + }); + + factory LanguageDetectionResponse.fromJson(Map json) { + return LanguageDetectionResponse( + detections: List>.from(json['detections']), + fullText: json['full_text'], + ); + } +} + +class _LanguageDetectionCacheItem { + Future data; + + _LanguageDetectionCacheItem({ + required this.data, + }); +} + +class LanguageDetectionController { + static final Map + _cache = {}; + late final PangeaController _pangeaController; + Timer? _cacheClearTimer; + + LanguageDetectionController(PangeaController pangeaController) { + _pangeaController = pangeaController; + _initializeCacheClearing(); + } + + void _initializeCacheClearing() { + const duration = Duration(minutes: 15); // Adjust the duration as needed + _cacheClearTimer = Timer.periodic(duration, (Timer t) => _clearCache()); + } + + void _clearCache() { + _cache.clear(); + } + + void dispose() { + _cacheClearTimer?.cancel(); + } + + Future get( + LanguageDetectionRequest params, + ) async { + if (_cache.containsKey(params)) { + return _cache[params]!.data; + } else { + final Future response = _fetchResponse( + await _pangeaController.userController.accessToken, + params, + ); + _cache[params] = _LanguageDetectionCacheItem(data: response); + return response; + } + } + + static Future _fetchResponse( + String accessToken, + LanguageDetectionRequest params, + ) async { + final Requests request = Requests( + choreoApiKey: Environment.choreoApi, + accessToken: accessToken, + ); + + final http.Response res = await request.post( + url: PApiUrls.languageDetection, + body: params.toJson(), + ); + + final Map json = jsonDecode(res.body); + return LanguageDetectionResponse.fromJson(json); + } +} diff --git a/lib/pangea/network/urls.dart b/lib/pangea/network/urls.dart index 16d8bcd233..ff0404947a 100644 --- a/lib/pangea/network/urls.dart +++ b/lib/pangea/network/urls.dart @@ -24,13 +24,12 @@ class PApiUrls { /// ---------------------- Conversation Partner ------------------------- static String searchUserProfiles = "/account/search"; - ///-------------------------------- Deprecated analytics -------------------- - static String classAnalytics = "${Environment.choreoApi}/class_analytics"; - static String messageService = "/message_service"; - ///-------------------------------- choreo -------------------------- static String igc = "${Environment.choreoApi}/grammar"; + static String languageDetection = + "${Environment.choreoApi}/language_detection"; + static String igcLite = "${Environment.choreoApi}/grammar_lite"; static String spanDetails = "${Environment.choreoApi}/span_details"; diff --git a/lib/pangea/repo/message_service.repo.dart b/lib/pangea/repo/message_service.repo.dart deleted file mode 100644 index ce51a38026..0000000000 --- a/lib/pangea/repo/message_service.repo.dart +++ /dev/null @@ -1,55 +0,0 @@ -import '../config/environment.dart'; -import '../network/requests.dart'; -import '../network/urls.dart'; - -class MessageServiceRepo { - static Future sendPayloads( - MessageServiceModel serviceModel, - String messageId, - ) async { - final Requests req = Requests( - baseUrl: Environment.choreoApi, - choreoApiKey: Environment.choreoApiKey, - ); - - final json = serviceModel.toJson(); - json["msg_id"] = messageId; - - await req.post(url: PApiUrls.messageService, body: json); - } -} - -class MessageServiceModel { - List payloadIds; - String? messageId; - String message; - String userId; - String roomId; - String? classId; - String? l1Lang; - String l2Lang; - - MessageServiceModel({ - required this.payloadIds, - required this.messageId, - required this.message, - required this.userId, - required this.roomId, - required this.classId, - required this.l1Lang, - required this.l2Lang, - }); - - toJson() { - return { - 'payload_ids': payloadIds, - 'msg_id': messageId, - 'message': message, - 'user_id': userId, - 'room_id': roomId, - 'class_id': classId, - 'l1_lang': l1Lang, - 'l2_lang': l2Lang, - }; - } -} diff --git a/needed-translations.txt b/needed-translations.txt index 7cbcc8a05d..120bd42556 100644 --- a/needed-translations.txt +++ b/needed-translations.txt @@ -821,6 +821,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -2242,6 +2244,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -3125,6 +3129,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -4008,6 +4014,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -4891,6 +4899,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -5774,6 +5784,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -6604,6 +6616,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -7487,6 +7501,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -8370,10 +8386,17 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], + "es": [ + "studentAnalyticsNotAvailable", + "roomDataMissing" + ], + "et": [ "accountInformation", "addGroupDescription", @@ -9196,6 +9219,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -10022,6 +10047,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -10905,6 +10932,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -11788,6 +11817,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -12671,6 +12702,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -13554,6 +13587,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -14380,6 +14415,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -15263,6 +15300,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -16146,6 +16185,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -17016,6 +17057,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -17899,6 +17942,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -19306,6 +19351,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -20189,6 +20236,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -21072,6 +21121,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -21940,6 +21991,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -22823,6 +22876,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -23706,6 +23761,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -24589,6 +24646,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -25472,6 +25531,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -26355,6 +26416,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -27238,6 +27301,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -28121,6 +28186,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -29004,6 +29071,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -29856,6 +29925,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -30739,6 +30810,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -31622,6 +31695,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -32448,6 +32523,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -33331,6 +33408,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -34214,6 +34293,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -35097,6 +35178,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -35945,6 +36028,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -36828,6 +36913,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -37711,6 +37798,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -38579,6 +38668,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -39405,6 +39496,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -40288,6 +40381,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -41114,6 +41209,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ], @@ -41997,6 +42094,8 @@ "accuracy", "points", "noPaymentInfo", + "studentAnalyticsNotAvailable", + "roomDataMissing", "updatePhoneOS", "wordsPerMinute" ]