WIP: android/ios-adaption feature, markdown, and augment #6
@ -1,16 +1,13 @@
|
||||
// this file should handle most of the API calls
|
||||
// it also builds some widgets, but it will be modulated later
|
||||
// it also builds some widgets, but it will be modulated later // chat it did
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
|
||||
|
||||
import 'structs.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
|
||||
class ApiService {
|
||||
static String ip = "";
|
||||
static String port = "";
|
||||
@ -141,7 +138,6 @@ class ApiService {
|
||||
} catch (e) {
|
||||
print('_getEmailContent caught error: $e');
|
||||
}
|
||||
// return content;
|
||||
return HTMLofThread;
|
||||
}
|
||||
|
||||
@ -344,75 +340,41 @@ class ApiService {
|
||||
return AttachmentResponse(name: "error", data: Uint8List(0));
|
||||
}
|
||||
|
||||
//TODO: MOVE THIS INTO WEB
|
||||
// Future<List<Map<String, dynamic>>> getMarkerPosition() async {
|
||||
// //this is so we can put a widget right below each email, but the way how the email content is generated
|
||||
// //leads to problems as for a) the html is added one right after the other in one iframe, b)
|
||||
// // if it was multiple iframes then the scrolling to jump would not work as expected
|
||||
Future<List<String>> fetchMarkdownContent(
|
||||
List<String> IDsString, String emailFolder) async {
|
||||
List<String> MDofThread = [];
|
||||
threadAttachments = [];
|
||||
int counter = 0;
|
||||
|
||||
// print("marker called");
|
||||
// // JavaScript code embedded as a string
|
||||
// String jsCode = '''
|
||||
// (async function waitForIframeAndMarkers() {
|
||||
// try {
|
||||
// return await new Promise((resolve) => {
|
||||
// const interval = setInterval(() => {
|
||||
// console.log("⏳ Checking for iframe...");
|
||||
// var iframe = document.getElementsByTagName('iframe')[0];
|
||||
// if (iframe && iframe.contentDocument) {
|
||||
// console.log("✅ Iframe found!");
|
||||
// var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
|
||||
// var markers = iframeDoc.querySelectorAll('[id^="JuanBedarramarker"]');
|
||||
// if (markers.length > 0) {
|
||||
// console.log(`✅ Found markers in the iframe.`);
|
||||
// var positions = [];
|
||||
// markers.forEach((marker) => {
|
||||
// var rect = marker.getBoundingClientRect();
|
||||
// positions.push({
|
||||
// id: marker.id,
|
||||
// x: rect.left + window.scrollX,
|
||||
// y: rect.top + window.scrollY,
|
||||
// });
|
||||
// });
|
||||
// console.log("📌 Marker positions:", positions);
|
||||
// clearInterval(interval);
|
||||
// resolve(JSON.stringify(positions)); // Ensure proper JSON string
|
||||
// } else {
|
||||
// console.log("❌ No markers found yet.");
|
||||
// }
|
||||
// } else {
|
||||
// console.log("❌ Iframe not found or not loaded yet.");
|
||||
// }
|
||||
// }, 200);
|
||||
// });
|
||||
// } catch (error) {
|
||||
// console.error("JS Error:", error);
|
||||
// throw error; // Propagate error to Dart
|
||||
// }
|
||||
// })();
|
||||
// ''';
|
||||
|
||||
// try {
|
||||
// // Execute the JavaScript code using eval
|
||||
// // final result = await js.context.callMethod('eval', [jsCode]);
|
||||
|
||||
// if (result != null && result is String) {
|
||||
// print("Result received: $result");
|
||||
|
||||
// // Parse the JSON string returned by JavaScript into a Dart list of maps
|
||||
// final List<dynamic> parsedResult = jsonDecode(result);
|
||||
// var positions = List<Map<String, dynamic>>.from(parsedResult);
|
||||
// print("positions put on");
|
||||
// print(positions);
|
||||
// return positions;
|
||||
// } else {
|
||||
// print("result is null or not a string");
|
||||
// }
|
||||
// } catch (e, stackTrace) {
|
||||
// print("Error executing JavaScript: $e");
|
||||
// print(stackTrace);
|
||||
// }
|
||||
|
||||
// return [];
|
||||
// }
|
||||
}
|
||||
try {
|
||||
//attaches email after email from a thread
|
||||
for (var id in IDsString) {
|
||||
var url = Uri.http('$ip:$port', 'email_md', {'id': id});
|
||||
print(url);
|
||||
var response = await http.get(url);
|
||||
currThread.add(id);
|
||||
if (response.statusCode == 200) {
|
||||
counter += 1;
|
||||
Map<String, dynamic> json = jsonDecode(response.body);
|
||||
|
||||
MDofThread.add(json['md'] ?? '');
|
||||
try {
|
||||
List<AttachmentInfo> attachments =
|
||||
await getAttachmentsInfo(emailFolder, id);
|
||||
for (var attachment in attachments) {
|
||||
//TODO: for each attachment creaate at the bottom a widget for each individual one
|
||||
threadAttachments
|
||||
.add(await getAttachment(emailFolder, id, attachment.name));
|
||||
}
|
||||
} catch (innerError) {
|
||||
print('_getAttachment info caught error $innerError');
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('_getMDContent caught error: $e');
|
||||
}
|
||||
|
||||
return MDofThread;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user