Skip to content

feat: emit amount of unread messages to display the badge in Talk Desktop #14668

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

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

markusstoll
Copy link
Contributor

@markusstoll markusstoll commented Mar 17, 2025

☑️ Implements issue #14667

I had to introduce some changes to spreed that are described below to create a central unreadCountStore to have an even hook in talk-desktop to get updates of these unreadCounts and enable talk-desktop to set the correct badge count on the app icon.

1. New unreadCountStore

A new Vuex store module that serves as the single source of truth for all unread counters:

state: {
    // Total counters
    totalUnreadMessages: 0,
    totalUnreadMentions: 0,
    totalUnreadMentionDirect: 0,

    // Per-conversation tracking
    unreadMessagesMap: {},
    unreadMentionsMap: {},
    unreadMentionDirectMap: {},
}

2. Integration Points

Conversations Store

  • Enhanced addConversation mutation:

    • Automatically updates unread counters when adding new conversations
    • Handles initial state synchronization
  • Improved updateConversation mutation:

    • Detects changes in unread counts
    • Dispatches updates to unreadCountStore
    • Maintains consistency across state changes
  • Updated deleteConversation mutation:

    • Properly removes conversation counts from tracking
    • Updates total counters accordingly

Messages Store

  • Enhanced updateLastReadMessage action:
    • Improved handling of "all messages read" scenarios
    • Proper counter reset when reaching conversation end
    • Better integration with chat-read-last feature

3. Event System

New event for badge updates:

EVENTS.UNREAD_COUNT_UPDATED: 'talk:unread:updated'

🏁 Checklist

This issue is not browser depending.
But I added a matching change in talk-desktop and have a working application icon badge implementation.
This is already tested in Windows and MacOs builds of talk-desktop.

Pull request for talk-desktop is about to follow

🛠️ API Checklist

🚧 Tasks

  • ...

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not possible
  • 📘 API documentation in docs/ has been updated or is not required
  • 🔖 Capability is added or not needed

@nickvergessen
Copy link
Member

The main colleagues are currently out a bit. Hopefully they are able to give feedback towards the end of the week

@Antreesy
Copy link
Contributor

A couple of things to mention:

  • we are migrating from Vuex to pinia. Introducing a new Vuex store creates a techdebt for us in the future;
  • second PR for talk-desktop would be nice to have, to be able to give both a test

@markusstoll
Copy link
Contributor Author

markusstoll commented Mar 17, 2025

@Antreesy I understand your point, but unaware of your replacement solution for Vuex, I hardly could have taken that into account.
A pull request for talk-desktop is almost finished, you will have it shortly

@Antreesy
Copy link
Contributor

Don't worry about it, we appreciate efforts you put into this and will help with fixing that 😉
Thanks again for your contribution! I'll be back at Wednesday and will try to check it ASAP

Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

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

Gave it a smoke test, seems to be working as expected 🎉

Leaving my thoughts for this PR. I suggest you to wait for another devs opinions, before rewriting anything; then we can find a common ground before putting more efforts into this feature.

@markusstoll
Copy link
Contributor Author

Here as with talk-desktop:
I do not want anyone to rush things, but I understood correctly that we shall wait for more input from your devs?

@ShGKme
Copy link
Contributor

ShGKme commented Mar 25, 2025

Thank you for your contribution and moving forward to adding the counter-badge in the desktop client!

It seems to work, but I agree with @Antreesy's points.

We should not create a new store state for the unread counters, as this is not an independent state, but a computation on top of the existing state (conversation list). Having it as a new state will likely lead to inconsistent application state in the future and requires manual updates.

This makes sense for performance. However, even with ~1000 conversations counting, there should be no performance issue.

Let's simplify it to one getter in the existing conversationsStore and then watch for its changes to emit the global event in the App.vue.

Copy link
Contributor

github-actions bot commented Apr 1, 2025

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@ShGKme
Copy link
Contributor

ShGKme commented Apr 7, 2025

Hey, @markusstoll!

Do you plan to adjust the PRs? Maybe we can assist with anything?

This is an important feature that we'd like to add. If you don't have time now - no problem, but then we'd need to take it over.

@markusstoll
Copy link
Contributor Author

Sorry, I was drawn into some urgent issues in my paid work. I will start the rework soon, hopefully this week

@markusstoll markusstoll force-pushed the feature/unreadCountStore branch from c93a01c to 8255759 Compare April 10, 2025 14:54
@markusstoll
Copy link
Contributor Author

Hi,

I hope I understood your comments correctly. Pls review the reworked PR - will submit a matching PR for talk-desktop asap

@markusstoll
Copy link
Contributor Author

Hi, I did take into account all your remarks and fixed them where needed.

On

It didn't work without emitting here? On updates it's supposed to change conversations data and trigger computing

Indeed without initial counter is not shown on badge

On

May I ask if this was AI-generated? :)

You bet, as being a Java Developer for 25 years, I am mostly illiterate on such fancy JavaScript stuff and need AI support for all this syntax. But here I forgot to remove these additions in conversationsStore.js after deciding for smaller approach - I apologise for that.

After waiting for this feature for 1.5 years, I finally had to do something about it, using the means I have.

@ShGKme

This comment was marked as resolved.

@markusstoll

This comment was marked as resolved.

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

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

Some comments above are still unresolved

@markusstoll
Copy link
Contributor Author

you were right, but pls note the spelling difference, which I changed back to

emit('talk:unreads:updated', {

so it matches the doc in constants and the usage in talk-desktop

archived conversations are now ignored

Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

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

Nice enhancements! Tested with following suggestions, to reduce amount of computations.

Feel free to squash all commits into one, and name it according to convention spec. something like feat: <what's it doing> should be fine. Then I'll trigger the CI to get it merged

@markusstoll markusstoll force-pushed the feature/unreadCountStore branch from 17328ca to aca814a Compare April 11, 2025 18:54
@markusstoll
Copy link
Contributor Author

markusstoll commented Apr 11, 2025

Thanks for your comments which made this change even more lean and clean.
I followed your advice, but changed to my proposed event name "talk:unread:updated" which is used in my PR on talk-desktop. As the details in the event data bear the plural I think we it makes sense to stick with singular in the event name.
And I squashed all changes into 1 commit

Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

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

Thanks, Markus 🚀

@Antreesy Antreesy merged commit bb093bd into nextcloud:main Apr 14, 2025
53 checks passed
@github-project-automation github-project-automation bot moved this from 🏗️ In progress to ☑️ Done in 💬 Talk team Apr 14, 2025
@Antreesy Antreesy changed the title Introduce unreadCount store feat: emit amount of unread messages to display the badge in Talk Desktop Apr 14, 2025
@Antreesy
Copy link
Contributor

/backport to stable31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

4 participants