mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #1356 from deltachat/fix-mute-multiaccount
Use the mute functions of the core
This commit is contained in:
+11
-2
@@ -1184,6 +1184,16 @@ JNIEXPORT jintArray Java_com_b44t_messenger_DcContext_getChatContacts(JNIEnv *en
|
||||
return dc_array2jintArray_n_unref(env, ca);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_setChatMuteDuration(JNIEnv *env, jobject obj, jint chat_id, jlong duration)
|
||||
{
|
||||
return dc_set_chat_mute_duration(get_dc_context(env, obj), chat_id, duration);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean Java_com_b44t_messenger_DcChat_isMuted(JNIEnv *env, jobject obj)
|
||||
{
|
||||
return dc_chat_is_muted(get_dc_chat(env, obj));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* DcMsg
|
||||
@@ -1668,5 +1678,4 @@ JNIEXPORT jstring Java_com_b44t_messenger_DcContext_dataToString(JNIEnv *env, jc
|
||||
}
|
||||
const char* cstring = (const char*)data;
|
||||
return JSTRING_NEW(cstring);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public class DcChat {
|
||||
public native boolean canSend ();
|
||||
public native boolean isVerified ();
|
||||
public native boolean isSendingLocations();
|
||||
public native boolean isMuted ();
|
||||
|
||||
// working with raw c-data
|
||||
private long chatCPtr; // CAVE: the name is referenced in the JNI
|
||||
|
||||
@@ -161,6 +161,7 @@ public class DcContext {
|
||||
public native int[] getChatMedia (int chat_id, int type1, int type2, int type3);
|
||||
public native int getNextMedia (int msg_id, int dir, int type1, int type2, int type3);
|
||||
public native int[] getChatContacts (int chat_id);
|
||||
public native boolean setChatMuteDuration (int chat_id, long duration);
|
||||
public native void deleteChat (int chat_id);
|
||||
public @NonNull DcMsg getMsg (int msg_id) { return new DcMsg(getMsgCPtr(msg_id)); }
|
||||
public native String getMsgInfo (int id);
|
||||
|
||||
@@ -433,7 +433,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
inflater.inflate(R.menu.conversation, menu);
|
||||
|
||||
if(Prefs.isChatMuted(this, chatId)) {
|
||||
if(Prefs.isChatMuted(dcChat)) {
|
||||
menu.findItem(R.id.menu_mute_notifications).setTitle(R.string.menu_unmute);
|
||||
}
|
||||
|
||||
@@ -561,14 +561,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void handleMuteNotifications() {
|
||||
if(!Prefs.isChatMuted(this, chatId)) {
|
||||
MuteDialog.show(this, until -> {
|
||||
Prefs.setChatMutedUntil(this, chatId, until);
|
||||
if(!Prefs.isChatMuted(dcChat)) {
|
||||
MuteDialog.show(this, duration -> {
|
||||
Prefs.setChatMuteDuration(dcContext, chatId, duration);
|
||||
titleView.setTitle(glideRequests, dcChat);
|
||||
});
|
||||
} else {
|
||||
// unmute
|
||||
Prefs.setChatMutedUntil(this, chatId, 0);
|
||||
Prefs.setChatMuteDuration(dcContext, chatId, 0);
|
||||
titleView.setTitle(glideRequests, dcChat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
|
||||
private DcLot dcSummary;
|
||||
private Set<Long> selectedThreads;
|
||||
private long chatId;
|
||||
private int chatId;
|
||||
private int msgId;
|
||||
private GlideRequests glideRequests;
|
||||
private TextView subjectView;
|
||||
@@ -130,7 +130,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
this.dcSummary = dcSummary;
|
||||
this.selectedThreads = selectedThreads;
|
||||
Recipient recipient = thread.getRecipient();
|
||||
this.chatId = thread.getThreadId();
|
||||
this.chatId = (int) thread.getThreadId();
|
||||
this.msgId = msgId;
|
||||
this.glideRequests = glideRequests;
|
||||
this.unreadCount = thread.getUnreadCount();
|
||||
@@ -173,7 +173,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
}
|
||||
|
||||
fromView.setCompoundDrawablesWithIntrinsicBounds(
|
||||
Prefs.isChatMuted(getContext(), (int) chatId)? R.drawable.ic_volume_off_grey600_18dp : 0,
|
||||
thread.isMuted()? R.drawable.ic_volume_off_grey600_18dp : 0,
|
||||
0,
|
||||
thread.isVerified()? R.drawable.ic_verified : 0,
|
||||
0);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
setComposeTitle();
|
||||
} else {
|
||||
setRecipientTitle(dcChat, showSubtitle);
|
||||
if (Prefs.isChatMuted(getContext(), dcChat.getId())) {
|
||||
if (Prefs.isChatMuted(dcChat)) {
|
||||
imgLeft = R.drawable.ic_volume_off_white_18dp;
|
||||
}
|
||||
if (dcChat.isVerified()) {
|
||||
|
||||
@@ -15,24 +15,24 @@ public class MuteDialog {
|
||||
builder.setItems(R.array.mute_durations, (dialog, which) -> {
|
||||
final long muteUntil;
|
||||
|
||||
// See https://c.delta.chat/classdc__context__t.html#a6460395925d49d2053bc95224bf5ce37.
|
||||
switch (which) {
|
||||
case 0: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break;
|
||||
case 1: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(2); break;
|
||||
case 2: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1); break;
|
||||
case 3: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(7); break;
|
||||
case 4: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(36500); break;
|
||||
default: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break;
|
||||
case 0: muteUntil = TimeUnit.HOURS.toSeconds(1); break;
|
||||
case 1: muteUntil = TimeUnit.HOURS.toSeconds(2); break;
|
||||
case 2: muteUntil = TimeUnit.DAYS.toSeconds(1); break;
|
||||
case 3: muteUntil = TimeUnit.DAYS.toSeconds(7); break;
|
||||
case 4: muteUntil = -1; break; // mute forever
|
||||
default: muteUntil = 0; break;
|
||||
}
|
||||
|
||||
listener.onMuted(muteUntil);
|
||||
});
|
||||
|
||||
builder.show();
|
||||
|
||||
}
|
||||
|
||||
public interface MuteSelectionListener {
|
||||
void onMuted(long until);
|
||||
void onMuted(long duration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
item = menu.findItem(R.id.menu_mute_notifications);
|
||||
if(item!=null) {
|
||||
item.setTitle(Prefs.isChatMuted(this, chatId)? R.string.menu_unmute : R.string.menu_mute);
|
||||
item.setTitle(Prefs.isChatMuted(dcContext.getChat(chatId))? R.string.menu_unmute : R.string.menu_mute);
|
||||
}
|
||||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
@@ -351,22 +351,17 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
public void onNotifyOnOff() {
|
||||
if (Prefs.isChatMuted(this, chatId)) {
|
||||
if (Prefs.isChatMuted(dcContext.getChat(chatId))) {
|
||||
setMuted(0);
|
||||
}
|
||||
else {
|
||||
MuteDialog.show(this, until -> setMuted(until));
|
||||
MuteDialog.show(this, duration -> setMuted(duration));
|
||||
}
|
||||
}
|
||||
|
||||
private void setMuted(final long until) {
|
||||
if(chatId!=0) {
|
||||
Prefs.setChatMutedUntil(this, chatId, until);
|
||||
|
||||
// normally, sendToObservers() is only used to forward events from the core to the ui.
|
||||
// we do an exception here, as "mute" is not handled by the core,
|
||||
// but various elements listen to similar changes with the DC_EVENT_CHAT_MODIFIED event.
|
||||
dcContext.eventCenter.sendToObservers(DcContext.DC_EVENT_CHAT_MODIFIED, new Integer(chatId), 0);
|
||||
private void setMuted(final long duration) {
|
||||
if (chatId != 0) {
|
||||
Prefs.setChatMuteDuration(dcContext, chatId, duration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.util.AttributeSet;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.ResUtil;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
@@ -71,15 +72,6 @@ public class FromTextView extends EmojiTextView {
|
||||
}
|
||||
|
||||
setText(builder);
|
||||
|
||||
int chatId = recipient.getAddress().isDcChat()? recipient.getAddress().getDcChatId() : 0;
|
||||
|
||||
if (Prefs.isChatMuted(getContext(), chatId)) {
|
||||
setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_grey600_18dp, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ public class ApplicationDcContext extends DcContext {
|
||||
|
||||
return new ThreadRecord(context, body, recipient, date,
|
||||
unreadCount, chatId,
|
||||
chat.getVisibility(), verified, chat.isSendingLocations(), summary);
|
||||
chat.getVisibility(), verified, chat.isSendingLocations(), chat.isMuted(), summary);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ public class ThreadRecord {
|
||||
private final int visibility;
|
||||
private final boolean verified;
|
||||
private final boolean isSendingLocations;
|
||||
private final boolean isMuted;
|
||||
private @Nullable final DcLot dcSummary;
|
||||
|
||||
public ThreadRecord(@NonNull Context context, @NonNull String body,
|
||||
@@ -56,6 +57,7 @@ public class ThreadRecord {
|
||||
int visibility,
|
||||
boolean verified,
|
||||
boolean isSendingLocations,
|
||||
boolean isMuted,
|
||||
@Nullable DcLot dcSummary)
|
||||
{
|
||||
this.context = context.getApplicationContext();
|
||||
@@ -67,6 +69,7 @@ public class ThreadRecord {
|
||||
this.visibility = visibility;
|
||||
this.verified = verified;
|
||||
this.isSendingLocations = isSendingLocations;
|
||||
this.isMuted = isMuted;
|
||||
this.dcSummary = dcSummary;
|
||||
}
|
||||
|
||||
@@ -121,4 +124,8 @@ public class ThreadRecord {
|
||||
public boolean isSendingLocations() {
|
||||
return isSendingLocations;
|
||||
}
|
||||
|
||||
public boolean isMuted() {
|
||||
return isMuted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import androidx.core.app.NotificationManagerCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@@ -86,23 +88,27 @@ abstract class MessageNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateNotification(int chatId, int messageId) {
|
||||
boolean isVisible = visibleChatId == chatId;
|
||||
void updateNotification(int chatId, int messageId) {
|
||||
updateNotification(DcHelper.getContext(appContext).getChat(chatId), messageId);
|
||||
}
|
||||
|
||||
private void updateNotification(DcChat chat, int messageId) {
|
||||
boolean isVisible = visibleChatId == chat.getId();
|
||||
|
||||
if (!Prefs.isNotificationsEnabled(appContext) ||
|
||||
Prefs.isChatMuted(appContext, chatId))
|
||||
Prefs.isChatMuted(chat))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isVisible) {
|
||||
sendInChatNotification(chatId);
|
||||
sendInChatNotification(chat);
|
||||
} else if (visibleChatId != NO_VISIBLE_CHAT_ID) {
|
||||
//different chat is on top
|
||||
sendNotifications(chatId, messageId, false);
|
||||
sendNotifications(chat, messageId, false);
|
||||
} else {
|
||||
//app is in background or different Activity is on top
|
||||
sendNotifications(chatId, messageId, true);
|
||||
sendNotifications(chat, messageId, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +126,7 @@ abstract class MessageNotifier {
|
||||
int[] freshMessages = dcContext.getFreshMsgs();
|
||||
for (int message : freshMessages) {
|
||||
DcMsg record = dcContext.getMsg(message);
|
||||
updateNotification(record.getChatId(), record.getId());
|
||||
updateNotification(dcContext.getChat(record.getChatId()), record.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,20 +178,20 @@ abstract class MessageNotifier {
|
||||
notifications.cancel(SUMMARY_NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
void sendNotifications(int chatId, int messageId, boolean signal) {
|
||||
void sendNotifications(DcChat chat, int messageId, boolean signal) {
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(appContext);
|
||||
if (signal = isSignalAllowed(signal)) {
|
||||
lastAudibleNotification = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
if (dcContext.getChat(chatId).isDeviceTalk()) {
|
||||
if (chat.isDeviceTalk()) {
|
||||
// currently, we just never notify on device chat.
|
||||
// esp. on first start, this is annoying.
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
addMessageToNotificationState(dcContext, chatId, messageId);
|
||||
addMessageToNotificationState(dcContext, chat, messageId);
|
||||
if (notificationState.hasMultipleChats()) {
|
||||
for (int id : notificationState.getChats()) {
|
||||
sendSingleChatNotification(appContext, new NotificationState(notificationState.getNotificationsForChat(id)), false, true);
|
||||
@@ -345,14 +351,14 @@ abstract class MessageNotifier {
|
||||
NotificationManagerCompat.from(context).notify(notificationId, notificationBuilder.build());
|
||||
}
|
||||
|
||||
private void sendInChatNotification(int chatId) {
|
||||
private void sendInChatNotification(DcChat chat) {
|
||||
if (!Prefs.isInChatNotifications(appContext) ||
|
||||
audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(Prefs.isChatMuted(appContext, chatId)) {
|
||||
if(Prefs.isChatMuted(chat)) {
|
||||
Log.d(TAG, "chat muted");
|
||||
return;
|
||||
}
|
||||
@@ -362,8 +368,8 @@ abstract class MessageNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void addMessageToNotificationState(ApplicationDcContext dcContext, int chatId, int msgId) {
|
||||
if (Prefs.isChatMuted(appContext, chatId)) {
|
||||
void addMessageToNotificationState(ApplicationDcContext dcContext, DcChat chat, int msgId) {
|
||||
if (Prefs.isChatMuted(chat)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -399,7 +405,7 @@ abstract class MessageNotifier {
|
||||
}
|
||||
|
||||
synchronized (lock) {
|
||||
notificationState.addNotification(new NotificationItem(id, chatRecipient, individualRecipient, chatId, body, timestamp, slideDeck));
|
||||
notificationState.addNotification(new NotificationItem(id, chatRecipient, individualRecipient, chat.getId(), body, timestamp, slideDeck));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.notifications;
|
||||
import android.content.Context;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
|
||||
@@ -40,19 +42,19 @@ class MessageNotifierPreApi23 extends MessageNotifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
void sendNotifications(int chatId, int messageId, boolean signal) {
|
||||
void sendNotifications(DcChat chat, int messageId, boolean signal) {
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(appContext);
|
||||
if (signal = isSignalAllowed(signal)) {
|
||||
lastAudibleNotification = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
if (dcContext.getChat(chatId).isDeviceTalk()) {
|
||||
if (chat.isDeviceTalk()) {
|
||||
// currently, we just never notify on device chat.
|
||||
// esp. on first start, this is annoying.
|
||||
return;
|
||||
}
|
||||
|
||||
addMessageToNotificationState(dcContext, chatId, messageId);
|
||||
addMessageToNotificationState(dcContext, chat, messageId);
|
||||
synchronized (lock) {
|
||||
if (notificationState.hasMultipleChats()) {
|
||||
sendMultipleChatNotification(appContext, notificationState, signal);
|
||||
|
||||
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
@@ -278,16 +279,12 @@ public class Prefs {
|
||||
|
||||
// mute
|
||||
|
||||
public static void setChatMutedUntil(Context context, int chatId, long until) {
|
||||
setLongPreference(context, CHAT_MUTED_UNTIL+chatId, until);
|
||||
public static void setChatMuteDuration(DcContext context, int chatId, long duration) {
|
||||
context.setChatMuteDuration(chatId, duration);
|
||||
}
|
||||
|
||||
public static long getChatMutedUntil(Context context, int chatId) {
|
||||
return getLongPreference(context, CHAT_MUTED_UNTIL+chatId, 0);
|
||||
}
|
||||
|
||||
public static boolean isChatMuted(Context context, int chatId) {
|
||||
return System.currentTimeMillis() <= getChatMutedUntil(context, chatId);
|
||||
public static boolean isChatMuted(DcChat chat) {
|
||||
return chat.isMuted();
|
||||
}
|
||||
|
||||
// map
|
||||
|
||||
Reference in New Issue
Block a user