adapt js to new webxdc-update-api (#2223)

* adapt js to new webxdc-update-api

* the stub implementation of getAllUpdates() must still return a Promise

* reword parameters of getStatusUpdates()
This commit is contained in:
bjoern
2022-03-04 20:23:56 +01:00
committed by GitHub
parent 92e1719d53
commit adf02b50e5
4 changed files with 19 additions and 13 deletions
+2 -2
View File
@@ -749,9 +749,9 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_sendWebxdcStatusUpdate(JNIE
}
JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getWebxdcStatusUpdates(JNIEnv *env, jobject obj, jint msg_id, jint status_update_id)
JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getWebxdcStatusUpdates(JNIEnv *env, jobject obj, jint msg_id, jint last_known_serial)
{
char* temp = dc_get_webxdc_status_updates(get_dc_context(env, obj), msg_id, status_update_id);
char* temp = dc_get_webxdc_status_updates(get_dc_context(env, obj), msg_id, last_known_serial);
jstring ret = JSTRING_NEW(temp);
dc_str_unref(temp);
return ret;
+13 -7
View File
@@ -1,11 +1,13 @@
window.webxdc = (() => {
var update_listener = () => {};
var last_serial = 0;
window.__webxdcUpdate = (updateId) => {
var updates = JSON.parse(InternalJSApi.getStatusUpdates(updateId));
if (updates.length === 1) {
update_listener(updates[0]);
}
window.__webxdcUpdate = () => {
var updates = JSON.parse(InternalJSApi.getStatusUpdates(last_serial));
updates.forEach((update) => {
update_listener(update);
last_serial = update.serial;
});
};
return {
@@ -13,10 +15,14 @@ window.webxdc = (() => {
selfName: InternalJSApi.selfName(),
setUpdateListener: (cb) => (update_listener = cb),
setUpdateListener: (cb, serial) => {
last_serial = typeof serial === "undefined" ? 0 : parseInt(serial);
window.__webxdcUpdate();
},
// deprecated 2022-02-20 all updates are returned through the callback set by setUpdateListener
getAllUpdates: () => {
return Promise.resolve(JSON.parse(InternalJSApi.getStatusUpdates(0)));
return Promise.resolve([]);
},
sendUpdate: (payload, descr) => {
+1 -1
View File
@@ -199,7 +199,7 @@ public class DcContext {
public native int sendTextMsg (int chat_id, String text);
public native int sendVideochatInvitation(int chat_id);
public native boolean sendWebxdcStatusUpdate(int msg_id, String payload, String descr);
public native String getWebxdcStatusUpdates(int msg_id, int status_update_id);
public native String getWebxdcStatusUpdates(int msg_id, int last_known_serial);
public native int addDeviceMsg (String label, DcMsg msg);
public native boolean wasDeviceMsgEverAdded(String label);
public DcLot checkQr (String qr) { return new DcLot(checkQrCPtr(qr)); }
@@ -147,7 +147,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
int eventId = event.getId();
if ((eventId == DcContext.DC_EVENT_WEBXDC_STATUS_UPDATE && event.getData1Int() == dcAppMsg.getId())) {
Log.i(TAG, "handleEvent");
webView.loadUrl("javascript:window.__webxdcUpdate(" + event.getData2Int() + ");");
webView.loadUrl("javascript:window.__webxdcUpdate();");
}
}
@@ -182,9 +182,9 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
}
@JavascriptInterface
public String getStatusUpdates(int statusUpdateId) {
public String getStatusUpdates(int lastKnownSerial) {
Log.i(TAG, "getStatusUpdates");
return WebxdcActivity.this.dcContext.getWebxdcStatusUpdates(WebxdcActivity.this.dcAppMsg.getId(), statusUpdateId);
return WebxdcActivity.this.dcContext.getWebxdcStatusUpdates(WebxdcActivity.this.dcAppMsg.getId(), lastKnownSerial );
}
}
}