text
stringlengths
0
357
* in a gallery or in a media player.
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @param curr_msg_id This is the current message
* from which the next or previous message should be searched.
* @param dir 1=get the next message, -1=get the previous one.
* @param msg_type Message type to search for.
* If 0, the message type from curr_msg_id is used.
* @param msg_type2 Alternative message type to search for. 0 to skip.
* @param msg_type3 Alternative message type to search for. 0 to skip.
* @return Returns the message ID that should be played next.
* The returned message is in the same chat as the given one
* and has one of the given types.
* Typically, this result is passed again to dc_get_next_media()
* later on the next swipe.
* If there is not next/previous message, the function returns 0.
*/
uint32_t dc_get_next_media(dc_context_t* context, uint32_t curr_msg_id, int dir,
int msg_type, int msg_type2, int msg_type3)
{
uint32_t ret_msg_id = 0;
dc_msg_t* msg = dc_msg_new_untyped(context);
dc_array_t* list = NULL;
int i = 0;
int cnt = 0;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
if (!dc_msg_load_from_db(msg, context, curr_msg_id)) {
goto cleanup;
}
if ((list=dc_get_chat_media(context, msg->chat_id,
msg_type>0? msg_type : msg->type,
msg_type2, msg_type3))==NULL) {
goto cleanup;
}
cnt = dc_array_get_cnt(list);
for (i = 0; i < cnt; i++) {
if (curr_msg_id==dc_array_get_id(list, i))
{
if (dir > 0) {
/* get the next message from the current position */
if (i+1 < cnt) {
ret_msg_id = dc_array_get_id(list, i+1);
}
}
else if (dir < 0) {
/* get the previous message from the current position */
if (i-1 >= 0) {
ret_msg_id = dc_array_get_id(list, i-1);
}
}
break;
}
}
cleanup:
dc_array_unref(list);
dc_msg_unref(msg);
return ret_msg_id;
}
/**
* Get contact IDs belonging to a chat.
*
* - for normal chats, the function always returns exactly one contact,
* DC_CONTACT_ID_SELF is returned only for SELF-chats.
*
* - for group chats all members are returned, DC_CONTACT_ID_SELF is returned
* explicitly as it may happen that oneself gets removed from a still existing
* group
*
* - for the deaddrop, the list is empty
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @param chat_id Chat ID to get the belonging contact IDs for.
* @return An array of contact IDs belonging to the chat; must be freed using dc_array_unref() when done.
*/
dc_array_t* dc_get_chat_contacts(dc_context_t* context, uint32_t chat_id)
{
/* Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a
groupchat but the chats stays visible, moreover, this makes displaying lists easier) */
dc_array_t* ret = dc_array_new(context, 100);
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
if (chat_id==DC_CHAT_ID_DEADDROP) {
goto cleanup; /* we could also create a list for all contacts in the deaddrop by searching contacts belonging to chats with chats.blocked=2, however, currently this is not needed */
}