Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "realtime is disabled" dialog #3405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 36 additions & 6 deletions src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.thoughtcrime.securesms;

import static org.thoughtcrime.securesms.connect.DcHelper.CONFIG_WEBXDC_REALTIME_ENABLED;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -28,6 +30,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.TaskStackBuilder;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
Expand Down Expand Up @@ -72,6 +75,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
private String sourceCodeUrl = "";
private boolean internetAccess = false;
private boolean hideActionBar = false;
private boolean realtimeWarned = false;

public static void openMaps(Context context, int chatId) {
DcContext dcContext = DcHelper.getContext(context);
Expand Down Expand Up @@ -526,15 +530,41 @@ public String sendToChat(String message) {
}
}

/** @noinspection unused*/
@JavascriptInterface
public boolean isRealtimeSupported() {
return WebxdcActivity.this.dcContext.getConfigInt(CONFIG_WEBXDC_REALTIME_ENABLED) != 0;
}

/** @noinspection unused*/
@JavascriptInterface
public void sendRealtimeAdvertisement() {
int accountId = WebxdcActivity.this.dcContext.getAccountId();
int msgId = WebxdcActivity.this.dcAppMsg.getId();
try {
WebxdcActivity.this.rpc.sendWebxdcRealtimeAdvertisement(accountId, msgId);
} catch (RpcException e) {
e.printStackTrace();
final WebxdcActivity activity = WebxdcActivity.this;
final DcContext dcContext = activity.dcContext;
final int accountId = activity.dcContext.getAccountId();
final int msgId = activity.dcAppMsg.getId();
if (dcContext.getConfigInt(CONFIG_WEBXDC_REALTIME_ENABLED) != 0) {
try {
activity.rpc.sendWebxdcRealtimeAdvertisement(accountId, msgId);
} catch (RpcException e) {
e.printStackTrace();
}
} else if (!activity.realtimeWarned) {
activity.realtimeWarned = true;
Util.runOnMain(() -> {
new AlertDialog.Builder(activity)
.setMessage(R.string.realtime_disabled_warning)
.setPositiveButton(R.string.enable, (d, b) -> {
dcContext.setConfigInt(CONFIG_WEBXDC_REALTIME_ENABLED, 1);
try {
activity.rpc.sendWebxdcRealtimeAdvertisement(accountId, msgId);
} catch (RpcException e) {
e.printStackTrace();
}
})
.setNegativeButton(R.string.cancel, null)
.show();
});
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/res/raw/webxdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ window.webxdc = (() => {

selfName: InternalJSApi.selfName(),

isRealtimeSupported: InternalJSApi.isRealtimeSupported,

joinRealtimeChannel: () => {
realtimeChannel = createRealtimeChannel();
InternalJSApi.sendRealtimeAdvertisement();
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<string name="app_name">Delta Chat</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="enable">Enable</string>
<!-- deprecated, the word "or" to separate blocks in the user interface that are mutually exclusive -->
<string name="or_separator">or</string>
<string name="clear_search">Clear Search</string>
Expand Down Expand Up @@ -448,6 +449,7 @@
<string name="send_message_to">Send Message to…</string>
<string name="enable_realtime">Real-Time Apps</string>
<string name="enable_realtime_explain">Enable real-time connections for apps shared in chats. If enabled, chat partners may be able to discover your IP address when you start an app.</string>
<string name="realtime_disabled_warning">\"Real-Time Apps\" feature is disabled, this app may not work properly. Do you want to enable it? Chat partners may be able to discover your IP address.</string>

<!-- map -->
<string name="filter_map_on_time">Show locations in time frame</string>
Expand Down
Loading