text stringlengths 0 357 |
|---|
} |
// automatically prepare normal messages |
if (msg->state!=DC_STATE_OUT_PREPARING) { |
if (!prepare_msg_common(context, chat_id, msg)) { |
return 0; |
}; |
} |
// update message state of separately prepared messages |
else { |
if (chat_id!=0 && chat_id!=msg->chat_id) { |
return 0; |
} |
dc_update_msg_state(context, msg->id, DC_STATE_OUT_PENDING); |
} |
// create message file and submit SMTP job |
if (!dc_job_send_msg(context, msg->id)) { |
return 0; |
} |
context->cb(context, DC_EVENT_MSGS_CHANGED, msg->chat_id, msg->id); |
if (dc_param_exists(msg->param, DC_PARAM_SET_LATITUDE)) { |
context->cb(context, DC_EVENT_LOCATION_CHANGED, DC_CONTACT_ID_SELF, 0); |
} |
// recursively send any forwarded copies |
if (!chat_id) { |
char* forwards = dc_param_get(msg->param, DC_PARAM_PREP_FORWARDS, NULL); |
if (forwards) { |
char* p = forwards; |
while (*p) { |
int32_t id = strtol(p, &p, 10); |
if (!id) break; // avoid hanging if user tampers with db |
dc_msg_t* copy = dc_get_msg(context, id); |
if (copy) { |
dc_send_msg(context, 0, copy); |
} |
dc_msg_unref(copy); |
} |
dc_param_set(msg->param, DC_PARAM_PREP_FORWARDS, NULL); |
dc_msg_save_param_to_disk(msg); |
} |
free(forwards); |
} |
return msg->id; |
} |
/** |
* Send a simple text message a given chat. |
* |
* Sends the event #DC_EVENT_MSGS_CHANGED on succcess. |
* However, this does not imply, the message really reached the recipient - |
* sending may be delayed eg. due to network problems. However, from your |
* view, you're done with the message. Sooner or later it will find its way. |
* |
* See also dc_send_msg(). |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
* @param chat_id Chat ID to send the text message to. |
* @param text_to_send Text to send to the chat defined by the chat ID. |
* Passing an empty text here causes an empty text to be sent, |
* it's up to the caller to handle this if undesired. |
* Passing NULL as the text causes the function to return 0. |
* @return The ID of the message that is about being sent. |
*/ |
uint32_t dc_send_text_msg(dc_context_t* context, uint32_t chat_id, const char* text_to_send) |
{ |
dc_msg_t* msg = dc_msg_new(context, DC_MSG_TEXT); |
uint32_t ret = 0; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL || text_to_send==NULL) { |
goto cleanup; |
} |
msg->text = dc_strdup(text_to_send); |
ret = dc_send_msg(context, chat_id, msg); |
cleanup: |
dc_msg_unref(msg); |
return ret; |
} |
/* |
* Log a device message. |
* Such a message is typically shown in the "middle" of the chat, the user can check this using dc_msg_is_info(). |
* Texts are typically "Alice has added Bob to the group" or "Alice fingerprint verified." |
*/ |
void dc_add_device_msg(dc_context_t* context, uint32_t chat_id, const char* text) |
{ |
uint32_t msg_id = 0; |
sqlite3_stmt* stmt = NULL; |
char* rfc724_mid = dc_create_outgoing_rfc724_mid(NULL, "@device"); |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || text==NULL) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.