From 7381990a96a1e66f173e22bdcd78b6c8df2f57a5 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sun, 21 Oct 2018 16:31:44 +0200 Subject: [PATCH] fix #317: allow editing the message once it gets available in the db after sending --- src/compose_message.cc | 8 +++-- src/compose_message.hh | 4 +-- src/modes/edit_message.cc | 46 ++++++++++++++++++++++++++-- src/modes/edit_message.hh | 3 +- src/modes/thread_view/thread_view.hh | 1 + 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/compose_message.cc b/src/compose_message.cc index e90c6f0d7..c9985e9a2 100644 --- a/src/compose_message.cc +++ b/src/compose_message.cc @@ -662,19 +662,21 @@ namespace Astroid { return m_message_sent; } - void ComposeMessage::emit_message_sent (bool res) { - m_message_sent.emit (res); + void ComposeMessage::emit_message_sent (bool res, ustring save_to) { + m_message_sent.emit (res, save_to); } void ComposeMessage::message_sent_event () { /* add to notmuch with sent tag (on main GUI thread) */ + ustring _sto = ""; if (!dryrun && message_sent_result && account->save_sent) { astroid->actions->doit (refptr ( new AddSentMessage (save_to.c_str (), account->additional_sent_tags))); + _sto = save_to.c_str (); LOG (info) << "cm: sent message added to db."; } - emit_message_sent (message_sent_result); + emit_message_sent (message_sent_result, _sto); } ComposeMessage::type_message_send_status diff --git a/src/compose_message.hh b/src/compose_message.hh index 655dccdf9..d6c5efe48 100644 --- a/src/compose_message.hh +++ b/src/compose_message.hh @@ -114,10 +114,10 @@ namespace Astroid { public: /* message sent */ - typedef sigc::signal type_message_sent; + typedef sigc::signal type_message_sent; type_message_sent message_sent (); - void emit_message_sent (bool); + void emit_message_sent (bool, ustring); bool message_sent_result; void message_sent_event (); diff --git a/src/modes/edit_message.cc b/src/modes/edit_message.cc index 07285facb..079feddb0 100644 --- a/src/modes/edit_message.cc +++ b/src/modes/edit_message.cc @@ -1129,8 +1129,9 @@ namespace Astroid { on_tv_ready (); } - void EditMessage::send_message_finished (bool result_from_sender) { + void EditMessage::send_message_finished (bool result_from_sender, ustring fname) { LOG (info) << "em: message sending done."; + delete sending_message; status_icon_visible = true; Glib::RefPtr theme = Gtk::IconTheme::get_default(); @@ -1150,6 +1151,35 @@ namespace Astroid { delete_draft (); } + if (!fname.empty ()) { + /* message has been saved to disk, but might be outside notmuch dir and + * adding to db is async (message_updated will be emitted when added) + * + * if the message has not been added yet, the signal will be emitted on + * this thread (GUI). so we are sure to catch it if we connect to it now. + * + */ + + Db db; + notmuch_message_t * m; + if ((notmuch_database_find_message_by_filename (db.nm_db, + fname.c_str (), &m) == NOTMUCH_STATUS_SUCCESS) && + (m != NULL)) + { + on_message_added_to_database (&db, notmuch_message_get_message_id (m)); + notmuch_message_destroy (m); + } else { + /* not yet added */ + astroid->actions->signal_message_updated ().connect ( + sigc::mem_fun (this, &EditMessage::on_message_added_to_database)); + } + } else { + /* this account does not save its message, however, the message might + * be synced back pretty soon so we wait and see if that happens */ + + astroid->actions->signal_message_updated ().connect ( + sigc::mem_fun (this, &EditMessage::on_message_added_to_database)); + } } else { fields_show (); @@ -1167,10 +1197,20 @@ namespace Astroid { close (true); } + emit_message_sent_attempt (result_from_sender); + } - delete sending_message; + void EditMessage::on_message_added_to_database (Db * db, ustring mid) { + if (mid == msg_id) { + LOG (info) << "em: message added to database, allow editing."; + thread_view->edit_mode = false; - emit_message_sent_attempt (result_from_sender); + db->on_message (mid, [&] (notmuch_message_t * msg) { + auto msgt = refptr(new MessageThread()); + msgt->add_message (refptr(new Message(msg, 0))); + thread_view->load_message_thread (msgt); + }); + } } void EditMessage::lock_message_after_send () { diff --git a/src/modes/edit_message.hh b/src/modes/edit_message.hh index 61842caa8..7ba8bfda5 100644 --- a/src/modes/edit_message.hh +++ b/src/modes/edit_message.hh @@ -106,8 +106,9 @@ namespace Astroid { ComposeMessage * sending_message; std::atomic sending_in_progress; - void send_message_finished (bool result); + void send_message_finished (bool result, ustring fname); void update_send_message_status (bool warn, ustring msg); + void on_message_added_to_database (Db * db, ustring mid); /* make a draft message that can be edited */ void prepare_message (); diff --git a/src/modes/thread_view/thread_view.hh b/src/modes/thread_view/thread_view.hh index a87ec864c..96eda0f5a 100644 --- a/src/modes/thread_view/thread_view.hh +++ b/src/modes/thread_view/thread_view.hh @@ -38,6 +38,7 @@ namespace Astroid { class ThreadView : public Mode { friend PageClient; + friend EditMessage; public: ThreadView (MainWindow *, bool _edit_mode = false);