1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

OMEMO: Remove duplicate session initalisation

The function `omemo_start_session` was effectively called twice in the
`/msg` command: Once in `chatwin_new` and afterwards in `cmd_msg`. I've
removed the second call.
This commit is contained in:
Maximilian Wuttke 2021-03-29 02:47:35 +02:00
parent 1ec606540e
commit 9e0d0ed466
2 changed files with 20 additions and 18 deletions

View File

@ -2151,30 +2151,22 @@ cmd_msg(ProfWin* window, const char* const command, gchar** args)
ProfChatWin* chatwin = wins_get_chat(barejid); ProfChatWin* chatwin = wins_get_chat(barejid);
if (!chatwin) { if (!chatwin) {
// NOTE: This will also start the new OMEMO session
// and send a MAM request.
chatwin = chatwin_new(barejid); chatwin = chatwin_new(barejid);
} }
ui_focus_win((ProfWin*)chatwin); ui_focus_win((ProfWin*)chatwin);
#ifdef HAVE_OMEMO
gboolean is_otr_secure = FALSE;
#ifdef HAVE_LIBOTR
is_otr_secure = otr_is_secure(barejid);
#endif // HAVE_LIBOTR
if (omemo_automatic_start(barejid) && is_otr_secure) {
win_println(window, THEME_DEFAULT, "!", "Chat could be either OMEMO or OTR encrypted. Use '/omemo start %s' or '/otr start %s' to start a session.", usr, usr);
return TRUE;
} else if (omemo_automatic_start(barejid)) {
omemo_start_session(barejid);
chatwin->is_omemo = TRUE;
}
#endif // HAVE_OMEMO
if (msg) { if (msg) {
// FIXME [OMEMO] We can't be sure whether the
// bundles have already been receieved. Thus, it is
// possible (and probable) that the recipent can't
// encrypt the message.
cl_ev_send_msg(chatwin, msg, NULL); cl_ev_send_msg(chatwin, msg, NULL);
} else { } else {
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
// Start the OTR session after this (i.e. the
// first) message was sent
if (otr_is_secure(barejid)) { if (otr_is_secure(barejid)) {
chatwin_otr_secured(chatwin, otr_is_trusted(barejid)); chatwin_otr_secured(chatwin, otr_is_trusted(barejid));
} }

View File

@ -80,12 +80,22 @@ chatwin_new(const char* const barejid)
} }
} }
// We start a new OMEMO session if this contact has been configured accordingly.
// However, if OTR is *also* configured, ask the user to choose between OMEMO and OTR.
#ifdef HAVE_OMEMO #ifdef HAVE_OMEMO
if (omemo_automatic_start(barejid)) { gboolean is_otr_secure = FALSE;
#ifdef HAVE_LIBOTR
is_otr_secure = otr_is_secure(barejid);
#endif // HAVE_LIBOTR
if (omemo_automatic_start(barejid) && is_otr_secure) {
win_println(window, THEME_DEFAULT, "!", "This chat could be either OMEMO or OTR encrypted, but not both. "
"Use '/omemo start' or '/otr start' to select the encryption method.");
} else if (omemo_automatic_start(barejid)) {
// Start the OMEMO session
omemo_start_session(barejid); omemo_start_session(barejid);
chatwin->is_omemo = TRUE; chatwin->is_omemo = TRUE;
} }
#endif #endif // HAVE_OMEMO
if (prefs_get_boolean(PREF_MAM)) { if (prefs_get_boolean(PREF_MAM)) {
iq_mam_request(chatwin); iq_mam_request(chatwin);