Start transitioning to the mute functions of the core

This commit is contained in:
Hocuri 2020-05-13 13:29:55 +02:00 committed by B. Petersen
parent 2eca2330a9
commit 40e24c3a39
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
9 changed files with 39 additions and 36 deletions

View file

@ -1184,6 +1184,16 @@ JNIEXPORT jintArray Java_com_b44t_messenger_DcContext_getChatContacts(JNIEnv *en
return dc_array2jintArray_n_unref(env, ca); 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 * DcMsg
@ -1669,4 +1679,3 @@ JNIEXPORT jstring Java_com_b44t_messenger_DcContext_dataToString(JNIEnv *env, jc
const char* cstring = (const char*)data; const char* cstring = (const char*)data;
return JSTRING_NEW(cstring); return JSTRING_NEW(cstring);
} }

View file

@ -35,6 +35,7 @@ public class DcChat {
public native boolean canSend (); public native boolean canSend ();
public native boolean isVerified (); public native boolean isVerified ();
public native boolean isSendingLocations(); public native boolean isSendingLocations();
public native boolean isMuted ();
// working with raw c-data // working with raw c-data
private long chatCPtr; // CAVE: the name is referenced in the JNI private long chatCPtr; // CAVE: the name is referenced in the JNI

View file

@ -161,6 +161,7 @@ public class DcContext {
public native int[] getChatMedia (int chat_id, int type1, int type2, int type3); 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 getNextMedia (int msg_id, int dir, int type1, int type2, int type3);
public native int[] getChatContacts (int chat_id); public native int[] getChatContacts (int chat_id);
public native boolean setChatMuteDuration (int chat_id, long duration);
public native void deleteChat (int chat_id); public native void deleteChat (int chat_id);
public @NonNull DcMsg getMsg (int msg_id) { return new DcMsg(getMsgCPtr(msg_id)); } public @NonNull DcMsg getMsg (int msg_id) { return new DcMsg(getMsgCPtr(msg_id)); }
public native String getMsgInfo (int id); public native String getMsgInfo (int id);

View file

@ -433,7 +433,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
inflater.inflate(R.menu.conversation, menu); 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); menu.findItem(R.id.menu_mute_notifications).setTitle(R.string.menu_unmute);
} }
@ -561,14 +561,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
private void handleMuteNotifications() { private void handleMuteNotifications() {
if(!Prefs.isChatMuted(this, chatId)) { if(!Prefs.isChatMuted(dcChat)) {
MuteDialog.show(this, until -> { MuteDialog.show(this, duration -> {
Prefs.setChatMutedUntil(this, chatId, until); Prefs.setChatMuteDuration(dcContext, chatId, duration);
titleView.setTitle(glideRequests, dcChat); titleView.setTitle(glideRequests, dcChat);
}); });
} else { } else {
// unmute // unmute
Prefs.setChatMutedUntil(this, chatId, 0); Prefs.setChatMuteDuration(dcContext, chatId, 0);
titleView.setTitle(glideRequests, dcChat); titleView.setTitle(glideRequests, dcChat);
} }
} }

View file

@ -66,7 +66,7 @@ public class ConversationTitleView extends RelativeLayout {
setComposeTitle(); setComposeTitle();
} else { } else {
setRecipientTitle(dcChat, showSubtitle); setRecipientTitle(dcChat, showSubtitle);
if (Prefs.isChatMuted(getContext(), dcChat.getId())) { if (Prefs.isChatMuted(dcChat)) {
imgLeft = R.drawable.ic_volume_off_white_18dp; imgLeft = R.drawable.ic_volume_off_white_18dp;
} }
if (dcChat.isVerified()) { if (dcChat.isVerified()) {

View file

@ -15,20 +15,20 @@ public class MuteDialog {
builder.setItems(R.array.mute_durations, (dialog, which) -> { builder.setItems(R.array.mute_durations, (dialog, which) -> {
final long muteUntil; final long muteUntil;
// See https://c.delta.chat/classdc__context__t.html#a6460395925d49d2053bc95224bf5ce37.
switch (which) { switch (which) {
case 0: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break; case 0: muteUntil = 0; break; // unmute
case 1: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(2); break; case 1: muteUntil = TimeUnit.HOURS.toSeconds(2); break;
case 2: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1); break; case 2: muteUntil = TimeUnit.DAYS.toSeconds(1); break;
case 3: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(7); break; case 3: muteUntil = TimeUnit.DAYS.toSeconds(7); break;
case 4: muteUntil = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(36500); break; case 4: muteUntil = -1; break; // mute forever
default: muteUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1); break; default: muteUntil = 0; break;
} }
listener.onMuted(muteUntil); listener.onMuted(muteUntil);
}); });
builder.show(); builder.show();
} }
public interface MuteSelectionListener { public interface MuteSelectionListener {

View file

@ -140,7 +140,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
item = menu.findItem(R.id.menu_mute_notifications); item = menu.findItem(R.id.menu_mute_notifications);
if(item!=null) { 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); super.onPrepareOptionsMenu(menu);
@ -351,7 +351,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
} }
public void onNotifyOnOff() { public void onNotifyOnOff() {
if (Prefs.isChatMuted(this, chatId)) { if (Prefs.isChatMuted(dcContext.getChat(chatId))) {
setMuted(0); setMuted(0);
} }
else { else {
@ -359,14 +359,9 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
} }
} }
private void setMuted(final long until) { private void setMuted(final long duration) {
if(chatId!=0) { if (chatId != 0) {
Prefs.setChatMutedUntil(this, chatId, until); Prefs.setChatMuteDuration(dcContext, chatId, duration);
// 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);
} }
} }

View file

@ -90,7 +90,7 @@ abstract class MessageNotifier {
boolean isVisible = visibleChatId == chatId; boolean isVisible = visibleChatId == chatId;
if (!Prefs.isNotificationsEnabled(appContext) || if (!Prefs.isNotificationsEnabled(appContext) ||
Prefs.isChatMuted(appContext, chatId)) Prefs.isChatMuted(dcContext.getChat(chatId)))
{ {
return; return;
} }
@ -352,7 +352,7 @@ abstract class MessageNotifier {
return; return;
} }
if(Prefs.isChatMuted(appContext, chatId)) { if(Prefs.isChatMuted(, chatId)) {
Log.d(TAG, "chat muted"); Log.d(TAG, "chat muted");
return; return;
} }
@ -363,7 +363,7 @@ abstract class MessageNotifier {
} }
void addMessageToNotificationState(ApplicationDcContext dcContext, int chatId, int msgId) { void addMessageToNotificationState(ApplicationDcContext dcContext, int chatId, int msgId) {
if (Prefs.isChatMuted(appContext, chatId)) { if (Prefs.isChatMuted(dcContext.getChat(chatId))) {
return; return;
} }

View file

@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContext; import com.b44t.messenger.DcContext;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
@ -278,16 +279,12 @@ public class Prefs {
// mute // mute
public static void setChatMutedUntil(Context context, int chatId, long until) { public static void setChatMuteDuration(DcContext context, int chatId, long duration) {
setLongPreference(context, CHAT_MUTED_UNTIL+chatId, until); context.setChatMuteDuration(chatId, duration);
} }
public static long getChatMutedUntil(Context context, int chatId) { public static boolean isChatMuted(DcChat chat) {
return getLongPreference(context, CHAT_MUTED_UNTIL+chatId, 0); return chat.isMuted();
}
public static boolean isChatMuted(Context context, int chatId) {
return System.currentTimeMillis() <= getChatMutedUntil(context, chatId);
} }
// map // map