finished api calls for moving an email, cleaned, and made clearer logs for errors in api calls
This commit is contained in:
parent
2677625b54
commit
9297468f6f
@ -18,9 +18,11 @@ import 'dart:js' as js;
|
||||
class ApiService {
|
||||
static String ip = "";
|
||||
static String port = "";
|
||||
static List<AttachmentResponse> threadAttachments = [];
|
||||
static List<AttachmentResponse> threadAttachments =
|
||||
[]; //holds attachments of the thread
|
||||
static String currFolder = "";
|
||||
static List<String> currThread = [];
|
||||
static List<String> currThread = []; //holds the email ids of the thread
|
||||
static String currThreadID = ""; //picked an email it prints the threadID
|
||||
|
||||
Future<List<GetThreadResponse>> fetchEmailsFromFolder(
|
||||
String folder, int pagenitaion) async {
|
||||
@ -31,7 +33,6 @@ class ApiService {
|
||||
'offset': pagenitaion.toString(),
|
||||
});
|
||||
var response = await http.get(url);
|
||||
// print(response);
|
||||
List<GetThreadResponse> allEmails = [];
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
@ -143,13 +144,52 @@ class ApiService {
|
||||
return content;
|
||||
}
|
||||
|
||||
Future<bool> moveEmail(String fromFolder, String uID, String toFolder) async {
|
||||
Future<List<SerializableMessage>> threadsInSerializable(
|
||||
String thread_id) async {
|
||||
// grab all of the emails in thread anyways, for the future it'll come in handy
|
||||
var url = Uri.http('$ip:$port', 'get_thread_messages', {'id': thread_id});
|
||||
try {
|
||||
var response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
List json = jsonDecode(response.body);
|
||||
List<SerializableMessage> serializableMessages = [];
|
||||
for (var mail in json) {
|
||||
serializableMessages.add(SerializableMessage.fromJson(mail));
|
||||
}
|
||||
return serializableMessages;
|
||||
} else {
|
||||
print(
|
||||
"failed get request with status code ${response.statusCode}, and body ${response.body}");
|
||||
}
|
||||
} catch (e) {
|
||||
print("caught in threadInSerializable method error: $e");
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
Future<bool> moveEmail(
|
||||
//only moves the first email of the thread //or perhaps should do the last
|
||||
String fromFolder,
|
||||
String thread_id,
|
||||
String toFolder) async {
|
||||
var url = Uri.http('$ip:$port', 'move_email');
|
||||
|
||||
List<SerializableMessage> mailsInSerializable =
|
||||
await this.threadsInSerializable(thread_id);
|
||||
|
||||
if (mailsInSerializable.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SerializableMessage firstMail = mailsInSerializable[0];
|
||||
|
||||
Map<String, String> requestBody = {
|
||||
'from': fromFolder,
|
||||
'uid': uID,
|
||||
'uid': firstMail.uid.toString(),
|
||||
'to': toFolder,
|
||||
};
|
||||
|
||||
try {
|
||||
var response = await http.post(
|
||||
url,
|
||||
@ -162,10 +202,10 @@ class ApiService {
|
||||
print('response body ${response.body}');
|
||||
return true;
|
||||
} else {
|
||||
print('error ');
|
||||
print('error ${response.statusCode} ${response.body}');
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
print("failed trying to post move_email, with error: $e");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -253,13 +293,6 @@ class ApiService {
|
||||
}
|
||||
|
||||
Future<bool> logIn(String json) async {
|
||||
// var url = Uri.https('')
|
||||
// try{
|
||||
// String response = await http.post(
|
||||
// url
|
||||
// );
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -298,7 +331,6 @@ class ApiService {
|
||||
var response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
var result = response.body;
|
||||
// print(result);
|
||||
Map<String, dynamic> attachmentData = json.decode(result);
|
||||
AttachmentResponse data = AttachmentResponse.fromJson(attachmentData);
|
||||
print("data $data");
|
||||
@ -449,7 +481,8 @@ class _EmailViewState extends State<EmailView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// print(currentContent);
|
||||
// print("thread id ${widget.id}");
|
||||
ApiService.currThreadID = widget.id;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.name),
|
||||
|
Loading…
Reference in New Issue
Block a user