irc: send typing status as TAGMSG to other users

This commit is contained in:
Sébastien Helleu 2021-06-28 20:27:44 +02:00
parent dccf605e66
commit b108e97085
6 changed files with 108 additions and 0 deletions

View File

@ -40,6 +40,9 @@
#include "irc-input.h" #include "irc-input.h"
char *irc_channel_typing_status_string[IRC_CHANNEL_NUM_TYPING_STATUSES] =
{ "off", "typing", "paused", "done" };
/* default CHANTYPES */ /* default CHANTYPES */
char *irc_channel_default_chantypes = "#&"; char *irc_channel_default_chantypes = "#&";
@ -508,6 +511,8 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
irc_modelist_new (new_channel, ptr_chanmode[0]); irc_modelist_new (new_channel, ptr_chanmode[0]);
} }
new_channel->join_smart_filtered = NULL; new_channel->join_smart_filtered = NULL;
new_channel->typing_status = IRC_CHANNEL_TYPING_STATUS_OFF;
new_channel->typing_status_sent = 0;
new_channel->buffer = ptr_buffer; new_channel->buffer = ptr_buffer;
new_channel->buffer_as_string = NULL; new_channel->buffer_as_string = NULL;
@ -1584,6 +1589,8 @@ irc_channel_hdata_channel_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_irc_channel, modelists, POINTER, 0, NULL, "irc_modelist"); WEECHAT_HDATA_VAR(struct t_irc_channel, modelists, POINTER, 0, NULL, "irc_modelist");
WEECHAT_HDATA_VAR(struct t_irc_channel, last_modelist, POINTER, 0, NULL, "irc_modelist"); WEECHAT_HDATA_VAR(struct t_irc_channel, last_modelist, POINTER, 0, NULL, "irc_modelist");
WEECHAT_HDATA_VAR(struct t_irc_channel, join_smart_filtered, HASHTABLE, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, join_smart_filtered, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, typing_status, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, typing_status_sent, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, buffer, POINTER, 0, NULL, "buffer"); WEECHAT_HDATA_VAR(struct t_irc_channel, buffer, POINTER, 0, NULL, "buffer");
WEECHAT_HDATA_VAR(struct t_irc_channel, buffer_as_string, STRING, 0, NULL, NULL); WEECHAT_HDATA_VAR(struct t_irc_channel, buffer_as_string, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, prev_channel, POINTER, 0, NULL, hdata_name); WEECHAT_HDATA_VAR(struct t_irc_channel, prev_channel, POINTER, 0, NULL, hdata_name);
@ -1774,6 +1781,8 @@ irc_channel_print_log (struct t_irc_channel *channel)
channel->join_smart_filtered, channel->join_smart_filtered,
weechat_hashtable_get_string (channel->join_smart_filtered, weechat_hashtable_get_string (channel->join_smart_filtered,
"keys_values")); "keys_values"));
weechat_log_printf (" typing_status. . . . . . : %d", channel->typing_status);
weechat_log_printf (" typing_status_sent . . . : %lld", (long long)channel->typing_status_sent);
weechat_log_printf (" buffer . . . . . . . . . : 0x%lx", channel->buffer); weechat_log_printf (" buffer . . . . . . . . . : 0x%lx", channel->buffer);
weechat_log_printf (" buffer_as_string . . . . : '%s'", channel->buffer_as_string); weechat_log_printf (" buffer_as_string . . . . : '%s'", channel->buffer_as_string);
weechat_log_printf (" prev_channel . . . . . . : 0x%lx", channel->prev_channel); weechat_log_printf (" prev_channel . . . . . . : 0x%lx", channel->prev_channel);

View File

@ -32,6 +32,16 @@
struct t_irc_server; struct t_irc_server;
struct t_irc_modelist; struct t_irc_modelist;
enum t_irc_channel_typing_status
{
IRC_CHANNEL_TYPING_STATUS_OFF = 0,
IRC_CHANNEL_TYPING_STATUS_TYPING,
IRC_CHANNEL_TYPING_STATUS_PAUSED,
IRC_CHANNEL_TYPING_STATUS_DONE,
/* number of channel typing statuses */
IRC_CHANNEL_NUM_TYPING_STATUSES,
};
struct t_irc_channel_speaking struct t_irc_channel_speaking
{ {
char *nick; /* nick speaking */ char *nick; /* nick speaking */
@ -73,12 +83,15 @@ struct t_irc_channel
struct t_irc_modelist *modelists; /* modelists in the channel */ struct t_irc_modelist *modelists; /* modelists in the channel */
struct t_irc_modelist *last_modelist; /* last modelist in the channel */ struct t_irc_modelist *last_modelist; /* last modelist in the channel */
struct t_hashtable *join_smart_filtered; /* smart filtered joins */ struct t_hashtable *join_smart_filtered; /* smart filtered joins */
int typing_status; /* typing status */
time_t typing_status_sent; /* last time typing status was sent */
struct t_gui_buffer *buffer; /* buffer allocated for channel */ struct t_gui_buffer *buffer; /* buffer allocated for channel */
char *buffer_as_string; /* used to return buffer info */ char *buffer_as_string; /* used to return buffer info */
struct t_irc_channel *prev_channel; /* link to previous channel */ struct t_irc_channel *prev_channel; /* link to previous channel */
struct t_irc_channel *next_channel; /* link to next channel */ struct t_irc_channel *next_channel; /* link to next channel */
}; };
extern char *irc_channel_typing_status_string[IRC_CHANNEL_NUM_TYPING_STATUSES];
extern char *irc_channel_default_chantypes; extern char *irc_channel_default_chantypes;
extern int irc_channel_valid (struct t_irc_server *server, extern int irc_channel_valid (struct t_irc_server *server,

View File

@ -98,6 +98,7 @@ struct t_config_option *irc_config_look_part_closes_buffer;
struct t_config_option *irc_config_look_pv_buffer; struct t_config_option *irc_config_look_pv_buffer;
struct t_config_option *irc_config_look_pv_tags; struct t_config_option *irc_config_look_pv_tags;
struct t_config_option *irc_config_look_raw_messages; struct t_config_option *irc_config_look_raw_messages;
struct t_config_option *irc_config_look_send_typing_status;
struct t_config_option *irc_config_look_server_buffer; struct t_config_option *irc_config_look_server_buffer;
struct t_config_option *irc_config_look_smart_filter; struct t_config_option *irc_config_look_smart_filter;
struct t_config_option *irc_config_look_smart_filter_account; struct t_config_option *irc_config_look_smart_filter_account;
@ -3115,6 +3116,13 @@ irc_config_init ()
"closed (messages will be displayed when opening raw data buffer)"), "closed (messages will be displayed when opening raw data buffer)"),
NULL, 0, 65535, "256", NULL, 0, NULL, 0, 65535, "256", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
irc_config_look_send_typing_status = weechat_config_new_option (
irc_config_file, ptr_section,
"send_typing_status", "boolean",
N_("send typing status to channels (capability \"message-tags\" must "
"be enabled)"),
NULL, 0, 0, "off", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
irc_config_look_server_buffer = weechat_config_new_option ( irc_config_look_server_buffer = weechat_config_new_option (
irc_config_file, ptr_section, irc_config_file, ptr_section,
"server_buffer", "integer", "server_buffer", "integer",

View File

@ -138,6 +138,7 @@ extern struct t_config_option *irc_config_look_part_closes_buffer;
extern struct t_config_option *irc_config_look_pv_buffer; extern struct t_config_option *irc_config_look_pv_buffer;
extern struct t_config_option *irc_config_look_pv_tags; extern struct t_config_option *irc_config_look_pv_tags;
extern struct t_config_option *irc_config_look_raw_messages; extern struct t_config_option *irc_config_look_raw_messages;
extern struct t_config_option *irc_config_look_send_typing_status;
extern struct t_config_option *irc_config_look_server_buffer; extern struct t_config_option *irc_config_look_server_buffer;
extern struct t_config_option *irc_config_look_smart_filter; extern struct t_config_option *irc_config_look_smart_filter;
extern struct t_config_option *irc_config_look_smart_filter_account; extern struct t_config_option *irc_config_look_smart_filter_account;

View File

@ -3734,6 +3734,34 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
ptr_redirect = ptr_next_redirect; ptr_redirect = ptr_next_redirect;
} }
/* send typing status on channels */
if (weechat_config_boolean (irc_config_look_send_typing_status))
{
for (ptr_channel = ptr_server->channels; ptr_channel;
ptr_channel = ptr_channel->next_channel)
{
if ((ptr_channel->typing_status != IRC_CHANNEL_TYPING_STATUS_OFF)
&& (ptr_channel->typing_status_sent + 3 < current_time))
{
irc_server_sendf (
ptr_server,
IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL,
"@+typing=%s TAGMSG %s",
irc_channel_typing_status_string[ptr_channel->typing_status],
ptr_channel->name);
if (ptr_channel->typing_status == IRC_CHANNEL_TYPING_STATUS_TYPING)
{
ptr_channel->typing_status_sent = current_time;
}
else
{
ptr_channel->typing_status = IRC_CHANNEL_TYPING_STATUS_OFF;
ptr_channel->typing_status_sent = 0;
}
}
}
}
/* purge some data (every 10 minutes) */ /* purge some data (every 10 minutes) */
if (current_time > ptr_server->last_data_purge + (60 * 10)) if (current_time > ptr_server->last_data_purge + (60 * 10))
{ {

View File

@ -159,6 +159,53 @@ irc_signal_upgrade_cb (const void *pointer, void *data,
return WEECHAT_RC_OK; return WEECHAT_RC_OK;
} }
/*
* Callback for signals "typing_*".
*/
int
irc_signal_typing_cb (const void *pointer, void *data,
const char *signal, const char *type_data,
void *signal_data)
{
struct t_irc_server *ptr_server;
struct t_irc_channel *ptr_channel;
int new_status;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) signal;
(void) type_data;
/* search server/channel with buffer */
irc_buffer_get_server_and_channel (signal_data, &ptr_server, &ptr_channel);
if (!ptr_server || !ptr_channel)
return WEECHAT_RC_OK;
/* typing works only if capability "message-tags" is enabled */
if (!weechat_hashtable_has_key (ptr_server->cap_list, "message-tags"))
return WEECHAT_RC_OK;
new_status = -1;
if (strcmp (signal, "typing_active") == 0)
new_status = IRC_CHANNEL_TYPING_STATUS_TYPING;
else if (strcmp (signal, "typing_paused") == 0)
new_status = IRC_CHANNEL_TYPING_STATUS_PAUSED;
else if (strcmp (signal, "typing_cleared") == 0)
new_status = IRC_CHANNEL_TYPING_STATUS_DONE;
else if (strcmp (signal, "typing_sent") == 0)
new_status = IRC_CHANNEL_TYPING_STATUS_OFF;
if ((new_status >= 0) && (new_status != ptr_channel->typing_status))
{
ptr_channel->typing_status = new_status;
ptr_channel->typing_status_sent = 0;
}
return WEECHAT_RC_OK;
}
/* /*
* Initializes IRC plugin. * Initializes IRC plugin.
*/ */
@ -200,6 +247,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
&irc_server_xfer_send_accept_resume_cb, NULL, NULL); &irc_server_xfer_send_accept_resume_cb, NULL, NULL);
weechat_hook_signal ("irc_input_send", weechat_hook_signal ("irc_input_send",
&irc_input_send_cb, NULL, NULL); &irc_input_send_cb, NULL, NULL);
weechat_hook_signal ("typing_*",
&irc_signal_typing_cb, NULL, NULL);
/* hook hsignals for redirection */ /* hook hsignals for redirection */
weechat_hook_hsignal ("irc_redirect_pattern", weechat_hook_hsignal ("irc_redirect_pattern",