android/ios-adaption feature, markdown, and augment #6
					 1 changed files with 46 additions and 14 deletions
				
			
		| 
						 | 
					@ -49,7 +49,39 @@ class ApiService {
 | 
				
			||||||
      return [];
 | 
					      return [];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  Future<List<GetThreadResponse>> fetchEmailsFromFolderReversed(
 | 
				
			||||||
 | 
					      String folder, int pagenitaion) async {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      var url = Uri.http('$ip:$port', 'sorted_threads_by_date_current', {
 | 
				
			||||||
 | 
					        'folder': folder,
 | 
				
			||||||
 | 
					        'limit': '50',
 | 
				
			||||||
 | 
					        'offset': pagenitaion.toString(),
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      var response = await http.get(url);
 | 
				
			||||||
 | 
					      List<GetThreadResponse> allEmails = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (response.statusCode == 200) {
 | 
				
			||||||
 | 
					        List json = jsonDecode(response.body);
 | 
				
			||||||
 | 
					        for (var item in json) {
 | 
				
			||||||
 | 
					          //each item in the json is a date
 | 
				
			||||||
 | 
					          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) {
 | 
				
			||||||
 | 
					              await fetchThreads(threadId, allEmails);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        currFolder = folder;
 | 
				
			||||||
 | 
					        return allEmails;
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        throw Exception('Failed to load threads');
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } catch (e) {
 | 
				
			||||||
 | 
					      print('_displayEmailsFromFolder caught error: $e');
 | 
				
			||||||
 | 
					      return [];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  Future<void> fetchThreads(
 | 
					  Future<void> fetchThreads(
 | 
				
			||||||
      //populates allEmails, which is the List that contains all the emails in a thread
 | 
					      //populates allEmails, which is the List that contains all the emails in a thread
 | 
				
			||||||
      int threadId,
 | 
					      int threadId,
 | 
				
			||||||
| 
						 | 
					@ -180,16 +212,17 @@ class ApiService {
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SerializableMessage firstMail = mailsInSerializable[0];
 | 
					    // SerializableMessage firstMail = mailsInSerializable[0];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    Map<String, String> requestBody = {
 | 
					 | 
				
			||||||
      'from': fromFolder,
 | 
					 | 
				
			||||||
      'uid': firstMail.uid.toString(),
 | 
					 | 
				
			||||||
      'to': "Deleted Crabmail",
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      var response = await http.post(
 | 
					      for (SerializableMessage mail in mailsInSerializable) {
 | 
				
			||||||
 | 
					        Map<String, String> requestBody = {
 | 
				
			||||||
 | 
					          'from': fromFolder,
 | 
				
			||||||
 | 
					          'uid': mail.uid.toString(),
 | 
				
			||||||
 | 
					          'to': "Deleted Crabmail",
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        var response = await http.post(
 | 
				
			||||||
        url,
 | 
					        url,
 | 
				
			||||||
        headers: {
 | 
					        headers: {
 | 
				
			||||||
          'Content-Type': 'application/json',
 | 
					          'Content-Type': 'application/json',
 | 
				
			||||||
| 
						 | 
					@ -201,7 +234,7 @@ class ApiService {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        print('error ${response.statusCode} ${response.body}');
 | 
					        print('error ${response.statusCode} ${response.body}');
 | 
				
			||||||
      }
 | 
					      }}
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      print("failed trying to post move_email, with error: $e");
 | 
					      print("failed trying to post move_email, with error: $e");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -374,8 +407,8 @@ class ApiService {
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      print('_getMDContent caught error: $e');
 | 
					      print('_getMDContent caught error: $e');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    print("IDS inside fetch md content $IDsString");
 | 
					    // print("IDS inside fetch md content $IDsString");
 | 
				
			||||||
 | 
					    // print("inside apiservice $MDofThread");
 | 
				
			||||||
    return MDofThread;
 | 
					    return MDofThread;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -454,9 +487,8 @@ class ApiService {
 | 
				
			||||||
        "subject": subject ?? "Untitled",
 | 
					        "subject": subject ?? "Untitled",
 | 
				
			||||||
        "in_reply_to": "",
 | 
					        "in_reply_to": "",
 | 
				
			||||||
        "messages": [
 | 
					        "messages": [
 | 
				
			||||||
          {
 | 
					          {"message": emailContent ?? "", "is_html": false}
 | 
				
			||||||
            "message": emailContent ?? "",
 | 
					        ],
 | 
				
			||||||
            "is_html": false}],
 | 
					 | 
				
			||||||
        "attachments": [],
 | 
					        "attachments": [],
 | 
				
			||||||
        "inline_images": [],
 | 
					        "inline_images": [],
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue