mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #3456 from deltachat/adb/improve-notifications
notify webxdc events, replies and reactions to own messages even if chat is muted
This commit is contained in:
@@ -85,6 +85,8 @@ public class DcContext {
|
||||
public final static int DC_CONNECTIVITY_WORKING = 3000;
|
||||
public final static int DC_CONNECTIVITY_CONNECTED = 4000;
|
||||
|
||||
private static final String CONFIG_MUTE_MENTIONS_IF_MUTED = "ui.mute_mentions_if_muted";
|
||||
|
||||
// when using DcAccounts, use DcAccounts.addAccount() instead
|
||||
public DcContext(String osName, String dbfile) {
|
||||
contextCPtr = createContextCPtr(osName, dbfile);
|
||||
@@ -211,6 +213,14 @@ public class DcContext {
|
||||
public native boolean isSendingLocationsToChat(int chat_id);
|
||||
public DcProvider getProviderFromEmailWithDns (String email) { long cptr = getProviderFromEmailWithDnsCPtr(email); return cptr!=0 ? new DcProvider(cptr) : null; }
|
||||
|
||||
public boolean isMentionsEnabled() {
|
||||
return getConfigInt(CONFIG_MUTE_MENTIONS_IF_MUTED) != 1;
|
||||
}
|
||||
|
||||
public void setMentionsEnabled(boolean enabled) {
|
||||
setConfigInt(CONFIG_MUTE_MENTIONS_IF_MUTED, enabled? 0 : 1);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
String displayname = getConfig("displayname");
|
||||
if (displayname.isEmpty()) {
|
||||
|
||||
@@ -360,7 +360,10 @@ public class NotificationCenter {
|
||||
}
|
||||
}
|
||||
|
||||
maybeAddNotification(accountId, dcChat, msgId, shortLine, tickerLine, true);
|
||||
DcMsg quotedMsg = dcMsg.getQuotedMsg();
|
||||
boolean isMention = dcChat.isMultiUser() && quotedMsg != null && quotedMsg.isOutgoing();
|
||||
|
||||
maybeAddNotification(accountId, dcChat, msgId, shortLine, tickerLine, true, isMention);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -376,7 +379,8 @@ public class NotificationCenter {
|
||||
|
||||
DcContact sender = dcContext.getContact(contactId);
|
||||
String shortLine = context.getString(R.string.reaction_by_other, sender.getDisplayName(), reaction, dcMsg.getSummarytext(2000));
|
||||
maybeAddNotification(accountId, dcContext.getChat(dcMsg.getChatId()), msgId, shortLine, shortLine, false);
|
||||
DcChat dcChat = dcContext.getChat(dcMsg.getChatId());
|
||||
maybeAddNotification(accountId, dcChat, msgId, shortLine, shortLine, false, dcChat.isMultiUser());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -403,18 +407,20 @@ public class NotificationCenter {
|
||||
JSONObject info = parentMsg.getWebxdcInfo();
|
||||
final String name = JsonUtils.optString(info, "name");
|
||||
String shortLine = name.isEmpty()? text : (name + ": " + text);
|
||||
maybeAddNotification(accountId, dcContext.getChat(dcMsg.getChatId()), msgId, shortLine, shortLine, false);
|
||||
DcChat dcChat = dcContext.getChat(dcMsg.getChatId());
|
||||
maybeAddNotification(accountId, dcChat, msgId, shortLine, shortLine, false, dcChat.isMultiUser());
|
||||
});
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private void maybeAddNotification(int accountId, DcChat dcChat, int msgId, String shortLine, String tickerLine, boolean playInChatSound) {
|
||||
private void maybeAddNotification(int accountId, DcChat dcChat, int msgId, String shortLine, String tickerLine, boolean playInChatSound, boolean isMention) {
|
||||
|
||||
DcContext dcContext = context.dcAccounts.getAccount(accountId);
|
||||
int chatId = dcChat.getId();
|
||||
ChatData chatData = new ChatData(accountId, chatId);
|
||||
isMention = isMention && dcContext.isMentionsEnabled();
|
||||
|
||||
if (dcContext.isMuted() || dcChat.isMuted()) {
|
||||
if (dcContext.isMuted() || (!isMention && dcChat.isMuted())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -36,6 +36,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||
|
||||
private CheckBoxPreference ignoreBattery;
|
||||
private CheckBoxPreference notificationsEnabled;
|
||||
private CheckBoxPreference mentionNotifEnabled;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
@@ -99,6 +100,13 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||
dcContext.setMuted(!enabled);
|
||||
return true;
|
||||
});
|
||||
|
||||
mentionNotifEnabled = this.findPreference("pref_enable_mention_notifications");
|
||||
mentionNotifEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setMentionsEnabled(enabled);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,6 +122,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||
// update ignoreBattery in onResume() to reflects changes done in the system settings
|
||||
ignoreBattery.setChecked(isIgnoringBatteryOptimizations());
|
||||
notificationsEnabled.setChecked(!dcContext.isMuted());
|
||||
mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user