mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #3443 from deltachat/adb/issue-3439
notify DC_EVENT_INCOMING_WEBXDC_NOTIFY
This commit is contained in:
@@ -13,6 +13,7 @@ public class DcContext {
|
||||
public final static int DC_EVENT_MSGS_CHANGED = 2000;
|
||||
public final static int DC_EVENT_REACTIONS_CHANGED = 2001;
|
||||
public final static int DC_EVENT_INCOMING_REACTION = 2002;
|
||||
public final static int DC_EVENT_INCOMING_WEBXDC_NOTIFY = 2003;
|
||||
public final static int DC_EVENT_INCOMING_MSG = 2005;
|
||||
public final static int DC_EVENT_MSGS_NOTICED = 2008;
|
||||
public final static int DC_EVENT_MSG_DELIVERED = 2010;
|
||||
|
||||
@@ -74,6 +74,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
private DcMsg dcAppMsg;
|
||||
private String baseURL;
|
||||
private String sourceCodeUrl = "";
|
||||
private String selfAddr = "";
|
||||
private boolean internetAccess = false;
|
||||
private boolean hideActionBar = false;
|
||||
|
||||
@@ -198,6 +199,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
|
||||
final JSONObject info = this.dcAppMsg.getWebxdcInfo();
|
||||
internetAccess = JsonUtils.optBoolean(info, "internet_access");
|
||||
selfAddr = JsonUtils.optString(info, "self_addr");
|
||||
|
||||
toggleFakeProxy(!internetAccess);
|
||||
|
||||
@@ -471,7 +473,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
class InternalJSApi {
|
||||
@JavascriptInterface
|
||||
public String selfAddr() {
|
||||
return WebxdcActivity.this.dcContext.getConfig("addr");
|
||||
return WebxdcActivity.this.selfAddr;
|
||||
}
|
||||
|
||||
/** @noinspection unused*/
|
||||
|
||||
@@ -178,6 +178,10 @@ public class DcEventCenter {
|
||||
DcHelper.getNotificationCenter(context).notifyReaction(accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_INCOMING_WEBXDC_NOTIFY:
|
||||
DcHelper.getNotificationCenter(context).notifyWebxdc(accountId, event.getData1Int(), event.getData2Int(), event.getData2Str());
|
||||
break;
|
||||
|
||||
case DcContext.DC_EVENT_MSGS_NOTICED:
|
||||
DcHelper.getNotificationCenter(context).removeNotifications(accountId, event.getData1Int());
|
||||
break;
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.ConversationActivity;
|
||||
import org.thoughtcrime.securesms.ConversationListActivity;
|
||||
@@ -42,6 +43,7 @@ import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPrefere
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.IntentUtils;
|
||||
import org.thoughtcrime.securesms.util.JsonUtils;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
@@ -370,6 +372,27 @@ public class NotificationCenter {
|
||||
});
|
||||
}
|
||||
|
||||
public void notifyWebxdc(int accountId, int contactId, int msgId, String text) {
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
NotificationPrivacyPreference privacy = Prefs.getNotificationPrivacy(context);
|
||||
if (!privacy.isDisplayContact() || !privacy.isDisplayMessage()) {
|
||||
return; // showing "New Message" is wrong, just do nothing.
|
||||
}
|
||||
|
||||
DcContext dcContext = context.dcAccounts.getAccount(accountId);
|
||||
DcMsg dcMsg = dcContext.getMsg(msgId);
|
||||
JSONObject info;
|
||||
if(dcMsg.getType() == DcMsg.DC_MSG_WEBXDC) {
|
||||
info = dcMsg.getWebxdcInfo();
|
||||
} else { // info message, get from parent xdc
|
||||
info = dcMsg.getParent() != null? dcMsg.getParent().getWebxdcInfo() : new JSONObject();
|
||||
}
|
||||
final String name = JsonUtils.optString(info, "name");
|
||||
String shortLine = name.isEmpty()? text : (name + ": " + text);
|
||||
maybeAddNotification(accountId, dcContext.getChat(dcMsg.getChatId()), msgId, shortLine, shortLine, false);
|
||||
});
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private void maybeAddNotification(int accountId, DcChat dcChat, int msgId, String shortLine, String tickerLine, boolean playInChatSound) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user