piffy is developing a theme component widget that displays a notification bubble for new or unread topics, using topicTrackingState.onStateChange() to trigger real-time rerenders. They want to replicate this behavior for private messages (PMs) using new_personal_messages_notifications_count, but discovered the widget doesn’t rerender automatically when a new PM arrives. In post 2, piffy found a workaround using pmTopicTrackingState.onStateChange("pm-tracking-key", ...), which triggers rerenders on PM state changes — though the new_personal_messages_notifications_count value lags slightly, causing a minor delay in the widget’s update. Despite this, they consider it a “good enough” solution since the notification eventually appears. They welcome feedback or better approaches.
I would like to do something similar with PMs. I can use new_personal_messages_notifications_count to get the number of messages for a user. But if a new message is received the widget does not automatically rerender. Is there an easy way for me to update the widget on a new message being received similar to the topicTrackingState above?
So I found a working solution. There is apparently a private message version of the TopicTrackingState. Took me a while to figure out that it requires a “key” as a parameter, which is unclear to me what the key is for but it took an arbitrary string without issue
This triggers the rerender but I noticed that new_personal_messages_notifications_count is not updated in time for the rerender so it fails to actually update immediately.
I think this is a “good enough” solution for me though. The notification eventually makes it’s way onto the widget. I’m happy to hear any comments on this though