purged unnecessay comments out, and dead code

This commit is contained in:
Juan Marulanda De Los Rios 2024-09-21 01:48:41 -04:00
parent 254972d2af
commit f867312af3
2 changed files with 56 additions and 126 deletions

View File

@ -28,56 +28,7 @@ class MailAddress {
}
}
// //data structure
// class SerializableMessage {
// final String name;
// final String from;
// final List<MailAddress> to;
// final List<MailAddress> 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<String, dynamic> 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<EmailPage> {
List emails = [];
void _displayEmailsFromFolder(String folder) async {
// Map<String, List<SerializableMessage>> messagesMap = {};
List<GetThreadResponse> allEmails = []; //all the emails
try {
@ -106,11 +56,8 @@ class _EmailPageState extends State<EmailPage> {
if (item.length > 1 && item[0] is String && item[1] is List) {
List<int> threadIDs = List<int>.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<EmailPage> {
setState(() {
emails = allEmails;
});
// print(emails[0]);
// Print allEmails to debug its structure
// print("allEmails: ${allEmails[0].messages}");
// Convert allEmails to a list
}
// }
Future<void> fetchThreads(
//complete
int threadId,
List<GetThreadResponse> 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<String, dynamic> messagesJson = jsonDecode(response.body);
// print(messagesJson);
// List<String> messagesofThread = messagesJson['messages'];
// messagesJson.map((mj) => GetThreadResponse.fromJson(mj)).toList();
// List<GetThreadResponse> messages = messagesJson.values.map((mj) {
// return GetThreadResponse.fromJson(mj as Map<String, dynamic>);
// }).toList();
// List<GetThreadResponse> 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<EmailPage> {
}
}
// Future<void> fetchThreadMessages(
// int threadId, List<SerializableMessage> 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<dynamic> messagesJson = jsonDecode(response.body);
// List<SerializableMessage> 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<String> _getEmailContent(List<String> IDs) async {
String content = r"""
""";
@ -205,7 +113,6 @@ class _EmailPageState extends State<EmailPage> {
} 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<EmailView> {
AugmentClasses.handleJump(spanId);
}
// void _invisibility(String )
// TODO: void _invisibility(String )
@override
Widget build(BuildContext context) {

View File

@ -45,3 +45,55 @@ class GetThreadResponse {
);
}
}
// //old data structure
// class SerializableMessage {
// final String name;
// final String from;
// final List<MailAddress> to;
// final List<MailAddress> 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<String, dynamic> 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'],
// );
// }
// }