aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-02-10 16:17:01 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-02-10 16:17:01 +0100
commit11181100712fc2a1c2f310b4470d752488e8961e (patch)
treecd5b5341d86e48e7df09c6bfc9414dfc296144ca /src/command
parent83b61e5160b6624eb0b2898c1321d33341e6510c (diff)
downloadprofani-tty-11181100712fc2a1c2f310b4470d752488e8961e.tar.gz
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.
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c11
-rw-r--r--src/command/cmd_defs.c17
-rw-r--r--src/command/cmd_funcs.c41
-rw-r--r--src/command/cmd_funcs.h1
4 files changed, 70 insertions, 0 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 0b411bcb..17629d87 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -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;
+}
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 982d81f6..db719b17 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -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;
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 70a6dcc0..9620f0d7 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -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;
+}
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index a2ccd000..768e14a2 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -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