text stringlengths 0 357 |
|---|
dc_lot_t* dc_chatlist_get_summary(const dc_chatlist_t* chatlist, size_t index, dc_chat_t* chat /*may be NULL*/) |
{ |
/* The summary is created by the chat, not by the last message. |
This is because we may want to display drafts here or stuff as |
"is typing". |
Also, sth. as "No messages" would not work if the summary comes from a |
message. */ |
dc_lot_t* ret = dc_lot_new(); /* the function never returns NULL */ |
uint32_t lastmsg_id = 0; |
dc_msg_t* lastmsg = NULL; |
dc_contact_t* lastcontact = NULL; |
dc_chat_t* chat_to_delete = NULL; |
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC || index>=chatlist->cnt) { |
ret->text2 = dc_strdup("ErrBadChatlistIndex"); |
goto cleanup; |
} |
lastmsg_id = dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT+1); |
if (chat==NULL) { |
chat = dc_chat_new(chatlist->context); |
chat_to_delete = chat; |
if (!dc_chat_load_from_db(chat, dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_CHATLIST_IDS_PER_RESULT))) { |
ret->text2 = dc_strdup("ErrCannotReadChat"); |
goto cleanup; |
} |
} |
if (lastmsg_id) |
{ |
lastmsg = dc_msg_new_untyped(chatlist->context); |
dc_msg_load_from_db(lastmsg, chatlist->context, lastmsg_id); |
if (lastmsg->from_id!=DC_CONTACT_ID_SELF && DC_CHAT_TYPE_IS_MULTI(chat->type)) |
{ |
lastcontact = dc_contact_new(chatlist->context); |
dc_contact_load_from_db(lastcontact, chatlist->context->sql, lastmsg->from_id); |
} |
} |
if (chat->id==DC_CHAT_ID_ARCHIVED_LINK) |
{ |
ret->text2 = dc_strdup(NULL); |
} |
else if (lastmsg==NULL || lastmsg->from_id==0) |
{ |
/* no messages */ |
ret->text2 = dc_stock_str(chatlist->context, DC_STR_NOMESSAGES); |
} |
else |
{ |
/* show the last message */ |
dc_lot_fill(ret, lastmsg, chat, lastcontact, chatlist->context); |
} |
cleanup: |
dc_msg_unref(lastmsg); |
dc_contact_unref(lastcontact); |
dc_chat_unref(chat_to_delete); |
return ret; |
} |
/** |
* Helper function to get the associated context object. |
* |
* @memberof dc_chatlist_t |
* @param chatlist The chatlist object to empty. |
* @return Context object associated with the chatlist. NULL if none or on errors. |
*/ |
dc_context_t* dc_chatlist_get_context(dc_chatlist_t* chatlist) |
{ |
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC) { |
return NULL; |
} |
return chatlist->context; |
} |
static uint32_t get_last_deaddrop_fresh_msg(dc_context_t* context) |
{ |
uint32_t ret = 0; |
sqlite3_stmt* stmt = NULL; |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT m.id " |
" FROM msgs m " |
" LEFT JOIN chats c ON c.id=m.chat_id " |
" WHERE m.state=" DC_STRINGIFY(DC_STATE_IN_FRESH) |
" AND m.hidden=0 " |
" AND c.blocked=" DC_STRINGIFY(DC_CHAT_DEADDROP_BLOCKED) |
" ORDER BY m.timestamp DESC, m.id DESC;"); /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */ |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
ret = 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.