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

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

View File

@ -115,7 +115,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs
}
void
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url)
cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *const oob_url, gboolean correct_last_msg)
{
chat_state_active(chatwin->state);
@ -139,11 +139,17 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
return;
}
char *replace_id = NULL;
if (correct_last_msg) {
replace_id = chatwin->last_msg_id;
}
// OTR suported, PGP supported, OMEMO unsupported
#ifdef HAVE_LIBOTR
#ifdef HAVE_LIBGPGME
#ifndef HAVE_OMEMO
if (chatwin->pgp_send) {
// TODO: replace_id
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt);
@ -151,7 +157,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
} else {
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt);
free(id);
@ -171,7 +177,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
#ifndef HAVE_OMEMO
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt);
free(id);
@ -194,7 +200,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PGP, request_receipt);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt);
free(id);
@ -217,7 +223,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_OMEMO, request_receipt);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt);
free(id);
@ -242,7 +248,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
} else {
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt);
free(id);
@ -301,7 +307,7 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
} else {
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt);
char *id = message_send_chat(chatwin->barejid, plugin_msg, oob_url, request_receipt, replace_id);
chat_log_msg_out(chatwin->barejid, plugin_msg, NULL);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_ENC_PLAIN, request_receipt);
free(id);
@ -332,6 +338,12 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oo
#endif
}
void
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url)
{
cl_ev_send_msg_correct(chatwin, msg, oob_url, FALSE);
}
void
cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url)
{

View File

@ -45,6 +45,7 @@ void cl_ev_disconnect(void);
void cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs);
void cl_ev_send_msg_correct(ProfChatWin *chatwin, const char *const msg, const char *const oob_url, gboolean correct_last_msg);
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url);
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url);
void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg, const char *const oob_url);

View File

@ -56,6 +56,7 @@
#endif
static void _chatwin_history(ProfChatWin *chatwin, const char *const contact);
static void _chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message);
ProfChatWin*
chatwin_new(const char *const barejid)
@ -323,6 +324,11 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id,
enc_char = prefs_get_omemo_char();
}
// save last id and message for LMC
if (id) {
_chatwin_set_last_message(chatwin, id, message);
}
if (request_receipt && id) {
win_print_with_receipt((ProfWin*)chatwin, enc_char, "me", message, id);
} else {
@ -496,3 +502,13 @@ _chatwin_history(ProfChatWin *chatwin, const char *const contact)
g_slist_free_full(history, free);
}
}
static void
_chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message)
{
free(chatwin->last_message);
chatwin->last_message = strdup(message);
free(chatwin->last_msg_id);
chatwin->last_msg_id = strdup(id);
}

View File

@ -160,6 +160,9 @@ typedef struct prof_chat_win_t {
char *enctext;
char *incoming_char;
char *outgoing_char;
// For LMC
char *last_message;
char *last_msg_id;
} ProfChatWin;
typedef struct prof_muc_win_t {

View File

@ -152,6 +152,8 @@ win_create_chat(const char *const barejid)
new_win->enctext = NULL;
new_win->incoming_char = NULL;
new_win->outgoing_char = NULL;
new_win->last_message = NULL;
new_win->last_msg_id = NULL;
new_win->memcheck = PROFCHATWIN_MEMCHECK;
@ -488,6 +490,8 @@ win_free(ProfWin* window)
free(chatwin->enctext);
free(chatwin->incoming_char);
free(chatwin->outgoing_char);
free(chatwin->last_message);
free(chatwin->last_msg_id);
chat_state_free(chatwin->state);
break;
}

View File

@ -259,8 +259,7 @@ message_pubsub_event_handler_add(const char *const node, ProfMessageCallback fun
}
char*
message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url,
gboolean request_receipt)
message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, gboolean request_receipt, const char *const replace_id)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
@ -284,6 +283,10 @@ message_send_chat(const char *const barejid, const char *const msg, const char *
stanza_attach_receipt_request(ctx, message);
}
if (replace_id) {
stanza_attach_correction(ctx, message, replace_id);
}
_send_message_stanza(message);
xmpp_stanza_release(message);

View File

@ -2606,3 +2606,15 @@ stanza_create_avatar_retrieve_data_request(xmpp_ctx_t *ctx, const char *stanza_i
return iq;
}
xmpp_stanza_t*
stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const replace_id)
{
xmpp_stanza_t *replace_stanza = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(replace_stanza, "replace");
xmpp_stanza_set_id(replace_stanza, replace_id);
xmpp_stanza_set_ns(replace_stanza, STANZA_NS_LAST_MESSAGE_CORRECTION);
xmpp_stanza_add_child(stanza, replace_stanza);
return stanza;
}

View File

@ -245,6 +245,7 @@ xmpp_stanza_t* stanza_attach_hints_store(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza)
xmpp_stanza_t* stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza);
xmpp_stanza_t* stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url);
xmpp_stanza_t* stanza_attach_origin_id(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const id);
xmpp_stanza_t* stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const replace_id);
xmpp_stanza_t* stanza_create_room_join_presence(xmpp_ctx_t *const ctx,
const char *const full_room_jid, const char *const passwd);

View File

@ -171,8 +171,7 @@ char* connection_jid_for_feature(const char *const feature);
const char* connection_get_profanity_identifier(void);
char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url,
gboolean request_receipt);
char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, gboolean request_receipt, const char *const replace_id);
char* message_send_chat_otr(const char *const barejid, const char *const msg, gboolean request_receipt);
char* message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean request_receipt);
char* message_send_chat_omemo(const char *const jid, uint32_t sid, GList *keys, const unsigned char *const iv, size_t iv_len, const unsigned char *const ciphertext, size_t ciphertext_len, gboolean request_receipt, gboolean muc);