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

Refactor cmd_omemo_start

Some code was duplicated/similar.
The parts about using a chatwin while being started from another window
(recipient provided) and being a chatwin were the same.

Like this it should be easier to read and less code.
This commit is contained in:
Michael Vetter 2019-06-07 21:11:11 +02:00
parent 2eb2bf3508
commit 9516324248

View File

@ -8060,6 +8060,8 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
ProfChatWin *chatwin = NULL;
// recipient supplied // recipient supplied
if (args[1]) { if (args[1]) {
char *contact = args[1]; char *contact = args[1];
@ -8068,12 +8070,19 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
barejid = contact; barejid = contact;
} }
ProfChatWin *chatwin = wins_get_chat(barejid); chatwin = wins_get_chat(barejid);
if (!chatwin) { if (!chatwin) {
chatwin = chatwin_new(barejid); chatwin = chatwin_new(barejid);
} }
ui_focus_win((ProfWin*)chatwin); ui_focus_win((ProfWin*)chatwin);
} else {
if (window->type == WIN_CHAT) {
chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
}
}
if (chatwin) {
if (chatwin->pgp_send) { if (chatwin->pgp_send) {
win_println((ProfWin*)chatwin, THEME_DEFAULT, '!', "You must disable PGP encryption before starting an OMEMO session."); win_println((ProfWin*)chatwin, THEME_DEFAULT, '!', "You must disable PGP encryption before starting an OMEMO session.");
return TRUE; return TRUE;
@ -8085,29 +8094,7 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
} }
if (chatwin->is_omemo) { if (chatwin->is_omemo) {
win_println((ProfWin*)chatwin, THEME_DEFAULT, '!', "You are already in an OMEMO session"); win_println((ProfWin*)chatwin, THEME_DEFAULT, '!', "You are already in an OMEMO session.");
return TRUE;
}
accounts_add_omemo_state(session_get_account_name(), barejid, TRUE);
omemo_start_session(barejid);
chatwin->is_omemo = TRUE;
} else {
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->pgp_send) {
win_println(window, THEME_DEFAULT, '!', "You must disable PGP encryption before starting an OMEMO session.");
return TRUE;
}
if (chatwin->is_otr) {
win_println(window, THEME_DEFAULT, '!', "You must disable OTR encryption before starting an OMEMO session.");
return TRUE;
}
if (chatwin->is_omemo) {
win_println(window, THEME_DEFAULT, '!', "You are already in an OMEMO session.");
return TRUE; return TRUE;
} }
@ -8129,8 +8116,6 @@ cmd_omemo_start(ProfWin *window, const char *const command, gchar **args)
win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session."); win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OMEMO session.");
} }
}
return TRUE; return TRUE;
#else #else
cons_show("This version of Profanity has not been built with OMEMO support enabled"); cons_show("This version of Profanity has not been built with OMEMO support enabled");