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

Show assigned/unassigned messages count in info.

This commit is contained in:
B. Petersen 2016-10-06 16:52:49 +02:00
parent 393ffeedff
commit dabaf4c31d
5 changed files with 35 additions and 13 deletions

View file

@ -501,7 +501,7 @@ char* mrmailbox_get_info(mrmailbox_t* ths)
/* read data (all pointers may be NULL!) */
char *addr, *mail_server, *mail_port, *mail_user, *mail_pw, *send_server, *send_port, *send_user, *send_pw, *debug_dir;
int contacts, chats, messages;
int contacts, chats, assigned_msgs, unassigned_msgs;
mrsqlite3_lock(ths->m_sql); /* CAVE: No return until unlock! */
@ -519,9 +519,10 @@ char* mrmailbox_get_info(mrmailbox_t* ths)
debug_dir = mrsqlite3_get_config_(ths->m_sql, "debug_dir", NULL);
chats = mr_get_chat_cnt_(ths);
messages = mr_get_msg_cnt_(ths);
contacts = mr_get_contact_cnt_(ths);
chats = mr_get_chat_cnt_(ths);
assigned_msgs = mr_get_assigned_msg_cnt_(ths);
unassigned_msgs = mr_get_unassigned_msg_cnt_(ths);
contacts = mr_get_contact_cnt_(ths);
mrsqlite3_unlock(ths->m_sql); /* /CAVE: No return until unlock! */
@ -532,7 +533,7 @@ char* mrmailbox_get_info(mrmailbox_t* ths)
"libEtPan version %i.%i\n"
"Database file %s\n"
"BLOB directory %s\n"
"Chats/Messages %i/%i\n"
"Chats %i chats with %i messages, %i unassigned messages\n"
"Contacts %i\n"
"addr %s\n"
@ -555,7 +556,7 @@ char* mrmailbox_get_info(mrmailbox_t* ths)
, ths->m_dbfile? ths->m_dbfile : unset
, ths->m_blobdir? ths->m_blobdir : unset
, chats, messages
, chats, assigned_msgs, unassigned_msgs
, contacts
, addr? addr : unset

View file

@ -113,16 +113,35 @@ int mrmsg_set_from_stmt_(mrmsg_t* ths, sqlite3_stmt* row, int row_offset) /* fie
******************************************************************************/
size_t mr_get_msg_cnt_(mrmailbox_t* mailbox) /* static function */
size_t mr_get_assigned_msg_cnt_(mrmailbox_t* mailbox) /* the number of messages assigned to a chat */
{
if( mailbox->m_sql->m_cobj==NULL ) {
return 0; /* no database, no messages - this is no error (needed eg. for information) */
}
sqlite3_stmt* s = mrsqlite3_predefine(mailbox->m_sql, SELECT_COUNT_FROM_msg, "SELECT COUNT(*) FROM msg;");
sqlite3_stmt* s = mrsqlite3_predefine(mailbox->m_sql, SELECT_COUNT_FROM_msg_WHERE_assigned,
"SELECT COUNT(*) FROM msg WHERE chat_id!=0;");
if( sqlite3_step(s) != SQLITE_ROW ) {
mrsqlite3_log_error(mailbox->m_sql);
mrlog_error("mr_get_msg_cnt() failed.");
mrlog_error("mr_get_assigned_msg_cnt_() failed.");
return 0; /* error */
}
return sqlite3_column_int(s, 0); /* success */
}
size_t mr_get_unassigned_msg_cnt_(mrmailbox_t* mailbox) /* the number of messages not assigned to a chat */
{
if( mailbox->m_sql->m_cobj==NULL ) {
return 0; /* no database, no messages - this is no error (needed eg. for information) */
}
sqlite3_stmt* s = mrsqlite3_predefine(mailbox->m_sql, SELECT_COUNT_FROM_msg_WHERE_unassigned,
"SELECT COUNT(*) FROM msg WHERE chat_id=0;");
if( sqlite3_step(s) != SQLITE_ROW ) {
mrsqlite3_log_error(mailbox->m_sql);
mrlog_error("mr_get_unassigned_msg_cnt_() failed.");
return 0; /* error */
}

View file

@ -89,8 +89,9 @@ void mrmsg_empty (mrmsg_t*);
#define MR_MSG_FIELDS " m.id,m.chat_id,m.from_id, m.timestamp,m.type,m.state, m.txt,m.param,m.bytes "
int mrmsg_set_from_stmt_ (mrmsg_t*, sqlite3_stmt* row, int row_offset); /* row order is MR_MSG_FIELDS */
size_t mr_get_msg_cnt_ (mrmailbox_t*);
int mr_message_id_exists_ (mrmailbox_t*, const char* rfc724_mid);
size_t mr_get_assigned_msg_cnt_ (mrmailbox_t*);
size_t mr_get_unassigned_msg_cnt_(mrmailbox_t*);
int mr_message_id_exists_ (mrmailbox_t*, const char* rfc724_mid);
#ifdef __cplusplus

View file

@ -35,7 +35,7 @@ mrmsglist_t* mrmsglist_new(mrchat_t* chat)
mrmsglist_t* ths = NULL;
if( (ths=malloc(sizeof(mrmsglist_t)))==NULL ) {
return NULL; /* error */
exit(21); /* cannot allocate little memory, unrecoverable error */
}
ths->m_chat = chat;

View file

@ -75,7 +75,8 @@ enum
,SELECT_COUNT_FROM_chats_contacts_WHERE_i
,UPDATE_chats_dd
,SELECT_COUNT_FROM_msg
,SELECT_COUNT_FROM_msg_WHERE_assigned
,SELECT_COUNT_FROM_msg_WHERE_unassigned
,SELECT_i_FROM_msg_m
,SELECT_icfttstpb_FROM_msg_i
,INSERT_INTO_msg_mcfttsmp