mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 19:42:04 +02:00
Get message lists.
This commit is contained in:
parent
1835b92733
commit
db155c622f
7 changed files with 53 additions and 17 deletions
|
@ -61,7 +61,7 @@ typedef struct mrchat_t
|
|||
|
||||
void mrchat_unref (mrchat_t*);
|
||||
char* mrchat_get_subtitle (mrchat_t*); /* either the e-mail-address or the number of group members, the result must be free()'d! */
|
||||
mrmsglist_t* mrchat_get_msgs (mrchat_t*, size_t index, size_t amount); /* the caller must unref the result */
|
||||
mrmsglist_t* mrchat_get_msgs (mrchat_t*, size_t offset, size_t amount); /* the caller must unref the result */
|
||||
int mrchat_get_unread_count (mrchat_t*);
|
||||
|
||||
/* the following functions get information about the last message or draft;
|
||||
|
|
|
@ -52,7 +52,9 @@ void mrchatlist_unref(mrchatlist_t* ths)
|
|||
}
|
||||
|
||||
mrchatlist_empty(ths);
|
||||
carray_free(ths->m_chats);
|
||||
if( ths->m_chats ) {
|
||||
carray_free(ths->m_chats);
|
||||
}
|
||||
free(ths);
|
||||
}
|
||||
|
||||
|
@ -111,7 +113,8 @@ int mrchatlist_load_from_db_(mrchatlist_t* ths)
|
|||
"SELECT " MR_CHAT_FIELDS "," MR_MSG_FIELDS " FROM chats c "
|
||||
" LEFT JOIN msg m ON (c.id=m.chat_id AND m.timestamp=(SELECT MIN(timestamp) FROM msg WHERE chat_id=c.id)) "
|
||||
" GROUP BY c.id " /* GROUP BY is needed as there may be several messages with the same timestamp */
|
||||
" ORDER BY timestamp;");
|
||||
" ORDER BY timestamp DESC;" /* the list starts with the newest chats */
|
||||
);
|
||||
if( stmt==NULL ) {
|
||||
goto GetChatList_Cleanup;
|
||||
}
|
||||
|
|
|
@ -40,15 +40,15 @@ typedef struct mrchatlist_t
|
|||
} mrchatlist_t;
|
||||
|
||||
|
||||
mrchatlist_t* mrchatlist_new (mrmailbox_t*);
|
||||
void mrchatlist_unref (mrchatlist_t*);
|
||||
void mrchatlist_empty (mrchatlist_t*);
|
||||
size_t mrchatlist_get_cnt (mrchatlist_t*);
|
||||
mrchat_t* mrchatlist_get_chat_by_index (mrchatlist_t*, size_t index); /* result must be unref'd, you can also use m_chats directly */
|
||||
|
||||
|
||||
/*** library-private **********************************************************/
|
||||
|
||||
mrchatlist_t* mrchatlist_new (mrmailbox_t*);
|
||||
void mrchatlist_empty (mrchatlist_t*);
|
||||
int mrchatlist_load_from_db_ (mrchatlist_t*);
|
||||
|
||||
|
||||
|
|
|
@ -442,7 +442,9 @@ void mrmimeparser_unref_(mrmimeparser_t* ths)
|
|||
}
|
||||
|
||||
mrmimeparser_empty_(ths);
|
||||
carray_free(ths->m_parts);
|
||||
if( ths->m_parts ) {
|
||||
carray_free(ths->m_parts);
|
||||
}
|
||||
free(ths);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,17 @@ void mrmsglist_unref(mrmsglist_t* ths)
|
|||
return; /* error */
|
||||
}
|
||||
|
||||
if( ths->m_msgs )
|
||||
mrmsglist_empty(ths);
|
||||
if( ths->m_msgs ) {
|
||||
carray_free(ths->m_msgs);
|
||||
}
|
||||
free(ths);
|
||||
}
|
||||
|
||||
|
||||
void mrmsglist_empty(mrmsglist_t* ths)
|
||||
{
|
||||
if( ths == NULL && ths->m_msgs )
|
||||
{
|
||||
int i, cnt = carray_count(ths->m_msgs);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
|
@ -58,10 +68,27 @@ void mrmsglist_unref(mrmsglist_t* ths)
|
|||
mrmsg_t* msg = (mrmsg_t*)carray_get(ths->m_msgs, i);
|
||||
mrmsg_unref(msg);
|
||||
}
|
||||
|
||||
carray_free(ths->m_msgs);
|
||||
ths->m_msgs = NULL;
|
||||
carray_set_size(ths->m_msgs, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t mrmsglist_get_cnt(mrmsglist_t* ths)
|
||||
{
|
||||
if( ths == NULL || ths->m_msgs == NULL ) {
|
||||
return 0; /* error */
|
||||
}
|
||||
|
||||
return (size_t)carray_count(ths->m_msgs);
|
||||
}
|
||||
|
||||
|
||||
mrmsg_t* mrmsglist_get_msg_by_index (mrmsglist_t* ths, size_t index)
|
||||
{
|
||||
if( ths == NULL || ths->m_msgs == NULL || index >= (size_t)carray_count(ths->m_msgs) ) {
|
||||
return 0; /* error */
|
||||
}
|
||||
|
||||
return mrmsg_ref((mrmsg_t*)carray_get(ths->m_msgs, index));
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,11 @@ typedef struct mrmsglist_t
|
|||
} mrmsglist_t;
|
||||
|
||||
|
||||
mrmsglist_t* mrmsglist_new (void);
|
||||
void mrmsglist_unref (mrmsglist_t*);
|
||||
mrmsglist_t* mrmsglist_new (void);
|
||||
void mrmsglist_unref (mrmsglist_t*);
|
||||
void mrmsglist_empty (mrmsglist_t*);
|
||||
size_t mrmsglist_get_cnt (mrmsglist_t*);
|
||||
mrmsg_t* mrmsglist_get_msg_by_index (mrmsglist_t*, size_t index); /* result must be unref'd, you can also use m_msgs directly */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -84,12 +84,13 @@ static carray* mr_split_into_lines(const char* buf_terminated)
|
|||
|
||||
static void mr_free_splitted_lines(carray* lines)
|
||||
{
|
||||
int i, cnt = carray_count(lines);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
free(carray_get(lines, i));
|
||||
if( lines ) {
|
||||
int i, cnt = carray_count(lines);
|
||||
for( i = 0; i < cnt; i++ ) {
|
||||
free(carray_get(lines, i));
|
||||
}
|
||||
carray_free(lines);
|
||||
}
|
||||
carray_free(lines);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue