Compare commits

...

3 commits

10 changed files with 149 additions and 190 deletions

View file

@ -28,6 +28,14 @@ android {
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
ndk {
abiFilters.addAll(listOf("arm64-v8a", "x86_64"))
}
sourceSets {
getByName("main") {
jniLibs.srcDirs("src/main/jniLibs")
}
}
}
buildTypes {

View file

@ -49,6 +49,7 @@ class ApiService {
return [];
}
}
Future<List<GetThreadResponse>> fetchEmailsFromFolderReversed(
String folder, int pagenitaion) async {
try {
@ -82,6 +83,7 @@ class ApiService {
return [];
}
}
Future<void> fetchThreads(
//populates allEmails, which is the List that contains all the emails in a thread
int threadId,
@ -214,7 +216,6 @@ class ApiService {
// SerializableMessage firstMail = mailsInSerializable[0];
try {
for (SerializableMessage mail in mailsInSerializable) {
Map<String, String> requestBody = {
@ -234,7 +235,8 @@ class ApiService {
return true;
} else {
print('error ${response.statusCode} ${response.body}');
}}
}
}
} catch (e) {
print("failed trying to post move_email, with error: $e");
}
@ -252,6 +254,17 @@ class ApiService {
}
}
Future<List<String>> fetchContacts() async {
try {
var url = Uri.http('$ip:$port', 'get_contacts');
var response = await http.get(url);
return List<String>.from(json.decode(response.body));
} catch (e) {
print('fetchFolders caught error: $e');
return [];
}
}
Future<void> createFolder(String folderName) async {
var url = Uri.http('$ip:$port', 'create_folder');
@ -416,6 +429,7 @@ class ApiService {
try {
var url = Uri.http(
'$ip:$port', 'post_seen_thread', {'id': thread_id.toString()});
print("url: $url");
var response = await http.get(url);
if (response.statusCode == 200) {
var result = response.body;
@ -430,6 +444,7 @@ class ApiService {
try {
var url = Uri.http(
'$ip:$port', 'post_unseen_thread', {'id': thread_id.toString()});
print("url: $url");
var response = await http.get(url);
if (response.statusCode == 200) {
var result = response.body;

View file

@ -1,6 +1,4 @@
import 'package:flutter/material.dart';
// import 'package:http/http.dart' as http;
// import 'package:flutter_html/flutter_html.dart';
class ContactsPage extends StatefulWidget {
const ContactsPage({super.key});

View file

@ -78,6 +78,8 @@ class _EmailListScreenState extends State<EmailListScreen>
selectedEmails[email].seen = read;
ApiService()
.markAsSeen(selectedEmails[email].id); //the remote or .json
print(selectedEmails[email].id);
}
} else {
//unread
@ -85,7 +87,7 @@ class _EmailListScreenState extends State<EmailListScreen>
selectedEmails[email].seen = read;
ApiService()
.markAsUnseen(selectedEmails[email].id); //the remote or .json
print(selectedEmails[email].subject);
print(selectedEmails[email].id);
}
}
});

View file

@ -57,7 +57,6 @@ class _EmailViewState extends State<EmailView> {
nameOfDocument: widget.subject,
);
final hardcodedMarkers = [
{'id': 'marker1', 'x': 50, 'y': 100},
{'id': 'marker2', 'x': 150, 'y': 200},
@ -75,6 +74,8 @@ class _EmailViewState extends State<EmailView> {
.emailContent; //html of the email/ actually entire thread, gives me little space to play in between
// i wonder if the other attributes change? because if so i have to add like some zooms in and out of the emails, as in collapse
// _registerViewFactory(currentContent);
print("email content in Collapsable ${widget.emailContent}");
}
void _scrollToNumber(String spanId) {
@ -99,7 +100,6 @@ class _EmailViewState extends State<EmailView> {
});
}
@override
Widget build(BuildContext context) {
ApiService.currThreadID = widget.id;

View file

@ -1,4 +1,5 @@
import 'package:crab_ui/sonicEmailView.dart';
import 'package:go_router/go_router.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'folder_drawer.dart';
@ -223,14 +224,22 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
leading: Icon(Icons.home),
onTap: () {
// Navigate to Home
context.go("/home");
},
),
ListTile(
leading: Icon(Icons.settings),
onTap: () {
// Navigate to Settings
},
),
// ListTile(
// leading: Icon(Icons.settings),
// onTap: () {
// // Navigate to Settings
// },
// ),
// ListTile(
// leading: Icon(Icons.contact_mail),
// onTap: () {
// // Navigate to Contacts
// },
// ),
ListTile(
leading: Icon(Icons.email),
onTap: () {
@ -534,7 +543,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
"Selected folder: $selectedFolder");
// Store the selected folder or perform any action
// ApiService.currFolder = selectedFolder!;
_emailPageKey.currentState! //the one selected
_emailPageKey
.currentState! //the one selected
.moveSelectedOfFolder(selectedFolder!);
_overlayEntry
?.remove();

View file

@ -12,21 +12,21 @@ import 'package:flutter/services.dart' show rootBundle;
class AuthService extends ChangeNotifier {
Future<bool> isUserLoggedIn() async {
ApiService.ip = '192.168.2.38';
ApiService.port = '3001';
print("setted up");
// ApiService.ip = '127.0.0.1';
// ApiService.port = '3001';
// print("setted up");
return true;
// return true;
try {
final response =
await http.get(Uri.http('localhost:6823', 'read-config'));
// await http.get(Uri.parse('http://localhost:6823/read-config'));
await http.get(Uri.http('127.0.0.1:6767', 'login_check'));
print(response.statusCode);
print(response.body);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
// return data['config'];
// print(data['state']);
// return true;
try {
var url = Uri.http('${data['ip']}:${data['port']}', 'is_logged_in');
var response = await http.get(url);
@ -106,18 +106,25 @@ class _SplashScreenState extends State<SplashScreen> {
}
Future<void> _checkLoginStatus() async {
// SharedPreferences prefs = await SharedPreferences.getInstance();
// print(prefs);
// bool isLoggedIn = prefs.getBool('isLoggedIn') ?? false;
await Future.delayed(const Duration(seconds: 1));
bool isLoggedIn = await _authService.isUserLoggedIn();
print("is logged in $isLoggedIn");
if (isLoggedIn) {
try {
final response =
await http.get(Uri.parse('http://127.0.0.1:6767/login_check'));
print(response.statusCode);
print(response.body);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print(data['state']);
if (data['state']) {
context.go("/home");
// Navigator.pushReplacementNamed(context, '/home');
} else {
context.go("/login");
// Navigator.pushReplacementNamed(context, '/login');
}
} else {
context.go("/login");
}
} catch (e) {
print("caught in checkloginstatus in login $e");
context.go("/login");
}
}
@ -139,14 +146,10 @@ class _LoginPageState extends State<LoginPage> {
final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
// final ConfigManager _configManager =
// ConfigManager("${Directory.current.parent}../crabmail2.conf");
// Key to identify the form
final _formKey = GlobalKey<FormState>();
Future<bool> setIp(String ip) async {
//this is not done :sob: :skull:
// _configManager.setField("api_addr", ip);
return false;
}
@ -155,31 +158,16 @@ class _LoginPageState extends State<LoginPage> {
}
Future<void> login() async {
bool result = await _handleLogin();
if (result) {
Navigator.pushReplacementNamed(context, '/home');
var result = await _handleLogin();
if (result[0]) {
ApiService.ip = result[1];
ApiService.port = result[2];
context.go('/home');
}
}
// Future<bool> _checkConfiguration() async {
// return false;
// }
// void checkLogin() async {
// try {
// var url = Uri.http('127.0.0.1:3001', 'is_logged_in');
// var response = await http.get(url);
// print(response.body);
// if (response.statusCode == 200) {
// print('all good on the west');
// }
// } catch (e) {
// print(e);
// }
// // bool isLoggedIn = await _authService.isUserLoggedIn();
// }
// Function to handle login action
Future<bool> _handleLogin() async {
Future<List> _handleLogin() async {
if (_formKey.currentState!.validate()) {
// Perform login action (e.g., authenticate with backend)
String ip = _ipController.text;
@ -193,96 +181,64 @@ class _LoginPageState extends State<LoginPage> {
print(ip);
print(port);
String baseUrl = "http://$ip:$port";
print("baseurl " + baseUrl);
print(baseUrl);
try {
final response =
await http.get(Uri.parse('http://localhost:6823/read-config'));
Map<String, String> requestBody = {
"user": email,
"password": password,
"ip": ip,
"port": port,
};
var url = Uri.http("$ip:6767", "login");
final response = await http.post(url,
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(
requestBody)); //keep the port but change the ip to the server that will process it?
print(response.statusCode);
print(response.body);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
// return data['config'];
if (data["state"] == true) {
try {
final response = await http
.get(Uri.parse('http://127.0.0.1:6767/login_check'));
print(response.statusCode);
print(response.body);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
print(data['state']);
if (data['state']) {
context.go("/home");
} else {
context.go("/login");
}
} else {
context.go("/login");
}
} catch (e) {
print("caught in checkloginstatus in login $e");
context.go("/login");
}
}
return [true, ip, port];
}
return [false];
} catch (e) {
print("caught in catch");
print(e);
return false;
}
Map<String, dynamic> updates = {
// "username": email,
// "password": password,
"ip": ip,
"port": port,
};
print("past");
try {
final sending = await http.post(
Uri.parse('http://localhost:6823/update-config'),
headers: {'Content-Type': "application/json"},
body: jsonEncode(updates));
print("sending");
} catch (e) {
print(e);
return false;
}
try {
// String status = await http.post(Uri.parse(''))
var url_log = Uri.http('$ip:$port', 'log_in');
Map<String, dynamic> filteredData = {
"email": email,
"password": password,
// 'email': updates['username'],
// 'password': updates['password']
};
print(filteredData);
var status = await http.post(
url_log,
headers: {
'Content-Type': 'application/json',
},
body: jsonEncode(filteredData),
);
if (status.statusCode == 200) {
print('response status ${status.body}');
if (status.body == "Successful log in") {
ApiService.ip = ip;
ApiService.port = port;
return true;
return [false];
}
}
} catch (e) {
print(e);
return false;
}
print("after");
return false;
// final content = await _authService.readConfFile();
// final config = await _authService.parseConfFile(content);
// print("BASE URL ${config["base_url"]}");
// print("api address ${config["api_addr"]}");
// print(config);
// const url = ''
// Clear the input fields
// _ipController.clear();
// _portController.clear();
// _emailController.clear();
// _passwordController.clear();
}
return false;
return [false];
}
@override
Widget build(BuildContext context) {
// try {
// _configManager.loadConfig();
// print(_configManager.getField('base_url'));
// } catch (e) {
// print("broke at build $e");
// }
// _configManager.
_ipController.text = "127.0.0.1";
_portController.text = "3001";
return Center(
child: Scaffold(
appBar: AppBar(
@ -317,14 +273,6 @@ class _LoginPageState extends State<LoginPage> {
return 'Please enter your ip';
}
},
// onSaved: (value) async {
// final content = await _authService.readConfFile();
// final config =
// await _authService.parseConfFile(content);
// print("BASE URL ${config["base_url"]}");
// print("api address ${config["api_addr"]}");
// //TODO: call a function to set the field ip in conf
// },
),
),
Container(
@ -403,17 +351,6 @@ class _LoginPageState extends State<LoginPage> {
child: const Text('Login'),
),
),
// SizedBox(
// width: 200,
// child: ElevatedButton(
// // onPressed: checkLogin,
// onPressed: () async {
// await _authService.isUserLoggedIn();
// // print(result);
// },
// child: const Text('checker'),
// ),
// )
],
),
),

View file

@ -22,7 +22,6 @@ class HyM extends StatelessWidget {
@override
Widget build(BuildContext context) {
final GoRouter _router = GoRouter(
// refreshListenable: ,
initialLocation: '/',
routes: [
GoRoute(
@ -48,7 +47,8 @@ class HyM extends StatelessWidget {
final target = state.pathParameters['target']!;
final viewspecs = state.pathParameters['viewspecs']!;
final emailId = state.pathParameters['emailID']!;
return Routinghandler.fromParameters("main anchor", subject, target, viewspecs, emailId);
return Routinghandler.fromParameters(
"main anchor", subject, target, viewspecs, emailId);
}),
]);
return MaterialApp.router(
@ -59,18 +59,6 @@ class HyM extends StatelessWidget {
),
title: 'HyM',
routerConfig: _router,
// home: HomeScreen(),
// routes: {
// "/": (context) => SplashScreen(),
// "/login": (context) => const LoginPage(),
// "/home": (context) => HomeScreen(),
// "/contacts": (context) => ContactsPage(),
// GoRoute(
// path:
// )
// "/email": (context) => EmailListScreen(),
// },
);
}
}

View file

@ -81,7 +81,7 @@ class SerializableMessage {
required this.subject,
required this.date,
required this.uid,
required this.list, //email list???
required this.list, //folder
required this.id,
required this.in_reply_to,
});

View file

@ -34,6 +34,7 @@ dependencies:
super_editor: ^0.3.0-dev.27
super_editor_markdown: 0.1.8
dev_dependencies:
flutter_test:
sdk: flutter