mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
make dc_get_fresh_msgs() more reliable
This commit is contained in:
parent
6fe88367d6
commit
b5df1118f3
1 changed files with 16 additions and 23 deletions
|
@ -690,17 +690,18 @@ char* dc_get_info(dc_context_t* context)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the message IDs of all _fresh_ messages of any chat. Typically used for implementing
|
* Returns the message IDs of all _fresh_ messages of any chat.
|
||||||
* notification summaries.
|
* Typically used for implementing notification summaries.
|
||||||
|
* The list is already sorted and starts with the most recent fresh message.
|
||||||
*
|
*
|
||||||
* @memberof dc_context_t
|
* @memberof dc_context_t
|
||||||
* @param context The context object as returned from dc_context_new().
|
* @param context The context object as returned from dc_context_new().
|
||||||
* @return Array of message IDs, must be dc_array_unref()'d when no longer used.
|
* @return Array of message IDs, must be dc_array_unref()'d when no longer used.
|
||||||
|
* On errors, the list is empty. NULL is never returned.
|
||||||
*/
|
*/
|
||||||
dc_array_t* dc_get_fresh_msgs(dc_context_t* context)
|
dc_array_t* dc_get_fresh_msgs(dc_context_t* context)
|
||||||
{
|
{
|
||||||
int show_deaddrop = 0;
|
int show_deaddrop = 0;
|
||||||
int success = 0;
|
|
||||||
dc_array_t* ret = dc_array_new(context, 128);
|
dc_array_t* ret = dc_array_new(context, 128);
|
||||||
sqlite3_stmt* stmt = NULL;
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
|
||||||
|
@ -708,35 +709,27 @@ dc_array_t* dc_get_fresh_msgs(dc_context_t* context)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
show_deaddrop = 0;//dc_sqlite3_get_config_int(context->sql, "show_deaddrop", 0);
|
|
||||||
|
|
||||||
stmt = dc_sqlite3_prepare(context->sql,
|
stmt = dc_sqlite3_prepare(context->sql,
|
||||||
"SELECT m.id"
|
"SELECT m.id"
|
||||||
" FROM msgs m"
|
" FROM msgs m"
|
||||||
" LEFT JOIN contacts ct ON m.from_id=ct.id"
|
" LEFT JOIN contacts ct ON m.from_id=ct.id"
|
||||||
" LEFT JOIN chats c ON m.chat_id=c.id"
|
" LEFT JOIN chats c ON m.chat_id=c.id"
|
||||||
" WHERE m.state=" DC_STRINGIFY(DC_STATE_IN_FRESH) " AND ct.blocked=0 AND (c.blocked=0 OR c.blocked=?)"
|
" WHERE m.state=?"
|
||||||
" ORDER BY m.timestamp DESC,m.id DESC;"); /* the list starts with the newest messages*/
|
" AND m.chat_id>?"
|
||||||
sqlite3_bind_int(stmt, 1, show_deaddrop? DC_CHAT_DEADDROP_BLOCKED : 0);
|
" AND ct.blocked=0"
|
||||||
|
" AND (c.blocked=0 OR c.blocked=?)"
|
||||||
|
" ORDER BY m.timestamp DESC,m.id DESC;");
|
||||||
|
sqlite3_bind_int(stmt, 1, DC_STATE_IN_FRESH);
|
||||||
|
sqlite3_bind_int(stmt, 2, DC_CHAT_ID_LAST_SPECIAL);
|
||||||
|
sqlite3_bind_int(stmt, 3, show_deaddrop? DC_CHAT_DEADDROP_BLOCKED : 0);
|
||||||
|
|
||||||
while (sqlite3_step(stmt)==SQLITE_ROW) {
|
while (sqlite3_step(stmt)==SQLITE_ROW) {
|
||||||
dc_array_add_id(ret, sqlite3_column_int(stmt, 0));
|
dc_array_add_id(ret, sqlite3_column_int(stmt, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
success = 1;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
|
return ret;
|
||||||
if (success) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (ret) {
|
|
||||||
dc_array_unref(ret);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue