Compare commits
1 Commits
ref/light-
...
3b84d5c4ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
3b84d5c4ee
|
46
PR_plugin_post_display.md
Normal file
46
PR_plugin_post_display.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# fix(chatwin): only fire plugins_post_chat_message_display on incoming
|
||||
|
||||
**Base:** `master` ← `fix/plugin-post-display-incoming-only`
|
||||
|
||||
**Create PR:** https://git.jabber.space/devs/cproof/pulls/new/fix/plugin-post-display-incoming-only
|
||||
|
||||
## 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":
|
||||
|
||||
- Opening a chat — every message loaded from history triggered the hook, so the user heard the notification sound once per historical message.
|
||||
- Sending a chat message — the outgoing-message path triggered the hook, so sending played the incoming sound.
|
||||
- Receiving a carbon copy of your own outgoing message from another device — same, played the incoming sound.
|
||||
|
||||
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`:
|
||||
|
||||
| Function | Path |
|
||||
|---|---|
|
||||
| `chatwin_incoming_msg` | remote → us (true incoming) |
|
||||
| `chatwin_outgoing_msg` | us → remote |
|
||||
| `chatwin_outgoing_carbon` | us → remote, mirrored back via XEP-0280 carbons |
|
||||
| `_chatwin_history` | history scroll-back |
|
||||
| `chatwin_db_history` | DB-backed history load |
|
||||
|
||||
Only 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 in `chatwin_incoming_msg`. The corresponding pre-display hook (`plugins_pre_chat_message_display`) and the `msg->plain = old_plain` swap that bracket it stay in place — those affect how the message is rendered, independent of the post hook.
|
||||
|
||||
One file, five deletions.
|
||||
|
||||
## Verify
|
||||
|
||||
- Open a chat that has stored history → expect zero notification sounds from `sounds.py` during the history render.
|
||||
- Send a message → expect zero notification sound for your own outgoing.
|
||||
- Receive an outgoing carbon (send from another XMPP client logged into the same account) → expect zero notification sound.
|
||||
- Receive an actual incoming message from the remote contact → expect the notification sound exactly once.
|
||||
|
||||
## Note for plugin authors
|
||||
|
||||
Plugins relying on the previous (broader) trigger semantics will see the hook only on true incoming displays. If a plugin needs to observe outgoing or history events, it should hook into the corresponding paths instead (`plugins_post_chat_message_send` for outgoing; no current hook for history — could be added separately).
|
||||
14
src/common.c
14
src/common.c
@@ -748,17 +748,17 @@ call_external(gchar** argv)
|
||||
*
|
||||
* This function constructs an argument vector (argv) based on the provided template string, replacing placeholders ("%u" and "%p") with the provided URL and filename, respectively.
|
||||
*
|
||||
* @param template_fmt The template string with placeholders.
|
||||
* @param url The URL to replace "%u" (or NULL to skip).
|
||||
* @param filename The filename to replace "%p" (or NULL to skip).
|
||||
* @return The constructed argument vector (argv) as a null-terminated array of strings.
|
||||
* @param template The template string with placeholders.
|
||||
* @param url The URL to replace "%u" (or NULL to skip).
|
||||
* @param filename The filename to replace "%p" (or NULL to skip).
|
||||
* @return The constructed argument vector (argv) as a null-terminated array of strings.
|
||||
*
|
||||
* @note Remember to free the returned argument vector using `auto_gcharv` or `g_strfreev()`.
|
||||
*/
|
||||
gchar**
|
||||
format_call_external_argv(const char* template_fmt, const char* url, const char* filename)
|
||||
format_call_external_argv(const char* template, const char* url, const char* filename)
|
||||
{
|
||||
gchar** argv = g_strsplit(template_fmt, " ", 0);
|
||||
gchar** argv = g_strsplit(template, " ", 0);
|
||||
|
||||
guint num_args = 0;
|
||||
while (argv[num_args]) {
|
||||
@@ -767,7 +767,7 @@ format_call_external_argv(const char* template_fmt, const char* url, const char*
|
||||
argv[num_args] = g_strdup(url);
|
||||
} else if (0 == g_strcmp0(argv[num_args], "%p") && filename != NULL) {
|
||||
g_free(argv[num_args]);
|
||||
argv[num_args] = g_strdup(filename);
|
||||
argv[num_args] = strdup(filename);
|
||||
}
|
||||
num_args++;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ void get_file_paths_recursive(const char* directory, GSList** contents);
|
||||
gchar* get_random_string(int length);
|
||||
|
||||
gboolean call_external(gchar** argv);
|
||||
gchar** format_call_external_argv(const char* template_fmt, const char* url, const char* filename);
|
||||
gchar** format_call_external_argv(const char* template, const char* url, const char* filename);
|
||||
|
||||
gchar* unique_filename_from_url(const char* url, const char* path);
|
||||
gchar* get_expanded_path(const char* path);
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#ifndef EVENT_COMMON_H
|
||||
#define EVENT_COMMON_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
void ev_disconnect_cleanup(void);
|
||||
void ev_inc_connection_counter(void);
|
||||
void ev_reset_connection_counter(void);
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#ifndef PGP_GPG_H
|
||||
#define PGP_GPG_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
typedef struct pgp_key_t
|
||||
{
|
||||
gchar* id;
|
||||
|
||||
@@ -10,10 +10,8 @@
|
||||
#ifndef BOOKMARK_IGNORE_H
|
||||
#define BOOKMARK_IGNORE_H
|
||||
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
void bookmark_ignore_on_connect(const char* const barejid);
|
||||
void bookmark_ignore_on_disconnect();
|
||||
void bookmark_ignore_on_disconnect(void);
|
||||
gboolean bookmark_ignored(Bookmark* bookmark);
|
||||
gchar** bookmark_ignore_list(gsize* len);
|
||||
void bookmark_ignore_add(const char* const barejid);
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#ifndef UI_TITLEBAR_H
|
||||
#define UI_TITLEBAR_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
void create_title_bar(void);
|
||||
void free_title_bar(void);
|
||||
void title_bar_update_virtual(void);
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "ai/ai_client.h"
|
||||
|
||||
static const int PAD_MIN_HEIGHT = 100;
|
||||
static const int PAD_THRESHOLD = 12000; // above buffer cap (~9000): reclaims dead pad space, never fires while scrolling
|
||||
static const int PAD_THRESHOLD = 3000;
|
||||
static gboolean _in_redraw = FALSE;
|
||||
|
||||
static void
|
||||
@@ -2172,10 +2172,9 @@ win_redraw(ProfWin* window)
|
||||
unsigned int size = buffer_size(window->layout->buffer);
|
||||
_in_redraw = TRUE;
|
||||
|
||||
// size the pad to fit the whole buffer (plus headroom) and erase it
|
||||
// shrink pad back to minimum size and erase it
|
||||
int cols = getmaxx(window->layout->win);
|
||||
int needed = window->layout->buffer->lines + 100;
|
||||
wresize(window->layout->win, MAX(needed, PAD_MIN_HEIGHT), cols);
|
||||
wresize(window->layout->win, PAD_MIN_HEIGHT, cols);
|
||||
werase(window->layout->win);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#ifndef XMPP_BLOCKING_H
|
||||
#define XMPP_BLOCKING_H
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
void blocking_request(void);
|
||||
int blocked_set_handler(xmpp_stanza_t* stanza);
|
||||
int reporting_set_handler(xmpp_stanza_t* stanza);
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#ifndef XMPP_IQ_H
|
||||
#define XMPP_IQ_H
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
typedef int (*ProfIqCallback)(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
typedef void (*ProfIqFreeCallback)(void* userdata);
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
/*!
|
||||
* \page OX OX Implementation
|
||||
*
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
#ifndef XMPP_ROSTER_H
|
||||
#define XMPP_ROSTER_H
|
||||
|
||||
#include "glib.h"
|
||||
#include <strophe.h>
|
||||
|
||||
void roster_request(void);
|
||||
void roster_set_handler(xmpp_stanza_t* const stanza);
|
||||
void roster_result_handler(xmpp_stanza_t* const stanza);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include "ui/win_types.h"
|
||||
#include "xmpp/vcard.h"
|
||||
#include <strophe.h>
|
||||
|
||||
vCard* vcard_new();
|
||||
void vcard_free(vCard* vcard);
|
||||
|
||||
Reference in New Issue
Block a user