element-x-ios icon indicating copy to clipboard operation
element-x-ios copied to clipboard

App icon badge notification count is wrong.

Open ara4n opened this issue 1 year ago • 26 comments

Steps to reproduce

The badge count on the icon is calculated by the server, not by the app, and so tends to be wrong.

Outcome

What did you expect?

Reliable app icon badge count

What happened instead?

We had https://github.com/element-hq/element-x-ios/issues/2066, but that was exacerbated by a synapse bug now fixed. The overall design problem from https://github.com/matrix-org/matrix-spec-proposals/pull/4076 is still there though, and so the badge counts continue to be wrong...

Your phone model

No response

Operating system version

No response

Application version

675

Homeserver

No response

Will you send logs?

No

ara4n avatar Aug 11 '24 20:08 ara4n

I have suffered from this bug many times! I can accept that this is generally problematic, but going forward, is there any way to force reset the count from Synapse when this issue arises? Otherwise, could some reset cache button be added as an escape hatch as I believe resolves this is regular Element?

itsthejb avatar Sep 02 '24 09:09 itsthejb

Otherwise, could some reset cache button be added as an escape hatch as I believe resolves this is regular Element?

This wouldn't help as the app would still be using the count from Synapse I'm afraid.

pixlwave avatar Sep 09 '24 11:09 pixlwave

@pixlwave But this is what I can't understand - I don't see this badge issue on any other client than Element X for iOS: even installing Element X on macOS results in the correct badge count. All regular Element clients also display it correctly. It's literally only Element X on my phone 🤷

itsthejb avatar Sep 09 '24 11:09 itsthejb

Element iOS is using the badge number from Synapse until you open the app at which point it computes the badge locally as it has a copy of all the messages to use. Element X on the other hand is using Sliding Sync and with this, we don't (yet) have the code to fetch all of the necessary messages in order to do the computation locally.

pixlwave avatar Sep 09 '24 11:09 pixlwave

Ah I see. Ok thanks, that makes more sense

itsthejb avatar Sep 09 '24 12:09 itsthejb

This is super annoying and there seems to be nothing I can do besides disallow the badge. IMG_0806 IMG_0810

ledlamp avatar Oct 03 '24 06:10 ledlamp

Is there any progress towards resolution of this very annoying issue ?

dregad avatar Apr 04 '25 13:04 dregad

An interesting approach has been proposed by Danny in the Matrix Rust SDK Development room.

manuroe avatar Jun 04 '25 15:06 manuroe

I have the same issue since moving from Element to Element X.

On the dekstop app the badge count is correct, but on all my devices with Element X, there is an offset of +1 notification always.

aeonoea avatar Jul 22 '25 18:07 aeonoea

I'm having the same issue. I have a badge count of 8 that I cannot clear.

young-hnau avatar Jul 26 '25 15:07 young-hnau

I gave up on the badge count some time ago. I just disable it in iOS app settings

itsthejb avatar Jul 26 '25 15:07 itsthejb

I am not sure this is the same issue as #4365 as I do not have a fixed offset, but the number is stuck at 2 no matter how many messages I get. Am I missing something about this bug report?

dwt avatar Jul 29 '25 18:07 dwt

I am not sure this is the same issue as #4365 as I do not have a fixed offset, but the number is stuck at 2 no matter how many messages I get. Am I missing something about this bug report?

Same here

pReya avatar Aug 18 '25 14:08 pReya

Friendly ping @maintainers - are there any logs or tests I can perform to help you replicate this issue? I am a senior python developer with lots of backend experience, so I'm pretty handy around dev tools, but I have next to no experience with Swift, and the last time I wrote Obj-C and touched Xcode was probably around 20 years ago…

dwt avatar Aug 19 '25 20:08 dwt

are there any logs or tests I can perform to help you replicate this issue?

Hi Martin, thanks for offering to help but this has always mostly been a backend issue, with synapse sometimes not updating unread counts and forcing the wrong value to the client. While https://github.com/matrix-org/matrix-spec-proposals/pull/4076 and an implementation for it exists we would still need to locally compute the counts, which is currently blocked behind an improved cross process lock (NSE vs. the main app).

Luckly synapse is python but I wouldn't know where to start, perhaps issues like https://github.com/element-hq/synapse/issues/15698

stefanceriu avatar Aug 20 '25 06:08 stefanceriu

@stefanceriu I just noticed that I responded to this bug instead of #4365 as I intended to, as I cannot yet actually reproduce this issue. Sorry for the mixup. But I would appreciate some advice on how to help for the other bug.

dwt avatar Aug 20 '25 06:08 dwt

👋 I'm working on it: https://github.com/matrix-org/matrix-rust-sdk will provide what's needed for Element X to get a correct count value.

Hywan avatar Sep 09 '25 11:09 Hywan

@Hywan Please feel free to ping me if there is anything I can help test or provide logs for.

dwt avatar Sep 09 '25 12:09 dwt

@dwt Thanks :-)!

Hywan avatar Sep 10 '25 15:09 Hywan

@Hywan Any updates?

riesentoaster avatar Oct 22 '25 16:10 riesentoaster

When will this issue be resolved?

hogger0 avatar Oct 27 '25 10:10 hogger0

@hogger0's message reminded me of this. I turned off icon badging on iOS years ago because of this. Considering the leaps and bounds Element X iOS has taken recently (now becoming a really nice native chat client), that this incredibly fundamental issue still persists is really very frustrating and undermining

itsthejb avatar Oct 27 '25 10:10 itsthejb

No update yet. I've been off for 3 weeks, but I'm resuming my work now. A couple of other stuff needed to be done before continuing working on this. We are progressing :-). Keep an eye on This Week In Matrix, could be fun.

Hywan avatar Oct 28 '25 11:10 Hywan

That's amazing news. I'm sure everyone here is looking forward to the result

itsthejb avatar Oct 28 '25 12:10 itsthejb

Like I do!

Hywan avatar Oct 28 '25 13:10 Hywan

I was able to "fix" this from the server side by sending read receipts to rooms that had notifications in the sync query.

Kind of a huge pain, made somewhat easier by using matrix-commander and jq.

After pulling & configuring matrix-commander, the process was something like:

# Use the "sync" endpoint to get joined room IDs having non-zero unread notification counts (this might take a minute)
docker run --network=<docker_matrix_server_network> --rm -v ./:/data:z matrixcommander/matrix-commander --rest GET "" "http://<server>:<port>/_matrix/client/r0/sync?access_token=__access_token__" | jq '.rooms.join | map_values(select(.unread_notifications.notification_count != 0)) | keys[]' -r
# Get the latest message 'event_id' from a particular 'room_id' (hopefully that "event" is the most recent)
docker run --network=<docker_matrix_server_network> --rm -v ./:/data:z matrixcommander/matrix-commander --rest GET "" "http://<server>:<port>/_matrix/client/r0/rooms/<room_id>/messages?access_token=__access_token__&dir=b&limit=1" | jq -r '.chunk[0].event_id'
# Send a receipt message in that 'room_id' for that 'event_id'
docker run --network=<docker_matrix_server_network> --rm -v ./:/data:z matrixcommander/matrix-commander --rest POST "{}" "http://<server>:<port>/_matrix/client/r0/rooms/<room_id>/receipt/m.read/<event_id>?access_token=__access_token__"

Edit: One can pull out the room_id and event_id from the initial call to sync with something like this:

# Added a "filter" parameter to get just the latest event for each room of either 'm.reaction' or 'm.room.*' types
docker run \
  --network=<docker_matrix_server_network> \
  --rm \
  -v ./:/data:z matrixcommander/matrix-commander \
  --rest GET "" "http://<server>:<port>/_matrix/client/r0/sync?access_token=__access_token__&filter={\"room\":{\"timeline\":{\"limit\":1,\"types\":[\"m.room.*\",\"m.reaction\"]}}}" | \
# jq prints each 'room_id' and its latest 'event_id'
    jq '.rooms.join as $rooms_join | $rooms_join | map_values(select(.unread_notifications.notification_count != 0)) | keys[] | . as $room_id | $rooms_join[$room_id].timeline.events[0].event_id | "\($room_id) \(.)"' -r

GroveJay avatar Nov 04 '25 06:11 GroveJay