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