1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 02:29:28 +02:00

add a function to get the profile image of a chat easily.

This commit is contained in:
B. Petersen 2017-11-21 16:30:19 +01:00
parent 5154f2f12e
commit 9311a78db2
6 changed files with 47 additions and 18 deletions

View file

@ -684,7 +684,7 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline)
else if( strcmp(cmd, "groupimage")==0 )
{
if( sel_chat ) {
ret = mrmailbox_set_chat_image(mailbox, sel_chat->m_id, (arg1&&arg1[0])?arg1:NULL)? COMMAND_SUCCEEDED : COMMAND_FAILED;
ret = mrmailbox_set_chat_profile_image(mailbox, sel_chat->m_id, (arg1&&arg1[0])?arg1:NULL)? COMMAND_SUCCEEDED : COMMAND_FAILED;
}
else {
ret = safe_strdup("No chat selected.");

View file

@ -107,8 +107,35 @@ void mrchat_empty(mrchat_t* chat)
}
/*******************************************************************************
* Getters
******************************************************************************/
/**
* Get a subtitle for a chat. The sibtitle is eg. the email-address or the
* Get the chat's profile image.
* The profile image is set using mrmailbox_set_chat_profile_image() for groups.
* For normal chats, the profile image is set using mrmailbox_set_contact_profile_image() (not yet implemented).
*
* @memberof mrchat_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* mrchat_get_profile_image(mrchat_t* chat)
{
if( chat == NULL ) {
return NULL;
}
return mrparam_get(chat->m_param, MRP_PROFILE_IMAGE, NULL);
}
/**
* Get a subtitle for a chat. The subtitle is eg. the email-address or the
* number of group members.
*
* @memberof mrchat_t
@ -177,6 +204,11 @@ char* mrchat_get_subtitle(mrchat_t* chat)
}
/*******************************************************************************
* Misc.
******************************************************************************/
int mrchat_update_param__(mrchat_t* ths)
{
int success = 0;

View file

@ -125,15 +125,9 @@ typedef struct mrchat_t
*/
int m_archived;
/**
* Additional parameters for the chat.
*
* To access the parameters, use mrparam_exists(), mrparam_get() for mrparam_get_int()
*/
mrparam_t* m_param;
/** @privatesection */
char* m_grpid; /* NULL if unset */
char* m_grpid; /**< Group ID that is used by all clients. Only used if the chat is a group. NULL if unset */
mrparam_t* m_param; /**< Additional parameters for a chat. Should not be used directly. */
} mrchat_t;
@ -141,6 +135,7 @@ mrchat_t* mrchat_new (mrmailbox_t*);
void mrchat_empty (mrchat_t*);
void mrchat_unref (mrchat_t*);
char* mrchat_get_profile_image (mrchat_t*);
char* mrchat_get_subtitle (mrchat_t*);
/* library-internal */

View file

@ -136,7 +136,7 @@ extern "C" {
/**
* Group changed. The name or the image of a chat group was changed or members were added or removed.
* See mrmailbox_set_chat_name(), mrmailbox_set_chat_image(), mrmailbox_add_contact_to_chat()
* See mrmailbox_set_chat_name(), mrmailbox_set_chat_profile_image(), mrmailbox_add_contact_to_chat()
* and mrmailbox_remove_contact_from_chat().
*
* @param data1 chat_id

View file

@ -3475,13 +3475,15 @@ cleanup:
/**
* Set group image.
* Set group profile image.
*
* If the group is already _promoted_ (any message was sent to the group),
* all group members are informed by a special status message that is sent automatically by this function.
*
* Sends out #MR_EVENT_CHAT_MODIFIED and #MR_EVENT_MSGS_CHANGED if a status message was sent.
*
* To find out the profile image of a chat, use mrchat_get_profile_image()
*
* @memberof mrmailbox_t
*
* @param mailbox Mailbox object as created by mrmailbox_new().
@ -3493,7 +3495,7 @@ cleanup:
*
* @return 1=success, 0=error
*/
int mrmailbox_set_chat_image(mrmailbox_t* mailbox, uint32_t chat_id, const char* new_image /*NULL=remove image*/)
int mrmailbox_set_chat_profile_image(mrmailbox_t* mailbox, uint32_t chat_id, const char* new_image /*NULL=remove image*/)
{
int success = 0, locked = 0;;
mrchat_t* chat = mrchat_new(mailbox);

View file

@ -277,12 +277,12 @@ mrchat_t* mrmailbox_get_chat (mrmailbox_t*, uint32_t chat_id);
/* Handle group chats */
uint32_t mrmailbox_create_group_chat (mrmailbox_t*, const char* name);
int mrmailbox_is_contact_in_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
int mrmailbox_add_contact_to_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
uint32_t mrmailbox_create_group_chat (mrmailbox_t*, const char* name);
int mrmailbox_is_contact_in_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
int mrmailbox_add_contact_to_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
int mrmailbox_remove_contact_from_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
int mrmailbox_set_chat_name (mrmailbox_t*, uint32_t chat_id, const char* name);
int mrmailbox_set_chat_image (mrmailbox_t*, uint32_t chat_id, const char* image);
int mrmailbox_set_chat_name (mrmailbox_t*, uint32_t chat_id, const char* name);
int mrmailbox_set_chat_profile_image (mrmailbox_t*, uint32_t chat_id, const char* image);
/* Handle messages */