Skip to content

Commit

Permalink
added language detection controller, edited README, and removed some …
Browse files Browse the repository at this point in the history
…old code
  • Loading branch information
William Jordan-Cooley authored and William Jordan-Cooley committed May 21, 2024
1 parent 7e7c881 commit aea0c9c
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 140 deletions.
66 changes: 9 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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”
Expand All @@ -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 <DEVICE_NAME>`

![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)

<a href='https://ko-fi.com/C1C86VN53' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi5.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

### 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)

* <a href="https://github.com/fabiyamada">Fabiyamada</a> is a graphics designer and has made the fluffychat logo and the banner. Big thanks for her great designs.

* <a href="https://github.com/advocatux">Advocatux</a> has made the Spanish translation with great love and care. He always stands by my side and supports my work with great commitment.
Expand Down
24 changes: 0 additions & 24 deletions lib/pangea/choreographer/controllers/analytics_sender.dart

This file was deleted.

122 changes: 122 additions & 0 deletions lib/pangea/controllers/language_detection_controller.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> 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<Map<String, dynamic>> detections;
String fullText;

LanguageDetectionResponse({
required this.detections,
required this.fullText,
});

factory LanguageDetectionResponse.fromJson(Map<String, dynamic> json) {
return LanguageDetectionResponse(
detections: List<Map<String, dynamic>>.from(json['detections']),
fullText: json['full_text'],
);
}
}

class _LanguageDetectionCacheItem {
Future<LanguageDetectionResponse> data;

_LanguageDetectionCacheItem({
required this.data,
});
}

class LanguageDetectionController {
static final Map<LanguageDetectionRequest, _LanguageDetectionCacheItem>
_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<LanguageDetectionResponse> get(
LanguageDetectionRequest params,
) async {
if (_cache.containsKey(params)) {
return _cache[params]!.data;
} else {
final Future<LanguageDetectionResponse> response = _fetchResponse(
await _pangeaController.userController.accessToken,
params,
);
_cache[params] = _LanguageDetectionCacheItem(data: response);
return response;
}
}

static Future<LanguageDetectionResponse> _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<String, dynamic> json = jsonDecode(res.body);
return LanguageDetectionResponse.fromJson(json);
}
}
7 changes: 3 additions & 4 deletions lib/pangea/network/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
55 changes: 0 additions & 55 deletions lib/pangea/repo/message_service.repo.dart

This file was deleted.

Loading

0 comments on commit aea0c9c

Please sign in to comment.