fetch email reversed and, fixed moveEmail, so it moves every message and not just the first of the thread
This commit is contained in:
		
							parent
							
								
									de7758102b
								
							
						
					
					
						commit
						2ce8af1608
					
				
					 1 changed files with 46 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -49,7 +49,39 @@ class ApiService {
 | 
			
		|||
      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(
 | 
			
		||||
      //populates allEmails, which is the List that contains all the emails in a thread
 | 
			
		||||
      int threadId,
 | 
			
		||||
| 
						 | 
				
			
			@ -180,16 +212,17 @@ class ApiService {
 | 
			
		|||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    SerializableMessage firstMail = mailsInSerializable[0];
 | 
			
		||||
 | 
			
		||||
    Map<String, String> requestBody = {
 | 
			
		||||
      'from': fromFolder,
 | 
			
		||||
      'uid': firstMail.uid.toString(),
 | 
			
		||||
      'to': "Deleted Crabmail",
 | 
			
		||||
    };
 | 
			
		||||
    // SerializableMessage firstMail = mailsInSerializable[0];
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    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,
 | 
			
		||||
        headers: {
 | 
			
		||||
          'Content-Type': 'application/json',
 | 
			
		||||
| 
						 | 
				
			
			@ -201,7 +234,7 @@ class ApiService {
 | 
			
		|||
        return true;
 | 
			
		||||
      } else {
 | 
			
		||||
        print('error ${response.statusCode} ${response.body}');
 | 
			
		||||
      }
 | 
			
		||||
      }}
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      print("failed trying to post move_email, with error: $e");
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -374,8 +407,8 @@ class ApiService {
 | 
			
		|||
    } catch (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;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -454,9 +487,8 @@ class ApiService {
 | 
			
		|||
        "subject": subject ?? "Untitled",
 | 
			
		||||
        "in_reply_to": "",
 | 
			
		||||
        "messages": [
 | 
			
		||||
          {
 | 
			
		||||
            "message": emailContent ?? "",
 | 
			
		||||
            "is_html": false}],
 | 
			
		||||
          {"message": emailContent ?? "", "is_html": false}
 | 
			
		||||
        ],
 | 
			
		||||
        "attachments": [],
 | 
			
		||||
        "inline_images": [],
 | 
			
		||||
      };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue