mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
really mark messages as read from notification
This commit is contained in:
@@ -8,6 +8,8 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
@@ -16,6 +18,7 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||
public static final String CANCEL_ACTION = "org.thoughtcrime.securesms.notifications.CANCEL";
|
||||
public static final String ACCOUNT_ID_EXTRA = "account_id";
|
||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||
public static final String MSG_ID_EXTRA = "msg_id";
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
@@ -26,6 +29,7 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||
|
||||
final int accountId = intent.getIntExtra(ACCOUNT_ID_EXTRA, 0);
|
||||
final int chatId = intent.getIntExtra(CHAT_ID_EXTRA, DC_CHAT_NO_CHAT);
|
||||
final int msgId = intent.getIntExtra(MSG_ID_EXTRA, 0);
|
||||
if (accountId == 0 || chatId == DC_CHAT_NO_CHAT) {
|
||||
return;
|
||||
}
|
||||
@@ -33,7 +37,9 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
DcHelper.getNotificationCenter(context).removeNotifications(accountId, chatId);
|
||||
if (markNoticed) {
|
||||
DcHelper.getAccounts(context).getAccount(accountId).marknoticedChat(chatId);
|
||||
DcContext dcContext = DcHelper.getAccounts(context).getAccount(accountId);
|
||||
dcContext.marknoticedChat(chatId);
|
||||
dcContext.markseenMsgs(new int[]{msgId});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -138,12 +138,13 @@ public class NotificationCenter {
|
||||
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE());
|
||||
}
|
||||
|
||||
private PendingIntent getMarkAsReadIntent(ChatData chatData, boolean markNoticed) {
|
||||
private PendingIntent getMarkAsReadIntent(ChatData chatData, int msgId, boolean markNoticed) {
|
||||
Intent intent = new Intent(markNoticed? MarkReadReceiver.MARK_NOTICED_ACTION : MarkReadReceiver.CANCEL_ACTION);
|
||||
intent.setClass(context, MarkReadReceiver.class);
|
||||
intent.setData(Uri.parse("custom://"+chatData.accountId+"."+chatData.chatId));
|
||||
intent.putExtra(MarkReadReceiver.ACCOUNT_ID_EXTRA, chatData.accountId);
|
||||
intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatData.chatId);
|
||||
intent.putExtra(MarkReadReceiver.MSG_ID_EXTRA, msgId);
|
||||
intent.setPackage(context.getPackageName());
|
||||
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | IntentUtils.FLAG_MUTABLE());
|
||||
}
|
||||
@@ -377,7 +378,7 @@ public class NotificationCenter {
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
.setOnlyAlertOnce(!signal)
|
||||
.setContentText(line)
|
||||
.setDeleteIntent(getMarkAsReadIntent(chatData, false))
|
||||
.setDeleteIntent(getMarkAsReadIntent(chatData, msgId, false))
|
||||
.setContentIntent(getOpenChatIntent(chatData));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
@@ -449,7 +450,7 @@ public class NotificationCenter {
|
||||
if (privacy.isDisplayContact() && privacy.isDisplayMessage()) {
|
||||
try {
|
||||
PendingIntent inNotificationReplyIntent = getRemoteReplyIntent(chatData);
|
||||
PendingIntent markReadIntent = getMarkAsReadIntent(chatData, true);
|
||||
PendingIntent markReadIntent = getMarkAsReadIntent(chatData, msgId, true);
|
||||
|
||||
NotificationCompat.Action markAsReadAction = new NotificationCompat.Action(R.drawable.check,
|
||||
context.getString(R.string.mark_as_read_short),
|
||||
|
||||
Reference in New Issue
Block a user