From 6a763ec2853c55b9c296a23b0ffd89e1cc212919 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 8 Oct 2020 18:17:37 +0200 Subject: [PATCH 1/4] speed up removeNotifications() if there is nothing to remove --- .../securesms/notifications/NotificationCenter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java index a8c859e6b..1d7cb84cb 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java @@ -502,9 +502,11 @@ public class NotificationCenter { } public void removeNotifications(int chatId) { - boolean removeSummary = false; + boolean removeSummary; synchronized (inboxes) { - inboxes.remove(chatId); + if (inboxes.remove(chatId) == null) { + return; // speed up things when there is nothing to remove + } removeSummary = inboxes.isEmpty(); } From 618af02bf54cb7fd66f9843e491bbf3206e7b26a Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 8 Oct 2020 18:41:04 +0200 Subject: [PATCH 2/4] fix "unread" appearance of chatlist before, the summary was bold when unread!=0 and the badge was shown when last-message-state=fresh|noticed. this is synced now; the unread-count-badge is mutual exclusive to checkmarks, so not meant to be shown for already answered messages. --- .../securesms/ConversationListItem.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 77a2ba4a7..bb19f1041 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -80,7 +80,6 @@ public class ConversationListItem extends RelativeLayout private DeliveryStatusView deliveryStatusIndicator; private ImageView unreadIndicator; - private int unreadCount; private AvatarImageView contactPhotoImage; public ConversationListItem(Context context) { @@ -133,7 +132,9 @@ public class ConversationListItem extends RelativeLayout this.chatId = thread.getThreadId(); this.msgId = msgId; this.glideRequests = glideRequests; - this.unreadCount = thread.getUnreadCount(); + + int state = dcSummary.getState(); + int unreadCount = (state==DcMsg.DC_STATE_IN_FRESH || state==DcMsg.DC_STATE_IN_NOTICED)? thread.getUnreadCount() : 0; if (highlightSubstring != null) { this.fromView.setText(getHighlightedSpan(locale, recipient.getName(), highlightSubstring)); @@ -159,7 +160,7 @@ public class ConversationListItem extends RelativeLayout thread.isSendingLocations()? R.drawable.ic_location_chatlist : 0, 0 ); - setStatusIcons(thread); + setStatusIcons(thread.getVisibility(), state, unreadCount); setBatchState(batchMode); setBgColor(thread); @@ -253,10 +254,9 @@ public class ConversationListItem extends RelativeLayout return dcContext.getMsg(msgId).getFromId(); } - private void setStatusIcons(ThreadRecord thread) { - if (thread.getVisibility()==DcChat.DC_CHAT_VISIBILITY_ARCHIVED) + private void setStatusIcons(int visibility, int state, int unreadCount) { + if (visibility==DcChat.DC_CHAT_VISIBILITY_ARCHIVED) { - // archived this.archivedView.setVisibility(View.VISIBLE); deliveryStatusIndicator.setNone(); unreadIndicator.setVisibility(View.GONE); @@ -264,12 +264,9 @@ public class ConversationListItem extends RelativeLayout else { this.archivedView.setVisibility(View.GONE); - int state = dcSummary.getState(); if (state==DcMsg.DC_STATE_IN_FRESH || state==DcMsg.DC_STATE_IN_NOTICED) { - // incoming deliveryStatusIndicator.setNone(); - int unreadCount = thread.getUnreadCount(); if(unreadCount==0) { unreadIndicator.setVisibility(View.GONE); } @@ -287,7 +284,6 @@ public class ConversationListItem extends RelativeLayout } else { - // outgoing unreadIndicator.setVisibility(View.GONE); if (state == DcMsg.DC_STATE_OUT_ERROR) { deliveryStatusIndicator.setFailed(); From cf1ab5f136c3365ad34cf97bdef91e96bf0abac2 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 8 Oct 2020 18:50:16 +0200 Subject: [PATCH 3/4] remove notifications when we know, a chat has no unread messages --- .../thoughtcrime/securesms/ConversationListItem.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index bb19f1041..2f1bb3ee7 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -126,6 +126,8 @@ public class ConversationListItem extends RelativeLayout boolean batchMode, @Nullable String highlightSubstring) { + ApplicationDcContext dcContext = DcHelper.getContext(getContext()); + this.dcSummary = dcSummary; this.selectedThreads = selectedThreads; Recipient recipient = thread.getRecipient(); @@ -133,8 +135,15 @@ public class ConversationListItem extends RelativeLayout this.msgId = msgId; this.glideRequests = glideRequests; + // if the last message is not fresh or noticed, we assume, there are no unread things + // and also remove notifications for the chat. + // this might be improved at some point in core, however, for now it is not that bad + // and ensures, things answered on device-A are no longer notified on device-B int state = dcSummary.getState(); int unreadCount = (state==DcMsg.DC_STATE_IN_FRESH || state==DcMsg.DC_STATE_IN_NOTICED)? thread.getUnreadCount() : 0; + if (unreadCount==0) { + dcContext.notificationCenter.removeNotifications((int)chatId); + } if (highlightSubstring != null) { this.fromView.setText(getHighlightedSpan(locale, recipient.getName(), highlightSubstring)); @@ -164,7 +173,6 @@ public class ConversationListItem extends RelativeLayout setBatchState(batchMode); setBgColor(thread); - ApplicationDcContext dcContext = DcHelper.getContext(getContext()); if(chatId == DcChat.DC_CHAT_ID_DEADDROP) { DcContact dcContact = dcContext.getContact(dcContext.getMsg(msgId).getFromId()); this.contactPhotoImage.setAvatar(glideRequests, dcContext.getRecipient(dcContact), false); From c89bec6a8b1ecd6de38ccd3001ca4b235a6e5ffc Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 9 Oct 2020 12:55:54 +0200 Subject: [PATCH 4/4] call removeNotifications() from bg thread and tweak comment --- .../securesms/ConversationListItem.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 2f1bb3ee7..794a149c5 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -52,6 +52,7 @@ import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.util.DateUtils; import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.ThemeUtil; +import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.ViewUtil; import java.util.Collections; @@ -135,14 +136,19 @@ public class ConversationListItem extends RelativeLayout this.msgId = msgId; this.glideRequests = glideRequests; - // if the last message is not fresh or noticed, we assume, there are no unread things - // and also remove notifications for the chat. - // this might be improved at some point in core, however, for now it is not that bad - // and ensures, things answered on device-A are no longer notified on device-B int state = dcSummary.getState(); int unreadCount = (state==DcMsg.DC_STATE_IN_FRESH || state==DcMsg.DC_STATE_IN_NOTICED)? thread.getUnreadCount() : 0; + + // if the last message is not fresh or noticed, we assume, there are no unread things + // and also remove notifications for the chat. + // this might be improved at some point in core, https://github.com/deltachat/deltachat-core-rust/issues/1974 + // and the following call to removeNotifications() can go to DC_EVENT_MSGS_NOTICED handler. + // however, for now it is not that bad + // and ensures, things answered on device-A are no longer notified on device-B. if (unreadCount==0) { - dcContext.notificationCenter.removeNotifications((int)chatId); + Util.runOnAnyBackgroundThread(() -> { + dcContext.notificationCenter.removeNotifications((int) chatId); + }); } if (highlightSubstring != null) {