fix/plugin-post-display-incoming-only #132
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/plugin-post-display-incoming-only"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Plugins listening on
plugins_post_chat_message_display(e.g.sounds.py— plays a notification sound on a new incoming chat message) were firing in places that are not "a remote party sent a chat message and it was displayed":Net effect for
sounds.py(and any plugin that treats the hook as "a new message arrived"): notification sound on every open / send / carbon, which is essentially constant nuisance.Root cause
The post-display hook was invoked from four sites in
src/ui/chatwin.c:chatwin_incoming_msgchatwin_outgoing_msgchatwin_outgoing_carbon_chatwin_historychatwin_db_historyOnly the first matches the hook's semantic. The other four were spurious — they treated "display happened" as the trigger condition instead of "an incoming message was displayed".
Fix
Remove the
plugins_post_chat_message_display(...)call from the four spurious sites. Keep it only inchatwin_incoming_msg. The corresponding pre-display hook (plugins_pre_chat_message_display) and themsg->plain = old_plainswap that bracket it stay in place — those affect how the message is rendered, independent of the post hook.One file, five deletions.
Why
prestays asymmetric topostAfter this fix the two hooks no longer pair up in outgoing / carbon / history paths:
pre_chat_message_displayis still called there,post_chat_message_displayis not. That asymmetry is deliberate. The two hooks have different semantics:pre_chat_message_displaylets a plugin modify the text that will be rendered (formatting, redaction, link rewriting, etc.). This is useful in every display path and is kept everywhere.post_chat_message_displayis a notification that an incoming chat message arrived and was displayed. It is the trigger plugins likesounds.pylegitimately listen to. It should not fire on history or on the user's own outgoing.Removing
pretogether withpostwould lose display-mutation capability for everything except true incoming, which is unrelated to the bug.Verify
sounds.pyduring the history render.Note for plugin authors
Plugins relying on the previous (broader) trigger semantics will see the hook only on true incoming displays. Replacements:
plugins_post_chat_message_send(already fires fromsrc/event/client_events.c:176).plugins_post_chat_message_send_carbon); intentionally out of scope here.Checked for collateral
plugins_post_room_message_display) — searchedsrc/ui/mucwin.candsrc/event/client_events.c; the analogous mis-use does not exist for groupchat. Onlyplugins_post_room_message_sendis wired, on the outgoing path. No companion MUC fix needed.chatwin_db_history. After this fix the post-display hook does not fire for MAM-loaded messages, which is the desired behaviour (archived messages are not new arrivals).preswap — theauto_charplugin string is freed at the end of its declaration scope, aftermsg->plain = old_plainhas restored the original pointer. No use-after-free introduced.3b84d5c4eetoa04a8948e1