xep-0308: Implement /correct to correct the last send message

So far the correction is sent. But the UI in Profanity itself is not
updated.

Also autocompletion for `/correct` with the last sent message is
missing.
This commit is contained in:
Michael Vetter
2020-02-10 16:17:01 +01:00
parent 83b61e5160
commit 1118110071
13 changed files with 132 additions and 11 deletions

View File

@@ -114,6 +114,7 @@ static char* _logging_autocomplete(ProfWin *window, const char *const input, gbo
static char* _color_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _avatar_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _correction_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context);
@@ -1640,6 +1641,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
g_hash_table_insert(ac_funcs, "/color", _color_autocomplete);
g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete);
g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete);
g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete);
int len = strlen(input);
char parsed[len+1];
@@ -3736,3 +3738,12 @@ _correction_autocomplete(ProfWin *window, const char *const input, gboolean prev
return NULL;
}
static char*
_correct_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
char *result = NULL;
//TODO: get last message
return result;
}

View File

@@ -2367,6 +2367,7 @@ static struct cmd_t command_defs[] =
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_correction)
CMD_TAGS(
CMD_TAG_UI,
CMD_TAG_CHAT,
CMD_TAG_GROUPCHAT)
CMD_SYN(
@@ -2379,6 +2380,22 @@ static struct cmd_t command_defs[] =
{ "char", "Set character that will prefix corrected messages. Default: +"})
CMD_NOEXAMPLES
},
{ "/correct",
parse_args, 1, 1, NULL,
CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_correct)
CMD_TAGS(
CMD_TAG_CHAT,
CMD_TAG_GROUPCHAT)
CMD_SYN(
"/correct <message>")
CMD_DESC(
"Correct and resend the last message (XEP-0308).")
CMD_ARGS(
{ "<message>", "The corrected message."})
CMD_NOEXAMPLES
},
};
static GHashTable *search_index;

View File

@@ -8680,3 +8680,44 @@ cmd_correction(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
gboolean
cmd_correct(ProfWin *window, const char *const command, gchar **args)
{
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are currently not connected.");
return TRUE;
}
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->last_msg_id == NULL || chatwin->last_message == NULL) {
win_println(window, THEME_DEFAULT, '!', "No last message to correct.");
return TRUE;
}
/*
char *session_jid = chat_session_get_jid(chatwin->barejid);
if (session_jid == NULL) {
win_println(window, THEME_DEFAULT, '!', "Cannot determine if recipeint supports last message correction.");
free(session_jid);
return TRUE;
}
if (caps_jid_has_feature(session_jid, XMPP_FEATURE_LAST_MESSAGE_CORRECTION) == FALSE) {
win_println(window, THEME_DEFAULT, '!', "Recipient does not support last message correction.");
free(session_jid);
return TRUE;
}
*/
// speciel send with replace tag
cl_ev_send_msg_correct(chatwin, args[0], FALSE, TRUE);
}
win_println(window, THEME_DEFAULT, '!', "Command /correct only valid in regular chat windows.");
return TRUE;
}

View File

@@ -228,4 +228,5 @@ gboolean cmd_color(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_os(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args);
#endif