Skip to content

Commit

Permalink
fix astroidmail#317: allow editing the message once it gets available…
Browse files Browse the repository at this point in the history
… in the db after sending
  • Loading branch information
gauteh committed Oct 21, 2018
1 parent 03e05bb commit 7381990
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/compose_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action> (
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
Expand Down
4 changes: 2 additions & 2 deletions src/compose_message.hh
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ namespace Astroid {

public:
/* message sent */
typedef sigc::signal <void, bool> type_message_sent;
typedef sigc::signal <void, bool, ustring> 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 ();
Expand Down
46 changes: 43 additions & 3 deletions src/modes/edit_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gtk::IconTheme> theme = Gtk::IconTheme::get_default();
Expand All @@ -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 ();

Expand All @@ -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<MessageThread>(new MessageThread());
msgt->add_message (refptr<Message>(new Message(msg, 0)));
thread_view->load_message_thread (msgt);
});
}
}

void EditMessage::lock_message_after_send () {
Expand Down
3 changes: 2 additions & 1 deletion src/modes/edit_message.hh
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ namespace Astroid {

ComposeMessage * sending_message;
std::atomic<bool> 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 ();
Expand Down
1 change: 1 addition & 0 deletions src/modes/thread_view/thread_view.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Astroid {

class ThreadView : public Mode {
friend PageClient;
friend EditMessage;

public:
ThreadView (MainWindow *, bool _edit_mode = false);
Expand Down

0 comments on commit 7381990

Please sign in to comment.