text stringlengths 0 357 |
|---|
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT cc.contact_id FROM chats_contacts cc" |
" LEFT JOIN contacts c ON c.id=cc.contact_id" |
" WHERE cc.chat_id=?" |
" ORDER BY c.id=1, LOWER(c.name||c.addr), c.id;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
while (sqlite3_step(stmt)==SQLITE_ROW) { |
dc_array_add_id(ret, sqlite3_column_int(stmt, 0)); |
} |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
/** |
* Get all message IDs belonging to a chat. |
* |
* The list is already sorted and starts with the oldest message. |
* Clients should not try to re-sort the list as this would be an expensive action |
* and would result in inconsistencies between clients. |
* |
* Optionally, some special markers added to the ID-array may help to |
* implement virtual lists. |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
* @param chat_id The chat ID of which the messages IDs should be queried. |
* @param flags If set to DC_GCM_ADDDAYMARKER, the marker DC_MSG_ID_DAYMARKER will |
* be added before each day (regarding the local timezone). Set this to 0 if you do not want this behaviour. |
* @param marker1before An optional message ID. If set, the id DC_MSG_ID_MARKER1 will be added just |
* before the given ID in the returned array. Set this to 0 if you do not want this behaviour. |
* @return Array of message IDs, must be dc_array_unref()'d when no longer used. |
*/ |
dc_array_t* dc_get_chat_msgs(dc_context_t* context, uint32_t chat_id, uint32_t flags, uint32_t marker1before) |
{ |
//clock_t start = clock(); |
int success = 0; |
dc_array_t* ret = dc_array_new(context, 512); |
sqlite3_stmt* stmt = NULL; |
uint32_t curr_id; |
time_t curr_local_timestamp; |
int curr_day, last_day = 0; |
long cnv_to_local = dc_gm2local_offset(); |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || ret==NULL) { |
goto cleanup; |
} |
if (chat_id==DC_CHAT_ID_DEADDROP) |
{ |
int show_emails = dc_sqlite3_get_config_int(context->sql, |
"show_emails", DC_SHOW_EMAILS_DEFAULT); |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT m.id, m.timestamp" |
" FROM msgs m" |
" LEFT JOIN chats ON m.chat_id=chats.id" |
" LEFT JOIN contacts ON m.from_id=contacts.id" |
" WHERE m.from_id!=" DC_STRINGIFY(DC_CONTACT_ID_SELF) |
" AND m.from_id!=" DC_STRINGIFY(DC_CONTACT_ID_DEVICE) |
" AND m.hidden=0 " |
" AND chats.blocked=" DC_STRINGIFY(DC_CHAT_DEADDROP_BLOCKED) |
" AND contacts.blocked=0" |
" AND m.msgrmsg>=? " |
" ORDER BY m.timestamp,m.id;"); /* the list starts with the oldest message*/ |
sqlite3_bind_int(stmt, 1, show_emails==DC_SHOW_EMAILS_ALL? 0 : 1); |
} |
else if (chat_id==DC_CHAT_ID_STARRED) |
{ |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT m.id, m.timestamp" |
" FROM msgs m" |
" LEFT JOIN contacts ct ON m.from_id=ct.id" |
" WHERE m.starred=1 " |
" AND m.hidden=0 " |
" AND ct.blocked=0" |
" ORDER BY m.timestamp,m.id;"); /* the list starts with the oldest message*/ |
} |
else |
{ |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT m.id, m.timestamp" |
" FROM msgs m" |
//" LEFT JOIN contacts ct ON m.from_id=ct.id" |
" WHERE m.chat_id=? " |
" AND m.hidden=0 " |
//" AND ct.blocked=0" -- we hide blocked-contacts from starred and deaddrop, but we have to show them in groups (otherwise it may be hard to follow conversation, wa and tg do the same. however, maybe this needs discussion some time :) |
" ORDER BY m.timestamp,m.id;"); /* the list starts with the oldest message*/ |
sqlite3_bind_int(stmt, 1, chat_id); |
} |
while (sqlite3_step(stmt)==SQLITE_ROW) |
{ |
curr_id = sqlite3_column_int(stmt, 0); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.