text stringlengths 0 357 |
|---|
} |
} |
/** |
* Get an informational text for a single message. The text is multiline and may |
* contain eg. the raw text of the message. |
* |
* The max. text returned is typically longer (about 100000 characters) than the |
* max. text returned by dc_msg_get_text() (about 30000 characters). |
* |
* @memberof dc_context_t |
* @param context The context object as created by dc_context_new(). |
* @param msg_id The message id for which information should be generated |
* @return Text string, must be free()'d after usage |
*/ |
char* dc_get_msg_info(dc_context_t* context, uint32_t msg_id) |
{ |
sqlite3_stmt* stmt = NULL; |
dc_msg_t* msg = dc_msg_new_untyped(context); |
dc_contact_t* contact_from = dc_contact_new(context); |
char* rawtxt = NULL; |
char* p = NULL; |
dc_strbuilder_t ret; |
dc_strbuilder_init(&ret, 0); |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
dc_msg_load_from_db(msg, context, msg_id); |
dc_contact_load_from_db(contact_from, context->sql, msg->from_id); |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT txt_raw FROM msgs WHERE id=?;"); |
sqlite3_bind_int(stmt, 1, msg_id); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
p = dc_mprintf("Cannot load message #%i.", (int)msg_id); dc_strbuilder_cat(&ret, p); free(p); |
goto cleanup; |
} |
rawtxt = dc_strdup((char*)sqlite3_column_text(stmt, 0)); |
sqlite3_finalize(stmt); |
stmt = NULL; |
dc_trim(rawtxt); |
dc_truncate_str(rawtxt, DC_MAX_GET_INFO_LEN); |
/* add time */ |
dc_strbuilder_cat(&ret, "Sent: "); |
p = dc_timestamp_to_str(dc_msg_get_timestamp(msg)); dc_strbuilder_cat(&ret, p); free(p); |
p = dc_contact_get_name_n_addr(contact_from); dc_strbuilder_catf(&ret, " by %s", p); free(p); |
dc_strbuilder_cat(&ret, "\n"); |
if (msg->from_id!=DC_CONTACT_ID_SELF) { |
dc_strbuilder_cat(&ret, "Received: "); |
p = dc_timestamp_to_str(msg->timestamp_rcvd? msg->timestamp_rcvd : msg->timestamp_sort); dc_strbuilder_cat(&ret, p); free(p); |
dc_strbuilder_cat(&ret, "\n"); |
} |
if (msg->from_id==DC_CONTACT_ID_DEVICE || msg->to_id==DC_CONTACT_ID_DEVICE) { |
goto cleanup; // device-internal message, no further details needed |
} |
/* add mdn's time and readers */ |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT contact_id, timestamp_sent FROM msgs_mdns WHERE msg_id=?;"); |
sqlite3_bind_int (stmt, 1, msg_id); |
while (sqlite3_step(stmt)==SQLITE_ROW) { |
dc_strbuilder_cat(&ret, "Read: "); |
p = dc_timestamp_to_str(sqlite3_column_int64(stmt, 1)); dc_strbuilder_cat(&ret, p); free(p); |
dc_strbuilder_cat(&ret, " by "); |
dc_contact_t* contact = dc_contact_new(context); |
dc_contact_load_from_db(contact, context->sql, sqlite3_column_int64(stmt, 0)); |
p = dc_contact_get_name_n_addr(contact); dc_strbuilder_cat(&ret, p); free(p); |
dc_contact_unref(contact); |
dc_strbuilder_cat(&ret, "\n"); |
} |
sqlite3_finalize(stmt); |
stmt = NULL; |
/* add state */ |
p = NULL; |
switch (msg->state) { |
case DC_STATE_IN_FRESH: p = dc_strdup("Fresh"); break; |
case DC_STATE_IN_NOTICED: p = dc_strdup("Noticed"); break; |
case DC_STATE_IN_SEEN: p = dc_strdup("Seen"); break; |
case DC_STATE_OUT_DELIVERED: p = dc_strdup("Delivered"); break; |
case DC_STATE_OUT_FAILED: p = dc_strdup("Failed"); break; |
case DC_STATE_OUT_MDN_RCVD: p = dc_strdup("Read"); break; |
case DC_STATE_OUT_PENDING: p = dc_strdup("Pending"); break; |
case DC_STATE_OUT_PREPARING: p = dc_strdup("Preparing"); break; |
default: p = dc_mprintf("%i", msg->state); break; |
} |
dc_strbuilder_catf(&ret, "State: %s", p); |
free(p); |
if (dc_msg_has_location(msg)) { |
dc_strbuilder_cat(&ret, ", Location sent"); |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.