diff --git a/lib/api_service.dart b/lib/api_service.dart index 9c447a9..ecc433e 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -49,6 +49,7 @@ class ApiService { return []; } } + Future> fetchEmailsFromFolderReversed( String folder, int pagenitaion) async { try { @@ -57,7 +58,7 @@ class ApiService { 'limit': '50', 'offset': pagenitaion.toString(), }); - + var response = await http.get(url); List allEmails = []; @@ -82,6 +83,7 @@ class ApiService { return []; } } + Future 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 requestBody = { @@ -223,18 +224,19 @@ class ApiService { 'to': "Deleted Crabmail", }; var response = await http.post( - url, - headers: { - 'Content-Type': 'application/json', - }, - body: jsonEncode(requestBody), - ); - if (response.statusCode == 200) { - print('response body ${response.body}'); - return true; - } else { - print('error ${response.statusCode} ${response.body}'); - }} + url, + headers: { + 'Content-Type': 'application/json', + }, + body: jsonEncode(requestBody), + ); + if (response.statusCode == 200) { + print('response body ${response.body}'); + return true; + } else { + print('error ${response.statusCode} ${response.body}'); + } + } } catch (e) { print("failed trying to post move_email, with error: $e"); } @@ -251,6 +253,17 @@ class ApiService { return []; } } + + Future> fetchContacts() async { + try { + var url = Uri.http('$ip:$port', 'get_contacts'); + var response = await http.get(url); + return List.from(json.decode(response.body)); + } catch (e) { + print('fetchFolders caught error: $e'); + return []; + } + } Future 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;