mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Continue using the core functions for muting
This commit is contained in:
@@ -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,
|
||||
Prefs.isChatMuted(dcContext.getChat(chatId))? R.drawable.ic_volume_off_grey600_18dp : 0,
|
||||
0,
|
||||
thread.isVerified()? R.drawable.ic_verified : 0,
|
||||
0);
|
||||
|
||||
@@ -17,10 +17,10 @@ public class MuteDialog {
|
||||
|
||||
// See https://c.delta.chat/classdc__context__t.html#a6460395925d49d2053bc95224bf5ce37.
|
||||
switch (which) {
|
||||
case 0: muteUntil = 0; break; // unmute
|
||||
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 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;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class MuteDialog {
|
||||
}
|
||||
|
||||
public interface MuteSelectionListener {
|
||||
void onMuted(long until);
|
||||
void onMuted(long duration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity
|
||||
setMuted(0);
|
||||
}
|
||||
else {
|
||||
MuteDialog.show(this, until -> setMuted(until));
|
||||
MuteDialog.show(this, duration -> setMuted(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;
|
||||
@@ -74,7 +75,7 @@ public class FromTextView extends EmojiTextView {
|
||||
|
||||
int chatId = recipient.getAddress().isDcChat()? recipient.getAddress().getDcChatId() : 0;
|
||||
|
||||
if (Prefs.isChatMuted(getContext(), chatId)) {
|
||||
if (Prefs.isChatMuted(DcHelper.getContext(getContext()).getChat(chatId))) {
|
||||
setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_grey600_18dp, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -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(dcContext.getChat(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(, 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(dcContext.getChat(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);
|
||||
|
||||
Reference in New Issue
Block a user