1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 19:42:04 +02:00

mrmailbox_initiate_key_transfer() waits until the setup message is really sent.

This commit is contained in:
B. Petersen 2017-12-05 14:25:54 +01:00
parent 9f07e59a0d
commit ce533af635
3 changed files with 50 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include <assert.h>
#include <dirent.h>
#include <unistd.h> /* for sleep() */
#include <openssl/rand.h>
#include <libetpan/mmapstring.h>
#include <netpgp-extra.h>
@ -476,6 +477,7 @@ char* mrmailbox_initiate_key_transfer(mrmailbox_t* mailbox)
uint32_t contact_id = 0;
uint32_t chat_id = 0;
mrmsg_t* msg = NULL;
uint32_t msg_id = 0;
if( !mrmailbox_alloc_ongoing(mailbox) ) {
return 0; /* no cleanup as this would call mrmailbox_free_ongoing() */
@ -517,10 +519,32 @@ char* mrmailbox_initiate_key_transfer(mrmailbox_t* mailbox)
CHECK_EXIT
if( mrmailbox_send_msg_object(mailbox, chat_id, msg) == 0 ) {
if( (msg_id = mrmailbox_send_msg_object(mailbox, chat_id, msg)) == 0 ) {
goto cleanup;
}
mrmsg_unref(msg);
msg = NULL;
/* wait until the message is really sent */
mrmailbox_log_info(mailbox, 0, "Wait for setup message being sent ...");
while( 1 )
{
CHECK_EXIT
sleep(1);
msg = mrmailbox_get_msg(mailbox, msg_id);
if( mrmsg_is_sent(msg) ) {
break;
}
mrmsg_unref(msg);
msg = NULL;
}
mrmailbox_log_info(mailbox, 0, "... setup message sent.");
success = 1;
cleanup:

View file

@ -147,6 +147,8 @@ int mrmsg_get_type(mrmsg_t* msg)
* - MR_STATE_OUT_MDN_RCVD (28) - Outgoing message read by the recipient (two checkmarks; this requires goodwill on the receiver's side)
* If a sent message changes to this state, you'll receive the event #MR_EVENT_MSG_READ.
*
* If you just want to check if a message is sent or not, please use mrmsg_is_sent() which regards all states accordingly.
*
* The state of just created message objects is MR_STATE_UNDEFINED (0).
* The state is always set by the core-library, users of the library cannot set the state directly, but it is changed implicitly eg.
* when calling mrmailbox_marknoticed_chat() or mrmailbox_markseen_msgs().
@ -575,6 +577,27 @@ char* mrmsg_get_summarytext(mrmsg_t* msg, int approx_characters)
}
/**
* Check if a message was sent successfully.
*
* Currently, "sent" messages are messages that are in the state "delivered" or "mdn received",
* see mrmsg_get_state().
*
* @memberof mrmsg_t
*
* @param msg The message object.
*
* @return 1=message sent successfully, 0=message not yet sent or message is an incoming message.
*/
int mrmsg_is_sent(mrmsg_t* msg)
{
if( msg == 0 ) {
return 0;
}
return (msg->m_state >= MR_STATE_OUT_DELIVERED)? 1 : 0;
}
/**
* Check if a message is starred. Starred messages are "favorites" marked by the user
* with a "star" or something like that. Starred messages can typically be shown

View file

@ -94,7 +94,7 @@ typedef struct mrmsg_t
#define MR_STATE_IN_SEEN 16
#define MR_STATE_OUT_PENDING 20
#define MR_STATE_OUT_ERROR 24
#define MR_STATE_OUT_DELIVERED 26
#define MR_STATE_OUT_DELIVERED 26 /* to check if a mail was sent, use mrmsg_is_sent() */
#define MR_STATE_OUT_MDN_RCVD 28
time_t m_timestamp; /**< Unix time the message was sended or received. 0 if unset. */
@ -129,6 +129,7 @@ int mrmsg_get_duration (mrmsg_t*);
int mrmsg_get_showpadlock (mrmsg_t*);
mrlot_t* mrmsg_get_summary (mrmsg_t*, mrchat_t*);
char* mrmsg_get_summarytext (mrmsg_t*, int approx_characters);
int mrmsg_is_sent (mrmsg_t*);
int mrmsg_is_starred (mrmsg_t*);
int mrmsg_is_forwarded (mrmsg_t*);
int mrmsg_is_systemcmd (mrmsg_t*);