From fc75fb4eae441db5582b63b6bc00aecbe75f2c24 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 4 Apr 2019 11:43:19 +0100 Subject: [PATCH 1/7] purple: add defer_joins, use_matrix_alias and name_with_tag options (Most of these changes are aimed at making matrix not a pain to use) - The `defer_joins` option on prpl accounts waits for users to be added to a prpl conversation before adding the bitlbee user, in the hope of being able to get some chat name/alias metadata before doing so. - (To that end, the name hint for rooms is now updated when users are added.) - The `name_with_tag` options prefixes the account tag to the name hint for prpl accounts, in order to namespace prpl channels somewhat. - The `use_matrix_alias` option is specialized for the purple-matrix plugin, and makes the name hint use the `matrix_alias` data item of the prpl conversation, instead of the title. --- bitlbee.h | 2 +- protocols/purple/purple.c | 44 ++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/bitlbee.h b/bitlbee.h index 17ab29797..1cbcdc23d 100644 --- a/bitlbee.h +++ b/bitlbee.h @@ -121,7 +121,7 @@ extern "C" { #define CONTROL_TOPIC "Welcome to the control channel. Type \2help\2 for help information." #define IRCD_INFO PACKAGE " " -#define MAX_NICK_LENGTH 24 +#define MAX_NICK_LENGTH 80 #define HELP_FILE VARDIR "help.txt" #define CONF_FILE_DEF ETCDIR "bitlbee.conf" diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index d07892d3d..6588f8216 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -284,6 +284,15 @@ static void purple_init(account_t *acc) s = set_add(&acc->set, "display_name", NULL, set_eval_display_name, acc); s->flags |= ACC_SET_ONLINE_ONLY; + s = set_add(&acc->set, "defer_joins", "false", set_eval_bool, acc); + s->flags |= ACC_SET_OFFLINE_ONLY; + + s = set_add(&acc->set, "use_matrix_alias", "false", set_eval_bool, acc); + s->flags |= ACC_SET_OFFLINE_ONLY; + + s = set_add(&acc->set, "name_with_tag", "false", set_eval_bool, acc); + s->flags |= ACC_SET_OFFLINE_ONLY; + if (pi->options & OPT_PROTO_MAIL_CHECK) { s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; @@ -1107,6 +1116,24 @@ static PurpleBlistUiOps bee_blist_uiops = prplcb_blist_remove, /* remove */ }; +void purple_hint_chat_names(struct groupchat *gc, PurpleConversation *conv) { + char *hint = NULL; + if (conv->title != NULL) { + hint = conv->title; + } + if (set_getbool(&(gc->ic->acc->set), "use_matrix_alias") && purple_conversation_get_data(conv, "matrix_alias") != NULL) { + hint = (char *) purple_conversation_get_data(conv, "matrix_alias"); + } + if (set_getbool(&(gc->ic->acc->set), "name_with_tag")) { + char tagged_name[128]; + char *tag = set_getstr(&(gc->ic->acc->set), "tag"); + g_snprintf(tagged_name, sizeof(tagged_name), "%s-%s", tag, hint); + imcb_chat_name_hint(gc, tagged_name); + } + else { + imcb_chat_name_hint(gc, conv->title); + } +} void prplcb_conv_new(PurpleConversation *conv) { if (conv->type == PURPLE_CONV_TYPE_CHAT) { @@ -1117,9 +1144,7 @@ void prplcb_conv_new(PurpleConversation *conv) if (!gc) { gc = imcb_chat_new(ic, conv->name); - if (conv->title != NULL) { - imcb_chat_name_hint(gc, conv->title); - } + purple_hint_chat_names(gc, conv); } /* don't set the topic if it's just the name */ @@ -1133,7 +1158,12 @@ void prplcb_conv_new(PurpleConversation *conv) /* libpurple brokenness: Whatever. Show that we join right away, there's no clear "This is you!" signaling in _add_users so don't even try. */ - imcb_chat_add_buddy(gc, gc->ic->acc->user); + if (!set_getbool(&(ic->acc->set), "defer_joins")) { + imcb_chat_add_buddy(gc, gc->ic->acc->user); + } + else { + imcb_log(gc->ic, "Deferring join to %s", conv->name); + } } } @@ -1154,6 +1184,10 @@ void prplcb_conv_add_users(PurpleConversation *conv, GList *cbuddies, gboolean n imcb_chat_add_buddy(gc, pcb->name); } + purple_hint_chat_names(gc, conv); + if (!gc->joined) { + imcb_chat_add_buddy(gc, gc->ic->acc->user); + } } void prplcb_conv_del_users(PurpleConversation *conv, GList *cbuddies) @@ -1171,7 +1205,7 @@ static void handle_conv_msg(PurpleConversation *conv, const char *who, const cha { struct im_connection *ic = purple_ic_by_pa(conv->account); struct groupchat *gc = conv->ui_data; - char *message = g_strdup(message_); + char *message = purple_unescape_html(message_); PurpleBuddy *buddy; buddy = purple_find_buddy(conv->account, who); From 51a6eec96bad2428fa3f18e993beee5ad9c77814 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 4 Apr 2019 13:13:22 +0100 Subject: [PATCH 2/7] address review commentary --- protocols/purple/purple.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index 6588f8216..2ba964ce9 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -285,12 +285,13 @@ static void purple_init(account_t *acc) s->flags |= ACC_SET_ONLINE_ONLY; s = set_add(&acc->set, "defer_joins", "false", set_eval_bool, acc); - s->flags |= ACC_SET_OFFLINE_ONLY; - s = set_add(&acc->set, "use_matrix_alias", "false", set_eval_bool, acc); - s->flags |= ACC_SET_OFFLINE_ONLY; + if (strcmp(prpl->info->name, "matrix") == 0) { + s = set_add(&acc->set, "use_matrix_alias", "false", set_eval_bool, acc); + s->flags |= ACC_SET_OFFLINE_ONLY; + } - s = set_add(&acc->set, "name_with_tag", "false", set_eval_bool, acc); + s = set_add(&acc->set, "chat_name_with_tag", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; if (pi->options & OPT_PROTO_MAIL_CHECK) { @@ -1125,13 +1126,12 @@ void purple_hint_chat_names(struct groupchat *gc, PurpleConversation *conv) { hint = (char *) purple_conversation_get_data(conv, "matrix_alias"); } if (set_getbool(&(gc->ic->acc->set), "name_with_tag")) { - char tagged_name[128]; char *tag = set_getstr(&(gc->ic->acc->set), "tag"); - g_snprintf(tagged_name, sizeof(tagged_name), "%s-%s", tag, hint); + char *tagged_name = g_strdup_printf("%s-%s", tag, hint); imcb_chat_name_hint(gc, tagged_name); - } - else { - imcb_chat_name_hint(gc, conv->title); + g_free(tagged_name); + } else { + imcb_chat_name_hint(gc, hint); } } void prplcb_conv_new(PurpleConversation *conv) @@ -1161,9 +1161,6 @@ void prplcb_conv_new(PurpleConversation *conv) if (!set_getbool(&(ic->acc->set), "defer_joins")) { imcb_chat_add_buddy(gc, gc->ic->acc->user); } - else { - imcb_log(gc->ic, "Deferring join to %s", conv->name); - } } } From 3547d281861e9262529a7bfd552d20bc963b1860 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 4 Apr 2019 13:15:38 +0100 Subject: [PATCH 3/7] reset max nick length --- bitlbee.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitlbee.h b/bitlbee.h index 1cbcdc23d..17ab29797 100644 --- a/bitlbee.h +++ b/bitlbee.h @@ -121,7 +121,7 @@ extern "C" { #define CONTROL_TOPIC "Welcome to the control channel. Type \2help\2 for help information." #define IRCD_INFO PACKAGE " " -#define MAX_NICK_LENGTH 80 +#define MAX_NICK_LENGTH 24 #define HELP_FILE VARDIR "help.txt" #define CONF_FILE_DEF ETCDIR "bitlbee.conf" From f427c4e070d2e162c4dc85863165d74e0e792ed4 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 4 Apr 2019 13:24:21 +0100 Subject: [PATCH 4/7] add helpstrings --- doc/user-guide/commands.xml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index f4fb2eb04..11fd34316 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -999,6 +999,40 @@ + + + false + + + + Only relevant for purple-matrix. If enabled, uses the Matrix canonical alias (or one of the room aliases, if not present) as the name of Matrix groupchats, instead of the room's title. This can help for Matrix rooms with frequently-changed titles. + + + + + + + false + + + + If this setting is enabled, the names of groupchats generated for this account will have "TAG-" prepended to them, where TAG is the tag of the account. This can help keep groupchats separated when using libpurple. + + + + + + + false + + + + This setting controls whether to wait for users to be added to groupchats before joining them. This can help make the channel names generated by some libpurple protocols nicer (e.g. when using purple-matrix). + + + + + false From 0809d99d6a7cc0bbe1511649792ca5d84a74f382 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 4 Apr 2019 13:26:59 +0100 Subject: [PATCH 5/7] rename chat_name_with_tag, duh --- protocols/purple/purple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index 2ba964ce9..cb14f906e 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -1125,7 +1125,7 @@ void purple_hint_chat_names(struct groupchat *gc, PurpleConversation *conv) { if (set_getbool(&(gc->ic->acc->set), "use_matrix_alias") && purple_conversation_get_data(conv, "matrix_alias") != NULL) { hint = (char *) purple_conversation_get_data(conv, "matrix_alias"); } - if (set_getbool(&(gc->ic->acc->set), "name_with_tag")) { + if (set_getbool(&(gc->ic->acc->set), "chat_name_with_tag")) { char *tag = set_getstr(&(gc->ic->acc->set), "tag"); char *tagged_name = g_strdup_printf("%s-%s", tag, hint); imcb_chat_name_hint(gc, tagged_name); From 0350b3d245f79ca76a0ba07d696beac71c3653d0 Mon Sep 17 00:00:00 2001 From: eta Date: Thu, 4 Apr 2019 13:43:26 +0100 Subject: [PATCH 6/7] prpl name is 'Matrix' --- protocols/purple/purple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index cb14f906e..a673cae96 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -286,7 +286,7 @@ static void purple_init(account_t *acc) s = set_add(&acc->set, "defer_joins", "false", set_eval_bool, acc); - if (strcmp(prpl->info->name, "matrix") == 0) { + if (strcmp(prpl->info->name, "Matrix") == 0) { s = set_add(&acc->set, "use_matrix_alias", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; } From 609aa5a6a032842678f5bc10c43c3b288b91d86b Mon Sep 17 00:00:00 2001 From: eta Date: Sun, 28 Jul 2019 05:48:32 +0100 Subject: [PATCH 7/7] purple: add option to automatically mark new messages as read - The new `mark_read` option controls whether messages are marked as read upon reception by bitlbee. - Not all libpurple prpls actually support this, but the ones that do (e.g. slack-libpurple) seem to be watching out for a conversation update of type PURPLE_CONV_UPDATE_UNSEEN, so we send that on message reception if the option is enabled. - Additionally, some (like purple-facebook) check for has_focus, so we always return TRUE for that if mark_read is enabled. --- doc/user-guide/commands.xml | 10 ++++++++++ protocols/purple/purple.c | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/user-guide/commands.xml b/doc/user-guide/commands.xml index 11fd34316..5d6779028 100644 --- a/doc/user-guide/commands.xml +++ b/doc/user-guide/commands.xml @@ -1022,6 +1022,16 @@ + + false + + + + If enabled, automatically marks every message received as read. Useful to avoid duplicate messages when the connection drops, but may annoy your friends. + + + + false diff --git a/protocols/purple/purple.c b/protocols/purple/purple.c index a673cae96..5e66e1ac3 100644 --- a/protocols/purple/purple.c +++ b/protocols/purple/purple.c @@ -285,6 +285,7 @@ static void purple_init(account_t *acc) s->flags |= ACC_SET_ONLINE_ONLY; s = set_add(&acc->set, "defer_joins", "false", set_eval_bool, acc); + s = set_add(&acc->set, "mark_read", "false", set_eval_bool, acc); if (strcmp(prpl->info->name, "Matrix") == 0) { s = set_add(&acc->set, "use_matrix_alias", "false", set_eval_bool, acc); @@ -1216,9 +1217,18 @@ static void handle_conv_msg(PurpleConversation *conv, const char *who, const cha imcb_chat_msg(gc, who, message, bee_flags, mtime); } + if (set_getbool(&(ic->acc->set), "mark_read")) { + purple_conversation_update(conv, PURPLE_CONV_UPDATE_UNSEEN); + } + g_free(message); } +/* Handles has_focus - this needs to return TRUE if we want marking things as read to work for some prpls */ +static gboolean prplcb_conv_has_focus(PurpleConversation *conv) { + struct im_connection *ic = purple_ic_by_pa(conv->account); + return set_getbool(&(ic->acc->set), "mark_read"); +} /* Handles write_im and write_chat. Removes echoes of locally sent messages. * * PURPLE_MESSAGE_DELAYED is used for chat backlogs - if a message has both @@ -1284,7 +1294,7 @@ static PurpleConversationUiOps bee_conv_uiops = prplcb_conv_del_users, /* chat_remove_users */ NULL, /* chat_update_user */ NULL, /* present */ - NULL, /* has_focus */ + prplcb_conv_has_focus, /* has_focus */ NULL, /* custom_smiley_add */ NULL, /* custom_smiley_write */ NULL, /* custom_smiley_close */