Fix IRCv3 typing notifications

This commit is contained in:
2026-09-26 06:10:20 -06:00
parent 2cf1f7e833
commit 222b4868f5
3 changed files with 36 additions and 20 deletions
+8 -6
View File
@@ -2826,6 +2826,7 @@ static gboolean
client_tag_allowed (server *serv, const char *tag) client_tag_allowed (server *serv, const char *tag)
{ {
char **deny; char **deny;
gboolean blocked = FALSE;
int i; int i;
if (!serv->have_message_tags) if (!serv->have_message_tags)
@@ -2837,15 +2838,16 @@ client_tag_allowed (server *serv, const char *tag)
deny = g_strsplit (serv->clienttagdeny, ",", 0); deny = g_strsplit (serv->clienttagdeny, ",", 0);
for (i = 0; deny[i]; i++) for (i = 0; deny[i]; i++)
{ {
if (!strcmp (deny[i], "*") || !strcmp (deny[i], tag) || (deny[i][0] == '+' && !strcmp (deny[i] + 1, tag))) if (!strcmp (deny[i], "*"))
{ blocked = TRUE;
g_strfreev (deny); else if (deny[i][0] == '-' && !strcmp (deny[i] + 1, tag))
return FALSE; blocked = FALSE;
} else if (!strcmp (deny[i], tag) || (deny[i][0] == '+' && !strcmp (deny[i] + 1, tag)))
blocked = TRUE;
} }
g_strfreev (deny); g_strfreev (deny);
return TRUE; return !blocked;
} }
static char * static char *
+1
View File
@@ -450,6 +450,7 @@ typedef struct session
int mode_timeout_tag; int mode_timeout_tag;
int typing_timeout_tag; int typing_timeout_tag;
int typing_status; int typing_status;
gint64 typing_last_sent;
int typing_animation_tag; int typing_animation_tag;
int typing_animation_frame; int typing_animation_frame;
+27 -14
View File
@@ -778,10 +778,13 @@ mg_inputbox_focus (GtkWidget *widget, GdkEventFocus *event, session_gui *gui)
} }
#define TYPING_THROTTLE_USEC (3 * G_USEC_PER_SEC)
static gboolean static gboolean
mg_client_tag_allowed (server *serv, const char *tag) mg_client_tag_allowed (server *serv, const char *tag)
{ {
char **deny; char **deny;
gboolean blocked = FALSE;
int i; int i;
if (!serv->have_message_tags) if (!serv->have_message_tags)
@@ -793,30 +796,42 @@ mg_client_tag_allowed (server *serv, const char *tag)
deny = g_strsplit (serv->clienttagdeny, ",", 0); deny = g_strsplit (serv->clienttagdeny, ",", 0);
for (i = 0; deny[i]; i++) for (i = 0; deny[i]; i++)
{ {
if (!strcmp (deny[i], "*") || !strcmp (deny[i], tag) || (deny[i][0] == '+' && !strcmp (deny[i] + 1, tag))) if (!strcmp (deny[i], "*"))
{ blocked = TRUE;
g_strfreev (deny); else if (deny[i][0] == '-' && !strcmp (deny[i] + 1, tag))
return FALSE; blocked = FALSE;
} else if (!strcmp (deny[i], tag) || (deny[i][0] == '+' && !strcmp (deny[i] + 1, tag)))
blocked = TRUE;
} }
g_strfreev (deny); g_strfreev (deny);
return TRUE; return !blocked;
} }
static void static gboolean
mg_typing_can_send (session *sess)
{
gint64 now = g_get_monotonic_time ();
return sess->typing_last_sent == 0 ||
now - sess->typing_last_sent >= TYPING_THROTTLE_USEC;
}
static gboolean
mg_send_typing (session *sess, const char *state) mg_send_typing (session *sess, const char *state)
{ {
char tags[32]; char tags[32];
if (!sess || !sess->server->connected || !mg_client_tag_allowed (sess->server, "typing") || !sess->channel[0]) if (!sess || !sess->server->connected || !mg_client_tag_allowed (sess->server, "typing") || !sess->channel[0])
return; return FALSE;
if (sess->type != SESS_CHANNEL && sess->type != SESS_DIALOG) if (sess->type != SESS_CHANNEL && sess->type != SESS_DIALOG)
return; return FALSE;
g_snprintf (tags, sizeof (tags), "+typing=%s", state); g_snprintf (tags, sizeof (tags), "+typing=%s", state);
sess->server->p_tagmsg (sess->server, tags, sess->channel); sess->server->p_tagmsg (sess->server, tags, sess->channel);
sess->typing_last_sent = g_get_monotonic_time ();
return TRUE;
} }
static int static int
@@ -845,17 +860,15 @@ mg_typing_update (session *sess, const char *text)
if (!text || !*text || text[0] == prefs.hex_input_command_char[0]) if (!text || !*text || text[0] == prefs.hex_input_command_char[0])
{ {
if (sess->typing_status) if (sess->typing_status && mg_typing_can_send (sess))
mg_send_typing (sess, "done"); mg_send_typing (sess, "done");
sess->typing_status = 0; sess->typing_status = 0;
return; return;
} }
if (sess->typing_status != 1) if (mg_typing_can_send (sess))
{
mg_send_typing (sess, "active"); mg_send_typing (sess, "active");
sess->typing_status = 1; sess->typing_status = 1;
}
sess->typing_timeout_tag = fe_timeout_add_seconds (6, mg_typing_pause_cb, sess); sess->typing_timeout_tag = fe_timeout_add_seconds (6, mg_typing_pause_cb, sess);
} }