text
stringlengths
0
357
dc_chat_t* dc_chat_new(dc_context_t* context)
{
dc_chat_t* chat = NULL;
if (context==NULL || (chat=calloc(1, sizeof(dc_chat_t)))==NULL) {
exit(14); /* cannot allocate little memory, unrecoverable error */
}
chat->magic = DC_CHAT_MAGIC;
chat->context = context;
chat->type = DC_CHAT_TYPE_UNDEFINED;
chat->param = dc_param_new();
return chat;
}
/**
* Free a chat object.
*
* @memberof dc_chat_t
* @param chat Chat object are returned eg. by dc_get_chat().
* If NULL is given, nothing is done.
* @return None.
*/
void dc_chat_unref(dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return;
}
dc_chat_empty(chat);
dc_param_unref(chat->param);
chat->magic = 0;
free(chat);
}
/**
* Empty a chat object.
*
* @private @memberof dc_chat_t
* @param chat The chat object to empty.
* @return None.
*/
void dc_chat_empty(dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return;
}
free(chat->name);
chat->name = NULL;
chat->type = DC_CHAT_TYPE_UNDEFINED;
chat->id = 0;
free(chat->grpid);
chat->grpid = NULL;
chat->blocked = 0;
chat->gossiped_timestamp = 0;
dc_param_set_packed(chat->param, NULL);
}
/**
* Get chat ID. The chat ID is the ID under which the chat is filed in the database.
*
* Special IDs:
* - DC_CHAT_ID_DEADDROP (1) - Virtual chat containing messages which senders are not confirmed by the user.
* - DC_CHAT_ID_STARRED (5) - Virtual chat containing all starred messages-
* - DC_CHAT_ID_ARCHIVED_LINK (6) - A link at the end of the chatlist, if present the UI should show the button "Archived chats"-
*
* "Normal" chat IDs are larger than these special IDs (larger than DC_CHAT_ID_LAST_SPECIAL).
*
* @memberof dc_chat_t
* @param chat The chat object.
* @return Chat ID. 0 on errors.
*/
uint32_t dc_chat_get_id(const dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return 0;
}
return chat->id;
}
/**
* Get chat type.
*
* Currently, there are two chat types:
*
* - DC_CHAT_TYPE_SINGLE (100) - a normal chat is a chat with a single contact,
* chats_contacts contains one record for the user. DC_CONTACT_ID_SELF
* (see dc_contact_t::id) is added _only_ for a self talk.
*