text
stringlengths
0
357
* Get the chat's profile image.
* For groups, this is the image set by any group member
* using dc_set_chat_profile_image().
* For normal chats, this is the image set by each remote user on their own
* using dc_set_config(context, "selfavatar", image).
*
* @memberof dc_chat_t
* @param chat The chat object.
* @return Path and file if the profile image, if any.
* NULL otherwise.
* Must be free()'d after usage.
*/
char* dc_chat_get_profile_image(const dc_chat_t* chat)
{
char* image_rel = NULL;
char* image_abs = NULL;
dc_array_t* contacts = NULL;
dc_contact_t* contact = NULL;
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
goto cleanup;
}
image_rel = dc_param_get(chat->param, DC_PARAM_PROFILE_IMAGE, NULL);
if (image_rel && image_rel[0]) {
image_abs = dc_get_abs_path(chat->context, image_rel);
}
else if(chat->type==DC_CHAT_TYPE_SINGLE) {
contacts = dc_get_chat_contacts(chat->context, chat->id);
if (contacts->count >= 1) {
contact = dc_get_contact(chat->context, contacts->array[0]);
image_abs = dc_contact_get_profile_image(contact);
}
}
cleanup:
free(image_rel);
dc_array_unref(contacts);
dc_contact_unref(contact);
return image_abs;
}
/**
* Get a color for the chat.
* For 1:1 chats, the color is calculated from the contact's email address.
* Otherwise, the chat name is used.
* The color can be used for an fallback avatar with white initials
* as well as for headlines in bubbles of group chats.
*
* @memberof dc_chat_t
* @param chat The chat object.
* @return Color as 0x00rrggbb with rr=red, gg=green, bb=blue
* each in the range 0-255.
*/
uint32_t dc_chat_get_color(const dc_chat_t* chat)
{
uint32_t color = 0;
dc_array_t* contacts = NULL;
dc_contact_t* contact = NULL;
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
goto cleanup;
}
if(chat->type==DC_CHAT_TYPE_SINGLE) {
contacts = dc_get_chat_contacts(chat->context, chat->id);
if (contacts->count >= 1) {
contact = dc_get_contact(chat->context, contacts->array[0]);
color = dc_str_to_color(contact->addr);
}
}
else {
color = dc_str_to_color(chat->name);
}
cleanup:
dc_array_unref(contacts);
dc_contact_unref(contact);
return color;
}
/**
* Get archived state.
*
* - 0 = normal chat, not archived, not sticky.
* - 1 = chat archived
* - 2 = chat sticky (reserved for future use, if you do not support this value, just treat the chat as a normal one)
*
* To archive or unarchive chats, use dc_archive_chat().
* If chats are archived, this should be shown in the UI by a little icon or text,
* eg. the search will also return archived chats.
*
* @memberof dc_chat_t
* @param chat The chat object.
* @return Archived state.
*/
int dc_chat_get_archived(const dc_chat_t* chat)
{