1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-29 19:56:07 -04:00

Add chat outgoing correction

This commit is contained in:
James Booth 2016-12-06 23:51:31 +00:00
parent 9926d016a0
commit 8bc9a64698
15 changed files with 107 additions and 29 deletions

View File

@ -2109,7 +2109,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args)
ui_focus_win((ProfWin*)chatwin);
if (msg) {
cl_ev_send_msg(chatwin, msg, FALSE);
cl_ev_send_msg(chatwin, msg, FALSE, FALSE);
} else {
#ifdef HAVE_LIBOTR
if (otr_is_secure(barejid)) {
@ -4721,7 +4721,7 @@ cmd_tiny(ProfWin *window, const char *const command, gchar **args)
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, tiny, FALSE);
cl_ev_send_msg(chatwin, tiny, FALSE, FALSE);
break;
}
case WIN_PRIVATE:
@ -7051,7 +7051,7 @@ cmd_correct(ProfWin *window, const char *const command, gchar **args)
cons_debug(" Original : %s", chatwin->last_message);
cons_debug(" Corrected : %s", corrected);
cl_ev_send_msg(chatwin, corrected, FALSE);
cl_ev_send_msg(chatwin, corrected, FALSE, TRUE);
return TRUE;
}
@ -7176,7 +7176,7 @@ _cmd_execute_default(ProfWin *window, const char *inp)
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, inp, FALSE);
cl_ev_send_msg(chatwin, inp, FALSE, FALSE);
break;
}
case WIN_PRIVATE:

View File

@ -115,7 +115,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m
}
void
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload)
cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload, gboolean correct)
{
chat_state_active(chatwin->state);
@ -134,6 +134,11 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload)
}
}
char *correct_id = NULL;
if (correct) {
correct_id = chatwin->last_id;
}
char *plugin_msg = plugins_pre_chat_message_send(chatwin->barejid, msg);
// OTR suported, PGP supported
@ -142,14 +147,14 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload)
if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP, request_receipt);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP, request_receipt, NULL);
free(id);
} else {
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload);
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload, correct_id);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt, correct_id);
free(id);
}
}
@ -165,9 +170,9 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload)
#ifndef HAVE_LIBGPGME
gboolean handled = otr_on_message_send(chatwin, plugin_msg, request_receipt);
if (!handled) {
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload);
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload, correct_id);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt. correct_id);
free(id);
}
@ -183,12 +188,12 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload)
if (chatwin->pgp_send) {
char *id = message_send_chat_pgp(chatwin->barejid, plugin_msg, request_receipt);
chat_log_pgp_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP, request_receipt);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PGP, request_receipt, NULL);
free(id);
} else {
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload);
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload, correct_id);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt, correct_id);
free(id);
}
@ -201,9 +206,9 @@ cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload)
// OTR unsupported, PGP unsupported
#ifndef HAVE_LIBOTR
#ifndef HAVE_LIBGPGME
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload);
char *id = message_send_chat(chatwin->barejid, plugin_msg, request_receipt, upload, correct_id);
chat_log_msg_out(chatwin->barejid, plugin_msg);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt);
chatwin_outgoing_msg(chatwin, plugin_msg, id, PROF_MSG_PLAIN, request_receipt, correct_id);
free(id);
plugins_post_chat_message_send(chatwin->barejid, plugin_msg);

View File

@ -44,7 +44,7 @@ void cl_ev_disconnect(void);
void cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs);
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload);
void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, gboolean upload, gboolean correct);
void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, gboolean upload);
void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char *const msg, gboolean upload);

View File

@ -347,7 +347,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean re
if (encrypted) {
id = message_send_chat_otr(chatwin->barejid, encrypted, request_receipt);
chat_log_otr_msg_out(chatwin->barejid, message);
chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_OTR, request_receipt);
chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_OTR, request_receipt, NULL);
otr_free_message(encrypted);
free(id);
return TRUE;
@ -367,7 +367,7 @@ otr_on_message_send(ProfChatWin *chatwin, const char *const message, gboolean re
if (policy == PROF_OTRPOLICY_OPPORTUNISTIC) {
char *otr_tagged_msg = otr_tag_message(message);
id = message_send_chat_otr(chatwin->barejid, otr_tagged_msg, request_receipt);
chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_PLAIN, request_receipt);
chatwin_outgoing_msg(chatwin, message, id, PROF_MSG_PLAIN, request_receipt, NULL);
chat_log_msg_out(chatwin->barejid, message);
free(otr_tagged_msg);
free(id);

View File

@ -258,7 +258,7 @@ end:
{
ProfChatWin *chatwin = (ProfChatWin*)(upload->window);
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, upload->get_url, TRUE);
cl_ev_send_msg(chatwin, upload->get_url, TRUE, FALSE);
break;
}
case WIN_PRIVATE:

View File

@ -292,12 +292,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha
free(plugin_message);
}
void
chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode,
gboolean request_receipt)
static void
_chatwin_set_last_message(ProfChatWin *chatwin, const char *const id, const char *const message)
{
assert(chatwin != NULL);
if (chatwin->last_message) {
free(chatwin->last_message);
}
@ -306,6 +303,22 @@ chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id,
free(chatwin->last_id);
}
chatwin->last_id = strdup(id);
}
void
chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode,
gboolean request_receipt, char *correct_id)
{
assert(chatwin != NULL);
if (correct_id) {
win_correct((ProfWin*)chatwin, '+', message, id, request_receipt, correct_id);
_chatwin_set_last_message(chatwin, id, message);
return;
}
_chatwin_set_last_message(chatwin, id, message);
char enc_char = '-';
if (enc_mode == PROF_MSG_OTR) {

View File

@ -123,7 +123,7 @@ void chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, cons
void chatwin_receipt_received(ProfChatWin *chatwin, const char *const id);
void chatwin_recipient_gone(ProfChatWin *chatwin);
void chatwin_outgoing_msg(ProfChatWin *chatwin, const char *const message, char *id, prof_enc_t enc_mode,
gboolean request_receipt);
gboolean request_receipt, char *correct_id);
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char *const message, prof_enc_t enc_mode);
void chatwin_contact_online(ProfChatWin *chatwin, Resource *resource, GDateTime *last_activity);
void chatwin_contact_offline(ProfChatWin *chatwin, char *resource, char *status);

View File

@ -1172,6 +1172,46 @@ win_print_outgoing(ProfWin *window, const char ch, const char *const message, co
buffer_append(window, entry);
}
void
win_correct(ProfWin *window, const char ch, const char *const message, const char *const id, gboolean request_receipt,
const char *const correct_id)
{
ProfBuffEntry *entry = buffer_get_entry_by_outgoing_id(window->layout->entries, correct_id);
if (!entry) {
return;
}
if (entry->date) {
if (entry->date->timestamp) {
g_date_time_unref(entry->date->timestamp);
}
free(entry->date);
}
entry->date = buffer_date_new_now();
entry->show_char = ch;
if (entry->message) {
free(entry->message);
}
entry->message = strdup(message);
if (entry->xmpp->outgoing_id) {
free(entry->xmpp->outgoing_id);
}
entry->xmpp->outgoing_id = strdup(id);
if (request_receipt) {
if (entry->xmpp->receipt) {
entry->xmpp->receipt->received = FALSE;
} else {
entry->xmpp->receipt = buffer_receipt_new();
}
}
win_redraw(window);
}
void
win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message)
{

View File

@ -68,6 +68,8 @@ void win_print_outgoing(ProfWin *window, const char ch, const char *const messag
void win_print_incoming(ProfWin *window, GDateTime *timestamp,
const char *const them, const char *const message, prof_enc_t enc_mode);
void win_print_history(ProfWin *window, GDateTime *timestamp, const char *const message);
void win_correct(ProfWin *window, const char ch, const char *const message, const char *const id, gboolean request_receipt,
const char *const correct_id);
void win_print_upload(ProfWin *window, const char *const message, char *url);
void win_update_upload(ProfWin *window, const char *const url, const char *const message);

View File

@ -132,7 +132,7 @@ message_handlers_init(void)
}
char*
message_send_chat(const char *const barejid, const char *const msg, gboolean request_receipt, gboolean upload)
message_send_chat(const char *const barejid, const char *const msg, gboolean request_receipt, gboolean upload, char *correct_id)
{
xmpp_ctx_t * const ctx = connection_get_ctx();
@ -156,6 +156,10 @@ message_send_chat(const char *const barejid, const char *const msg, gboolean req
stanza_attach_receipt_request(ctx, message);
}
if (correct_id) {
stanza_attach_correction(ctx, message, correct_id);
}
_send_message_stanza(message);
xmpp_stanza_release(message);

View File

@ -405,6 +405,19 @@ stanza_attach_receipt_request(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza)
return stanza;
}
xmpp_stanza_t*
stanza_attach_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, char *correct_id)
{
xmpp_stanza_t *replace = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(replace, "replace");
xmpp_stanza_set_id(replace, correct_id);
xmpp_stanza_set_ns(replace, STANZA_NS_LASTMESSAGECORRECTION);
xmpp_stanza_add_child(stanza, replace);
xmpp_stanza_release(replace);
return stanza;
}
xmpp_stanza_t*
stanza_attach_x_oob_url(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, const char *const url)
{

View File

@ -228,6 +228,7 @@ xmpp_stanza_t* stanza_attach_hints_no_copy(xmpp_ctx_t *ctx, xmpp_stanza_t *stanz
xmpp_stanza_t* stanza_attach_hints_no_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_correction(xmpp_ctx_t *ctx, xmpp_stanza_t *stanza, char *correct_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

@ -132,7 +132,7 @@ GList* connection_get_available_resources(void);
gboolean connection_supports(const char *const feature);
char* connection_jid_for_feature(const char *const feature);
char* message_send_chat(const char *const barejid, const char *const msg, gboolean request_receipt, gboolean upload);
char* message_send_chat(const char *const barejid, const char *const msg, gboolean request_receipt, gboolean upload, char *correct_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_private(const char *const fulljid, const char *const msg, gboolean upload);

View File

@ -154,7 +154,7 @@ void ui_disconnected(void) {}
void chatwin_recipient_gone(ProfChatWin *chatwin) {}
void chatwin_outgoing_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode,
gboolean request_receipt) {}
gboolean request_receipt, char *correct_id) {}
void chatwin_outgoing_carbon(ProfChatWin *chatwin, const char * const message, prof_enc_t enc_mode) {}
void privwin_outgoing_msg(ProfPrivateWin *privwin, const char * const message, const char *const id) {}

View File

@ -91,7 +91,7 @@ connection_supports(const char *const feature)
}
// message functions
char* message_send_chat(const char * const barejid, const char * const msg, gboolean request_receipt, gboolean upload)
char* message_send_chat(const char * const barejid, const char * const msg, gboolean request_receipt, gboolean upload, char *correct)
{
check_expected(barejid);
check_expected(msg);