Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import androidx.core.graphics.drawable.IconCompat;
import chat.delta.rpc.Rpc;
import chat.delta.rpc.RpcException;
import chat.delta.rpc.types.WebxdcMessageInfo;

import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcEvent;
Expand Down Expand Up @@ -73,6 +75,8 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
private String baseURL;
private String sourceCodeUrl = "";
private String selfAddr;
private boolean isAppSender;
private boolean isBroadcast;
private int sendUpdateMaxSize;
private int sendUpdateInterval;
private boolean internetAccess = false;
Expand Down Expand Up @@ -215,13 +219,21 @@ public boolean onShowFileChooser(
// (a random-id would also work, but would need maintenance and does not add benefits as we
// regard the file-part interceptRequest() only,
// also a random-id is not that useful for debugging)
this.baseURL = "https://acc" + dcContext.getAccountId() + "-msg" + appMessageId + ".localhost";
this.baseURL = "https://acc" + accountId + "-msg" + appMessageId + ".localhost";

final JSONObject info = this.dcAppMsg.getWebxdcInfo();
internetAccess = JsonUtils.optBoolean(info, "internet_access");
selfAddr = info.optString("self_addr");
sendUpdateMaxSize = info.optInt("send_update_max_size");
sendUpdateInterval = info.optInt("send_update_interval");
try {
WebxdcMessageInfo info = rpc.getWebxdcInfo(accountId, appMessageId);
internetAccess = info.internetAccess;
selfAddr = info.selfAddr;
isAppSender = info.isAppSender;
isBroadcast = info.isBroadcast;
sendUpdateMaxSize = info.sendUpdateMaxSize;
sendUpdateInterval = info.sendUpdateInterval;
} catch (RpcException e) { // unexpected error, log it and finish
Log.i(TAG, "RPC Error", e);
finish();
return;
}

toggleFakeProxy(!internetAccess);

Expand Down Expand Up @@ -614,6 +626,16 @@ public String selfName() {
return WebxdcActivity.this.dcContext.getName();
}

@JavascriptInterface
public boolean isAppSender() {
return WebxdcActivity.this.isAppSender;
}

@JavascriptInterface
public boolean isBroadcast() {
return WebxdcActivity.this.isBroadcast;
}

/**
* @noinspection unused
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/raw/webxdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ window.webxdc = (() => {

selfName: InternalJSApi.selfName(),

isAppSender: InternalJSApi.isAppSender(),

isBroadcast: InternalJSApi.isBroadcast(),

joinRealtimeChannel: () => {
realtimeChannel = createRealtimeChannel();
InternalJSApi.sendRealtimeAdvertisement();
Expand Down
Loading