text stringlengths 0 357 |
|---|
* If a new chat is created, the given message ID is moved to this chat, however, |
* there may be more messages moved to the chat from the deaddrop. To get the |
* chat messages, use dc_get_chat_msgs(). |
* |
* If the user is asked before creation, he should be |
* asked whether he wants to chat with the _contact_ belonging to the message; |
* the group names may be really weird when taken from the subject of implicit |
* groups and this may look confusing. |
* |
* Moreover, this function also scales up the origin of the contact belonging |
* to the message and, depending on the contacts origin, messages from the |
* same group may be shown or not - so, all in all, it is fine to show the |
* contact name only. |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
* @param msg_id The message ID to create the chat for. |
* @return The created or reused chat ID on success. 0 on errors. |
*/ |
uint32_t dc_create_chat_by_msg_id(dc_context_t* context, uint32_t msg_id) |
{ |
uint32_t chat_id = 0; |
int send_event = 0; |
dc_msg_t* msg = dc_msg_new_untyped(context); |
dc_chat_t* chat = dc_chat_new(context); |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
goto cleanup; |
} |
if (!dc_msg_load_from_db(msg, context, msg_id) |
|| !dc_chat_load_from_db(chat, msg->chat_id) |
|| chat->id<=DC_CHAT_ID_LAST_SPECIAL) { |
goto cleanup; |
} |
chat_id = chat->id; |
if (chat->blocked) { |
dc_unblock_chat(context, chat->id); |
send_event = 1; |
} |
dc_scaleup_contact_origin(context, msg->from_id, DC_ORIGIN_CREATE_CHAT); |
cleanup: |
dc_msg_unref(msg); |
dc_chat_unref(chat); |
if (send_event) { |
context->cb(context, DC_EVENT_MSGS_CHANGED, 0, 0); |
} |
return chat_id; |
} |
/** |
* Returns all message IDs of the given types in a chat. |
* Typically used to show a gallery. |
* The result must be dc_array_unref()'d |
* |
* 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. |
* |
* @memberof dc_context_t |
* @param context The context object as returned from dc_context_new(). |
* @param chat_id The chat ID to get all messages with media from. |
* @param msg_type Specify a message type to query here, one of the DC_MSG_* constats. |
* @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 An array with messages from the given chat ID that have the wanted message types. |
*/ |
dc_array_t* dc_get_chat_media(dc_context_t* context, uint32_t chat_id, |
int msg_type, int msg_type2, int msg_type3) |
{ |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) { |
return NULL; |
} |
dc_array_t* ret = dc_array_new(context, 100); |
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql, |
"SELECT id FROM msgs WHERE chat_id=? AND (type=? OR type=? OR type=?) ORDER BY timestamp, id;"); |
sqlite3_bind_int(stmt, 1, chat_id); |
sqlite3_bind_int(stmt, 2, msg_type); |
sqlite3_bind_int(stmt, 3, msg_type2>0? msg_type2 : msg_type); |
sqlite3_bind_int(stmt, 4, msg_type3>0? msg_type3 : msg_type); |
while (sqlite3_step(stmt)==SQLITE_ROW) { |
dc_array_add_id(ret, sqlite3_column_int(stmt, 0)); |
} |
sqlite3_finalize(stmt); |
return ret; |
} |
/** |
* Search next/previous message based on a given message and a list of types. |
* The |
* Typically used to implement the "next" and "previous" buttons |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.