Skip to content

fix(dashboard): Don't treat "no mention" as unread when the read marker is negative - #20061

Open
vlfesko wants to merge 1 commit into
nextcloud:mainfrom
vlfesko:fix/noid/dashboard-unread-mention
Open

vlfesko wants to merge 1 commit into
nextcloud:mainfrom
vlfesko:fix/noid/dashboard-unread-mention

Conversation

@vlfesko

@vlfesko vlfesko commented Oct 30, 2026

Copy link
Copy Markdown

☑️ Resolves

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

The patch and the test were written with the help of Claude Code and reviewed by me; the commit carries an Assisted-by trailer.

The problem

last_mention_message is 0 when there is no mention, while last_read_message can be negative: -2 (ChatManager::UNREAD_FIRST_MESSAGE) or -1 (UNREAD_MIGRATION). The dashboard widget compared them with getLastMentionMessage() > getLastReadMessage(), and 0 > -2 is true.

Since #19654 TalkWidget::prepareRoom() then calls ChatManager::getComment($room, "0"), where OC\Comments\Manager::get("0") throws InvalidArgumentException: IDs must be translatable to a number in this implementation. Only NotFoundException is caught, so GET /ocs/v2.php/apps/dashboard/api/v2/widget-items?widgets[]=spreed answers 500. The dashboard then stops loading other widgets too (the "Recommended files" widget kept its spinner).

-2 is not rare: it is set when the chat history is cleared (ParticipantService::resetChatDetails), by "mark as unread", and by the FixLastReadMessageZero repair step (a new attendee of an empty room starts with 0, which becomes -2 after an update).

Seen on a real instance (25.0.6): the per-user changelog conversation Talk creates after an update, not opened yet (last_read_message = -2, last_mention_message = 0). Opening the conversation made the 500 go away.

To reproduce without the changelog: two users in a group conversation, a moderator clears the history, the other user opens the dashboard.

The fix

hasUnreadMention(Attendee) requires an actual mention (> 0) before comparing it with the read marker, and is used at the three places that had the comparison (getItems(), getItemsV2(), prepareRoom()). In API v2 such a conversation is also no longer listed among the "mentions".

prepareRoom() does not catch InvalidArgumentException on purpose: after the guard the ID is always positive, and ICommentsManager::get() documents only NotFoundException.

On stable32–34 there is no 500 (the getComment() call is not there), only the same misclassification ("You were mentioned"); the code differs there, so a backport to those is up to you.

Tests

New tests/php/Dashboard/TalkWidgetTest.php: a data provider for hasUnreadMention() and a getItemsV2() case with last_read_message = -2 and last_mention_message = 0. Run against the server master (sqlite): 9 tests pass; without the fix the getItemsV2() test fails with getComment(..., '0') was not expected to be called. I did not run php-cs-fixer and psalm locally, CI will.

🛠️ API 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

Could you add the regression label and /backport to stable35 after merging? I can't set labels from a fork.

…er is negative

last_mention_message is 0 when there is no mention, but last_read_message
can be -2 (UNREAD_FIRST_MESSAGE) or -1 (UNREAD_MIGRATION), so `0 > -2` counted
the conversation as an unread mention. Since nextcloud#19654 prepareRoom() then loads
message "0", OC\Comments\Manager::get() throws an InvalidArgumentException and
the widget-items request fails with HTTP 500.

Assisted-by: ClaudeCode:claude-sonnet-5-5
Signed-off-by: Volodymyr Fesko <vladimir.fesko@gmail.com>
@nickvergessen nickvergessen added this to the ☃️ Next Major (36) milestone Oct 30, 2026
@nickvergessen nickvergessen added bug feature: api 🛠️ OCS API for conversations, chats and participants feature: dashboard 🏠 Features relating to the Talk internal dashboard labels Oct 30, 2026
@sudormant sudormant self-assigned this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug feature: api 🛠️ OCS API for conversations, chats and participants feature: dashboard 🏠 Features relating to the Talk internal dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants