Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show number of unread messages in back-button (#2280) #2303

Merged
merged 4 commits into from
Oct 25, 2024

Conversation

zeitschlag
Copy link
Collaborator

@zeitschlag zeitschlag commented Sep 20, 2024

  • These changes are iOS 13+ only.
  • Adds an indicator with the number of unread messages to the back-button in chat if there are unread messages.

Simulator Screenshot - iPhone 16 Pro - 2024-09-23 at 12 24 58

  • If you have more than 50 unread messages, you'll just see a dot.
  • Also: Fix build Xcode 18

@zeitschlag zeitschlag linked an issue Sep 20, 2024 that may be closed by this pull request
@zeitschlag zeitschlag self-assigned this Sep 20, 2024
@zeitschlag zeitschlag changed the title [WIP] 2280 show unread messages Show number of unread messages in back-button (#2280) Sep 23, 2024
@zeitschlag zeitschlag marked this pull request as ready for review September 23, 2024 10:30
@zeitschlag
Copy link
Collaborator Author

zeitschlag commented Oct 1, 2024

The current implementation doesn't show the number in case the account is muted. This kind of feels like a bug? So I was thinking about adding this additional piece, which just gets all accounts' fresh messages. WDYT @r10s?

diff --git a/deltachat-ios/Controller/ChatListViewController.swift b/deltachat-ios/Controller/ChatListViewController.swift
index 64eadc64..0bfa5b03 100644
--- a/deltachat-ios/Controller/ChatListViewController.swift
+++ b/deltachat-ios/Controller/ChatListViewController.swift
@@ -253,7 +253,7 @@ class ChatListViewController: UITableViewController {
     }
 
     private func updateNextScreensBackButton(accountId: Int? = nil, chatId: Int? = nil) {
-        let numberOfUnreadMessages = DcAccounts.shared.getFreshMessageCount()
+        let numberOfUnreadMessages = DcAccounts.shared.getAllFreshMessages()
 
         if isArchive {
             navigationItem.backBarButtonItem = nil
diff --git a/deltachat-ios/DC/DcAccount.swift b/deltachat-ios/DC/DcAccount.swift
index ff1cbe9a..fca72f7f 100644
--- a/deltachat-ios/DC/DcAccount.swift
+++ b/deltachat-ios/DC/DcAccount.swift
@@ -129,6 +129,17 @@ public class DcAccounts {
         return freshCount
     }
 
+    public func getAllFreshMessages() -> Int {
+
+        let accountIDs = getAll()
+        let numberOfFreshMessages = accountIDs
+            .compactMap { get(id: $0) }
+            .compactMap { $0.getFreshMessages().count }
+            .reduce(0) { $0 + $1 }
+
+        return numberOfFreshMessages
+    }
+
     @discardableResult
     public func blockingCall(method: String, params: [AnyObject]) -> Data? {
         if let paramsData = try? JSONSerialization.data(withJSONObject: params),

@Amzd
Copy link
Collaborator

Amzd commented Oct 15, 2024

The current implementation doesn't show the number in case the account is muted

I think that would be expected. If you mute eg a group chat you don't want it still to show up in the back button because that would hide wether there is actual messages that you need to look at.

Copy link
Member

@r10s r10s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am using this PR since quite some time, and it is really great!

i am still a bit unsure about the displaying of "50 max" - discussed alternatives are
(1) using a normal number (this is what whatsapp is doing) or
(2) do not show a number at all but show a "unread dot" only if sth. new comes in or
(3) use a "real" badge (this is more effort, and we should really know that we want the badge to stay

however, let's stay with the current state, maybe it is just fine and good enough :)

wondering, btw about the reasoning of using updateNextScreensBackButton() to pass the event from ChatListViewController to ChatViewController. is that because of improved performance as when using an event in ChatViewController, one has to calculate things again?

@r10s r10s added the enhancement actually in development, user visible enhancement label Oct 21, 2024
Consider this WIP as there's still some flickering when receiving a message when on a chat. Something, something event-handling
Back-button wasn't updated when there were no more fresh messages
@r10s r10s merged commit bd3d4e8 into main Oct 25, 2024
1 check passed
@r10s r10s deleted the 2280-show-unread-messages branch October 25, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement actually in development, user visible enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show number of unread messages in Back-button on ChatViewController
3 participants