latest bug with sonic

This commit is contained in:
Juan Marulanda De Los Rios 2024-12-12 12:47:39 -05:00
parent a0652ba5c5
commit ed9d2d8a7b
4 changed files with 73 additions and 17 deletions

View File

@ -13,7 +13,7 @@ class ApiService {
Future<List<GetThreadResponse>> fetchEmailsFromFolder(
String folder, int pagenitaion) async {
try {
var url = Uri.http('127.0.0.1:3001', 'sorted_threads_by_date', {
var url = Uri.http('0.0.0.0:3001', 'sorted_threads_by_date', {
'folder': folder,
'limit': '50',
'offset': pagenitaion.toString(),
@ -49,7 +49,7 @@ class ApiService {
List<GetThreadResponse> allEmails) async {
try {
var url =
Uri.http('127.0.0.1:3001', 'get_thread', {'id': threadId.toString()});
Uri.http('0.0.0.0:3001', 'get_thread', {'id': threadId.toString()});
var response = await http.get(url);
if (response.statusCode == 200) {
@ -70,15 +70,16 @@ class ApiService {
Future<List<SerializableMessage>> sonicSearch(
String list, int limit, int offset, String query) async {
try {
var url = Uri.http('127.0.0.1:3001', 'search', {
var url = Uri.http('0.0.0.0:3001', 'search_emails', {
'list': list,
'limit': limit.toString(),
'offset': offset.toString(),
'query': query
});
print(url);
var response = await http.get(url);
print(response);
if (response.statusCode == 200) {
List<dynamic> messagesJson = json.decode(response.body);
List<SerializableMessage> messages =
@ -86,6 +87,7 @@ class ApiService {
return messages;
}
print(response.statusCode);
} catch (e) {
print("caught $e");
}
@ -99,12 +101,17 @@ class ApiService {
try {
//attaches email after email from a thread
for (var id in IDs) {
var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
var url = Uri.http('0.0.0.0:3001', 'email', {'id': id});
var response = await http.get(url);
if (response.statusCode == 200) {
content += response.body;
try {
getAttachmentsInfo("INBOX", id);
} catch (innerError) {
print('_getAttachment info caught error $innerError');
}
content += "<hr>";
}
}
@ -121,7 +128,7 @@ class ApiService {
Future<List<String>> fetchFolders() async {
try {
var url = Uri.http('127.0.0.1:3001', 'folders');
var url = Uri.http('0.0.0.0:3001', 'folders');
var response = await http.get(url);
return List<String>.from(json.decode(response.body));
} catch (e) {
@ -131,7 +138,7 @@ class ApiService {
}
Future<void> createFolder(String folderName) async {
var url = Uri.http('127.0.0.1:3001', 'create_folder');
var url = Uri.http('0.0.0.0:3001', 'create_folder');
Map<String, String> requestBody = {'name': folderName};
@ -154,7 +161,7 @@ class ApiService {
}
Future<void> deleteFolder(String folderName) async {
var url = Uri.http('127.0.0.1:3001', 'delete_folder');
var url = Uri.http('0.0.0.0:3001', 'delete_folder');
Map<String, String> requestBody = {'name': folderName};
@ -175,6 +182,41 @@ class ApiService {
print('error making post req: $e');
}
}
Future<bool> logIn(String json) async {
// var url = Uri.https('')
// try{
// String response = await http.post(
// url
// );
// }
return false;
}
Future<List<AttachmentInfo>> getAttachmentsInfo(
String folder, String email_id) async {
try {
var url = Uri.http('0.0.0.0:3001', 'get_attachments_info',
{'folder': folder, 'email_id': email_id});
print(url);
var response = await http.get(url);
print("response $response");
if (response.statusCode == 200) {
var result = response.body;
List<dynamic> attachmentList = json.decode(result);
print("attachment list $attachmentList");
List<AttachmentInfo> attachments =
attachmentList.map((al) => AttachmentInfo.fromJson(al)).toList();
print("attachments $attachments");
return attachments;
}
} catch (e) {
print(e);
}
return [];
}
}
class EmailView extends StatefulWidget {

View File

@ -1,14 +1,12 @@
import 'package:crab_ui/contact.dart';
import 'package:flutter/material.dart';
import 'home_page.dart';
// import 'api_service.dart';
import 'login.dart';
import 'email.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// debugPaintSizeEnabled = true;
runApp( HyM());
runApp(HyM());
}
class HyM extends StatelessWidget {
@ -22,14 +20,12 @@ class HyM extends StatelessWidget {
theme: ThemeData.light(),
title: 'HyM',
// home: HomeScreen(),
// home: HomeScreen(),
initialRoute: "/",
routes: {
"/": (context) => SplashScreen(),
"/login": (context) => const LoginPage(),
"/home": (context) => HomeScreen(),
// "/email": (context) => EmailPage(),
"/contacts": (context) => ContactsPage(),
},
);

View File

@ -21,14 +21,14 @@ class GetThreadResponse {
factory GetThreadResponse.fromJson(Map<String, dynamic> json) {
var toList = json['to'] as List<dynamic>;
return GetThreadResponse (
return GetThreadResponse(
id: json['id'],
messages: List<String>.from(json['messages']),
subject: json['subject'],
date: DateTime.parse(json['date']),
from_name: json['from_name'],
from_address: json['from_address'],
to: toList.map((i)=> MailAddress.fromJson(i)).toList(),
to: toList.map((i) => MailAddress.fromJson(i)).toList(),
);
}
}
@ -51,6 +51,7 @@ class MailAddress {
return '${name} <${address}>';
}
}
// //old data structure
class SerializableMessage {
final String name;
@ -100,4 +101,20 @@ class SerializableMessage {
in_reply_to: json['in_reply_to'],
);
}
}
}
class AttachmentInfo {
final String name;
final int size;
final String path;
AttachmentInfo({required this.name, required this.size, required this.path});
factory AttachmentInfo.fromJson(Map<String, dynamic> json) {
return AttachmentInfo(
name: json['name'],
size: json['size'],
path: json['path'],
);
}
}

View File

@ -17,6 +17,7 @@ dependencies:
shared_preferences: ^2.0.6
encrypt: ^5.0.0
pointycastle: ^3.4.0
mime: ^1.0.3
english_words: ^4.0.0
provider: ^6.0.0