diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2021-06-28 20:27:44 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2021-07-04 13:27:33 +0200 |
commit | b108e97085409c1bad5fa0833d805f47a032f5b2 (patch) | |
tree | 170cafc4ca97a7f72ea9f964294ea126e9e04e9d | |
parent | dccf605e6647f8ae1a075558384a521843760ed1 (diff) | |
download | weechat-b108e97085409c1bad5fa0833d805f47a032f5b2.zip |
irc: send typing status as TAGMSG to other users
-rw-r--r-- | src/plugins/irc/irc-channel.c | 9 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 13 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.h | 1 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 28 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 49 |
6 files changed, 108 insertions, 0 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index b81f87f73..5dfa4163c 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -40,6 +40,9 @@ #include "irc-input.h" +char *irc_channel_typing_status_string[IRC_CHANNEL_NUM_TYPING_STATUSES] = +{ "off", "typing", "paused", "done" }; + /* 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]); } 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_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, 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, 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_as_string, STRING, 0, NULL, NULL); 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, weechat_hashtable_get_string (channel->join_smart_filtered, "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_as_string . . . . : '%s'", channel->buffer_as_string); weechat_log_printf (" prev_channel . . . . . . : 0x%lx", channel->prev_channel); diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index 101703c24..0094be4a8 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -32,6 +32,16 @@ struct t_irc_server; 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 { 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 *last_modelist; /* last modelist in the channel */ 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 */ char *buffer_as_string; /* used to return buffer info */ struct t_irc_channel *prev_channel; /* link to previous 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 int irc_channel_valid (struct t_irc_server *server, diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 8434041aa..f68df8d36 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -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_tags; 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_smart_filter; 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)"), NULL, 0, 65535, "256", NULL, 0, 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_file, ptr_section, "server_buffer", "integer", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 25c17319b..c21093b67 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -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_tags; 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_smart_filter; extern struct t_config_option *irc_config_look_smart_filter_account; diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 0312c99d9..6dcf5bb18 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -3734,6 +3734,34 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls) 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) */ if (current_time > ptr_server->last_data_purge + (60 * 10)) { diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 9c1a1a3db..e0029f1fd 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -160,6 +160,53 @@ irc_signal_upgrade_cb (const void *pointer, void *data, } /* + * 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. */ @@ -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); weechat_hook_signal ("irc_input_send", &irc_input_send_cb, NULL, NULL); + weechat_hook_signal ("typing_*", + &irc_signal_typing_cb, NULL, NULL); /* hook hsignals for redirection */ weechat_hook_hsignal ("irc_redirect_pattern", |