diff --git a/lib/api_service.dart b/lib/api_service.dart index 1eaca5c..4b1a011 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -28,56 +28,7 @@ class MailAddress { } } -// //data structure -// class SerializableMessage { -// final String name; -// final String from; -// final List to; -// final List cc; -// final String hash; -// final String subject; -// final String date; -// final int uid; -// final String list; -// final String id; -// final String in_reply_to; - -// SerializableMessage({ -// required this.name, -// required this.from, -// required this.to, -// required this.cc, -// required this.hash, -// required this.subject, -// required this.date, -// required this.uid, -// required this.list, -// required this.id, -// required this.in_reply_to, -// }); - -// factory SerializableMessage.fromJson(Map json) { -// var toList = json['to'] as List; -// var ccList = json['cc'] as List; - -// return SerializableMessage( -// name: json['name'], -// from: json['from'], -// // to: json['name', 'address'] -// to: toList.map((i) => MailAddress.fromJson(i)).toList(), -// cc: ccList.map((i) => MailAddress.fromJson(i)).toList(), -// // path: json['path'], -// hash: json['hash'], -// subject: json['subject'], -// date: json['date'], -// uid: json['uid'], -// list: json['list'], -// id: json['id'], -// in_reply_to: json['in_reply_to'], -// ); -// } -// } class EmailPage extends StatefulWidget { const EmailPage({super.key}); @@ -91,7 +42,6 @@ class _EmailPageState extends State { List emails = []; void _displayEmailsFromFolder(String folder) async { - // Map> messagesMap = {}; List allEmails = []; //all the emails try { @@ -106,11 +56,8 @@ class _EmailPageState extends State { if (item.length > 1 && item[0] is String && item[1] is List) { List threadIDs = List.from(item[1]); for (var threadId in threadIDs) { - // print(threadId); - // await fetchThreadMessages(threadId, allEmails); await fetchThreads(threadId, allEmails); } - //TODO: get exact thread with new api endpoint from chosen thread? } } } else { @@ -124,39 +71,22 @@ class _EmailPageState extends State { setState(() { emails = allEmails; }); - // print(emails[0]); - // Print allEmails to debug its structure - // print("allEmails: ${allEmails[0].messages}"); - - // Convert allEmails to a list } -// } Future fetchThreads( - //complete int threadId, List allEmails) async { try { var url = Uri.http('127.0.0.1:3001', 'get_thread', {'id': threadId.toString()}); var response = await http.get(url); - // print(response.body); + if (response.statusCode == 200) { Map messagesJson = jsonDecode(response.body); - // print(messagesJson); - // List messagesofThread = messagesJson['messages']; - // messagesJson.map((mj) => GetThreadResponse.fromJson(mj)).toList(); - // List messages = messagesJson.values.map((mj) { - // return GetThreadResponse.fromJson(mj as Map); - // }).toList(); - // List thread = - // messagesJson.map((mj) => GetThreadResponse.fromJson(mj)).toList(); - GetThreadResponse threadResponse = + GetThreadResponse threadResponse = GetThreadResponse.fromJson(messagesJson); - allEmails.add( - threadResponse); //adds all the messages of the thread into all emails - //perhaps should change + allEmails.add(threadResponse); } else { throw Exception( 'Failed to fetch thread messages for thread ID: $threadId'); @@ -166,28 +96,6 @@ class _EmailPageState extends State { } } - // Future fetchThreadMessages( - // int threadId, List allEmails) async { - // try { - // var url = Uri.http( - // '127.0.0.1:3001', 'get_thread_messages', {'id': threadId.toString()}); - - // var response = await http.get(url); - - // if (response.statusCode == 200) { - // List messagesJson = jsonDecode(response.body); - // List messages = - // messagesJson.map((mj) => SerializableMessage.fromJson(mj)).toList(); - // allEmails.addAll(messages); - // } else { - // throw Exception( - // 'Failed to fetch thread messages for thread ID: $threadId'); - // } - // } catch (e) { - // print('Error fetching thread messages: $e'); - // } - // } - Future _getEmailContent(List IDs) async { String content = r""" """; @@ -205,7 +113,6 @@ class _EmailPageState extends State { } catch (e) { print('_getEmailContent caught error: $e'); } - print(content); return content; } @@ -312,18 +219,12 @@ class EmailListScreen extends StatelessWidget { onTap: () async { String emailContent = await getEmailContent(emails[index].messages); - String messages = emails[index].messages.toString(); String fromName = emails[index].from_name.toString(); String fromAddress = emails[index].from_address.toString(); String to = emails[index].to.toString(); - // String cc = emails[index].cc.toString(); - // String hash = emails[index].hash.toString(); String subject = emails[index].subject.toString(); String date = emails[index].date.toString(); - // String uid = emails[index].uid.toString(); - // String list = emails[index].list.toString(); String id = emails[index].id.toString(); - // String in_reply_to = emails[index].in_reply_to.toString(); Navigator.push( context, @@ -333,16 +234,10 @@ class EmailListScreen extends StatelessWidget { from: fromAddress, name: fromName, to: to, - // cc: cc, - // hash: hash, subject: subject, date: date, - // uid: uid, - // list: list, id: id, - // in_reply_to: in_reply_to, ) - //nada hpta ), ); }); @@ -357,39 +252,22 @@ class EmailListScreen extends StatelessWidget { class EmailView extends StatefulWidget { final String emailContent; - // final String jsonEmail; final String from; final String name; - final String to; - - // final String to; - // final String cc; - // final String hash; final String subject; final String date; - // final String uid; - // final String list; final String id; - // final String in_reply_to; const EmailView({ Key? key, required this.emailContent, - // required this.jsonEmail, required this.from, required this.name, required this.to, - - // required this.to, - // required this.cc, - // required this.hash, required this.subject, required this.date, - // required this.uid, - // required this.list, required this.id, - // required this.in_reply_to }) : super(key: key); @override _EmailViewState createState() => _EmailViewState(); @@ -426,7 +304,7 @@ class _EmailViewState extends State { AugmentClasses.handleJump(spanId); } - // void _invisibility(String ) + // TODO: void _invisibility(String ) @override Widget build(BuildContext context) { diff --git a/lib/structs.dart b/lib/structs.dart index 09b42ef..b428c3c 100644 --- a/lib/structs.dart +++ b/lib/structs.dart @@ -45,3 +45,55 @@ class GetThreadResponse { ); } } + + +// //old data structure +// class SerializableMessage { +// final String name; +// final String from; +// final List to; +// final List cc; +// final String hash; + +// final String subject; +// final String date; +// final int uid; +// final String list; +// final String id; +// final String in_reply_to; + +// SerializableMessage({ +// required this.name, +// required this.from, +// required this.to, +// required this.cc, +// required this.hash, +// required this.subject, +// required this.date, +// required this.uid, +// required this.list, +// required this.id, +// required this.in_reply_to, +// }); + +// factory SerializableMessage.fromJson(Map json) { +// var toList = json['to'] as List; +// var ccList = json['cc'] as List; + +// return SerializableMessage( +// name: json['name'], +// from: json['from'], +// // to: json['name', 'address'] +// to: toList.map((i) => MailAddress.fromJson(i)).toList(), +// cc: ccList.map((i) => MailAddress.fromJson(i)).toList(), +// // path: json['path'], +// hash: json['hash'], +// subject: json['subject'], +// date: json['date'], +// uid: json['uid'], +// list: json['list'], +// id: json['id'], +// in_reply_to: json['in_reply_to'], +// ); +// } +// } \ No newline at end of file