Browse Source

show case that the bridge js -> swift is working

cyberta 3 years ago
parent
commit
36c5367cd5
1 changed files with 9 additions and 4 deletions
  1. 9 4
      deltachat-ios/Controller/WebxdcViewController.swift

+ 9 - 4
deltachat-ios/Controller/WebxdcViewController.swift

@@ -50,9 +50,12 @@ class WebxdcViewController: WebViewViewController {
 
             setUpdateListener: (cb) => (update_listener = cb),
 
-            async getAllUpdates: () => {
+            getAllUpdates: () => {
               // FIXME: we need to add an callback here, comp. https://programming.vip/docs/the-perfect-solution-for-wkwebview-to-interact-with-js.html
-              return  JSON.parse(webkit.messageHandlers.getStatusUpdatesHandler.postMessage(0));
+              webkit.messageHandlers.getStatusUpdatesHandler.postMessage("0")
+              // call to webkit.messageHandlers.getStatusUpdatesHandler.postMessage("0") doesn't return anything currently but showcases
+              // the communication js -> swift is working
+              return  Promise.resolve([]);
             },
 
             sendUpdate: (payload, descr) => {
@@ -172,11 +175,13 @@ extension WebxdcViewController: WKScriptMessageHandler {
         switch handler {
         case .getStatusUpdates:
             logger.debug("getStatusUpdates called")
-            guard let param = message.body as? Int else {
+            guard let param = message.body as? String,
+                    let statusId = Int(param) else {
                 logger.error("could not convert param \(message.body) to int")
                 return
             }
-            // let statusUpdates = dcContext.getWebxdcStatusUpdates(msgId: messageId, statusUpdateId: param)
+            let statusUpdates = dcContext.getWebxdcStatusUpdates(msgId: messageId, statusUpdateId: statusId)
+            logger.debug("status updates for message \(messageId) and statusId: \(statusId): \(statusUpdates)")
             // TODO: return
         case .sendStatusUpdate:
             logger.debug("sendStatusUpdate called")