New message is marked as read by a conversation screen left in the background

Open Beginner friendly
#927 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Read app/src/main/kotlin/org/fossify/messages/activities/ThreadActivity.kt, especially setupThreadItems() at the linked lines and the existing onResume() call to markThreadMessagesRead(threadId). Reproduce by leaving a conversation on the Home screen and receiving a message from that contact. Done when the message stays unread while the conversation screen is in the background and is marked read when the user returns.

Written by the indexing model from the issue text.

Description

bug needs triage
Checklist
  • I can reproduce the bug with the latest version given here.
  • I made sure that there are no existing issues - open or closed - to which I could contribute my information.
  • I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
  • I have read the FAQs inside the app (Menu -> About -> FAQs) and my problem isn't listed.
  • I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
  • This issue contains only one bug.
  • I have read and understood the contribution guidelines.
Affected app version

1.10.1

Affected Android/Custom ROM version

Android 16 (One UI 8.5)

Affected device model

Samsung Galaxy A54 (SM-A546E), also reproduced on the Android Studio emulator (API 36)

How did you install the app?

No response

Steps to reproduce the bug
  1. Open a conversation with contact X.
  2. Press Home (do not press Back, so the conversation screen stays in memory).
  3. Receive an SMS from X.
  4. Open the app.
Expected behavior

The new message is unread: the conversation is shown as unread in the list until I open it.

Actual behavior

A notification is shown (and the launcher badge says 1), but the message is already marked as read in the SMS database (read=1). The conversation list shows nothing unread.

Screenshots/Screen recordings

No response

Additional information

Cause: SmsReceiver posts RefreshMessages. The ThreadActivity in the background receives it (ThreadMode.ASYNC), rebuilds its list in setupThreadItems() and marks every unread message as read, even though the screen is not visible:
https://github.com/FossifyOrg/Messages/blob/cf045ab5bdd36814be2b3d287cc294ce3f2b3fc7/app/src/main/kotlin/org/fossify/messages/activities/ThreadActivity.kt#L1371-L1375

Suggested fix: mark messages as read there only while the screen is visible. onResume() already calls markThreadMessagesRead(threadId), so nothing is lost when the user comes back.

@Volatile // read on background threads too
private var isActivityVisible = false
...
if (!message.read && isActivityVisible) {
    hadUnreadItems = true
    markMessageRead(message.id, message.isMMS)
    conversationsDB.markRead(threadId)
}

Found and tested in a personal fork built from 1.10.1 (only unrelated features added). The code involved is unchanged on main (cf045ab). Fix in the fork, for reference: https://github.com/fatehiman/peppa-ai-messages/commit/44d2d3876

Dominant language
Kotlin
Stars
1.6k
Forks
187
Avg merge
4d 5h
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from FossifyOrg/Messages

All issues in FossifyOrg/Messages

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.