diff options
author | Michael Vetter <jubalh@iodoru.org> | 2021-05-12 13:31:20 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2021-05-12 13:31:20 +0200 |
commit | 722d07adf68438559aeaec1ed1ce22b12a21a187 (patch) | |
tree | c2263ad26a8fd48be3c5a657ac0be18dcc957255 /src/command | |
parent | 5906c4ade1b215ece95dbd85ea3bdd44fd508b8b (diff) | |
download | profani-tty-722d07adf68438559aeaec1ed1ce22b12a21a187.tar.gz |
Use direct messages instead of MUC-PMs for non-anon MUCs
In https://github.com/profanity-im/profanity/issues/1070 we have: `OMEMO encryption for MUC PM (OMEMO MUCs are not anonymous, so we should start a regular 1:1 in this case instead of MUC PM. A discussion started to make this a general feature #1531)` In https://github.com/profanity-im/profanity/issues/1531 we have the general issue to start regular 1:1 messages instead of MUC PMs if the room is non-anonymous. This is like suggested in https://docs.modernxmpp.org/client/groupchat/.
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_funcs.c | 86 |
1 files changed, 51 insertions, 35 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index ab212975..6c3f3708 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -2108,6 +2108,33 @@ cmd_who(ProfWin* window, const char* const command, gchar** args) return TRUE; } +static void +_cmd_msg_chatwin(const char* const barejid, const char* const msg) +{ + ProfChatWin* chatwin = wins_get_chat(barejid); + if (!chatwin) { + // NOTE: This will also start the new OMEMO session and send a MAM request. + chatwin = chatwin_new(barejid); + } + ui_focus_win((ProfWin*)chatwin); + + if (msg) { + // NOTE: In case the message is OMEMO encrypted, we can't be sure + // whether the key bundles of the recipient have already been + // received. In the case that *no* bundles have been received yet, + // the message won't be sent, and an error is shown to the user. + // Other cases are not handled here. + cl_ev_send_msg(chatwin, msg, NULL); + } else { +#ifdef HAVE_LIBOTR + // Start the OTR session after this (i.e. the first) message was sent + if (otr_is_secure(barejid)) { + chatwin_otr_secured(chatwin, otr_is_trusted(barejid)); + } +#endif // HAVE_LIBOTR + } +} + gboolean cmd_msg(ProfWin* window, const char* const command, gchar** args) { @@ -2125,22 +2152,32 @@ cmd_msg(ProfWin* window, const char* const command, gchar** args) if (window->type == WIN_MUC) { ProfMucWin* mucwin = (ProfMucWin*)window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); - if (muc_roster_contains_nick(mucwin->roomjid, usr)) { - GString* full_jid = g_string_new(mucwin->roomjid); - g_string_append(full_jid, "/"); - g_string_append(full_jid, usr); - ProfPrivateWin* privwin = wins_get_private(full_jid->str); - if (!privwin) { - privwin = (ProfPrivateWin*)wins_new_private(full_jid->str); - } - ui_focus_win((ProfWin*)privwin); + Occupant* occupant = muc_roster_item(mucwin->roomjid, usr); + if (occupant) { + // in case of non-anon muc send regular chatmessage + if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) { + Jid* jidp = jid_create(occupant->jid); + _cmd_msg_chatwin(jidp->barejid, msg); + jid_destroy(jidp); + } else { + // otherwise send mucpm + GString* full_jid = g_string_new(mucwin->roomjid); + g_string_append(full_jid, "/"); + g_string_append(full_jid, usr); + + ProfPrivateWin* privwin = wins_get_private(full_jid->str); + if (!privwin) { + privwin = (ProfPrivateWin*)wins_new_private(full_jid->str); + } + ui_focus_win((ProfWin*)privwin); - if (msg) { - cl_ev_send_priv_msg(privwin, msg, NULL); - } + if (msg) { + cl_ev_send_priv_msg(privwin, msg, NULL); + } - g_string_free(full_jid, TRUE); + g_string_free(full_jid, TRUE); + } } else { win_println(window, THEME_DEFAULT, "-", "No such participant \"%s\" in room.", usr); @@ -2155,28 +2192,7 @@ cmd_msg(ProfWin* window, const char* const command, gchar** args) barejid = usr; } - ProfChatWin* chatwin = wins_get_chat(barejid); - if (!chatwin) { - // NOTE: This will also start the new OMEMO session and send a MAM request. - chatwin = chatwin_new(barejid); - } - ui_focus_win((ProfWin*)chatwin); - - if (msg) { - // NOTE: In case the message is OMEMO encrypted, we can't be sure - // whether the key bundles of the recipient have already been - // received. In the case that *no* bundles have been received yet, - // the message won't be sent, and an error is shown to the user. - // Other cases are not handled here. - cl_ev_send_msg(chatwin, msg, NULL); - } else { -#ifdef HAVE_LIBOTR - // Start the OTR session after this (i.e. the first) message was sent - if (otr_is_secure(barejid)) { - chatwin_otr_secured(chatwin, otr_is_trusted(barejid)); - } -#endif // HAVE_LIBOTR - } + _cmd_msg_chatwin(barejid, msg); return TRUE; } |