Problem/Motivation
InboxMessageFetcher::storeMessages() sets state to unread on every message it receives. InboxMessageStorage::save() then merges on id only and writes all fields, including state.
state.
So whenever the feed returns a message that is already stored, it goes back to unread, even if the user read or dismissed it. A dismissed message shows up in the dashboard inbox again, and the unread count in the toolbar goes back up.
This started with #3546833. Before that change, the merge keys were id + state = unread, so messages that were no longer unread were never updated. Re-fetching one threw a primary key violation instead, which is what #3546833 fixed by removing the state key. The fetcher still forces unread, though, so read and dismissed messages are now silently overwritten.
Steps to reproduce
- Let cron fetch the inbox messages (or fetch them manually).
- Dismiss (or read) a message on
/admin/commerce. - Delete the
commerce.inbox_messages_cron_laststate key (drush state:del commerce.inbox_messages_cron_last) and run cron again while the message is still in the feed. - The message is unread again and shows up in the inbox.
Proposed resolution
In InboxMessageFetcher::storeMessages(), keep the state of a message that is already stored, and only default to unread for new messages. The subject, body and CTA still get updated from the feed.
This also covers fetchNewStoreMessages(), which goes through the same method.
Remaining tasks
- Fix
- Kernel test that re-fetching a read or dismissed message keeps its state
Issue fork commerce-3635099
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jsacksick commented