From c278145081e54b0470aa3b5fdfcdf1d9b220699c Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 20 Nov 2017 16:19:56 +0100 Subject: [PATCH] Comment --- cmdline/cmdline.c | 2 +- src/mrchat.h | 1 + src/mrmailbox.c | 2 + src/mrmsg.c | 561 +++++++++++++++++++++++++++------------------- src/mrmsg.h | 64 ++---- 5 files changed, 355 insertions(+), 275 deletions(-) diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 51ea7bd7..adb98ec0 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -216,7 +216,7 @@ static void log_msglist(mrmailbox_t* mailbox, mrarray_t* msglist) contact_name, contact_id, msg->m_text, - mrmsg_show_padlock(msg)? "\xF0\x9F\x94\x92" : "", + mrmsg_get_showpadlock(msg)? "\xF0\x9F\x94\x92" : "", msg->m_starred? " \xE2\x98\x85" : "", msg->m_from_id==1? "" : (msg->m_state==MR_STATE_IN_SEEN? "[SEEN]" : (msg->m_state==MR_STATE_IN_NOTICED? "[NOTICED]":"[FRESH]")), mrparam_get_int(msg->m_param, MRP_SYSTEM_CMD, 0)? "[SYSTEM]" : "", diff --git a/src/mrchat.h b/src/mrchat.h index 0971fdb6..3f1f0cfa 100644 --- a/src/mrchat.h +++ b/src/mrchat.h @@ -140,6 +140,7 @@ typedef struct mrchat_t mrchat_t* mrchat_new (mrmailbox_t*); void mrchat_empty (mrchat_t*); void mrchat_unref (mrchat_t*); + char* mrchat_get_subtitle (mrchat_t*); /* library-internal */ diff --git a/src/mrmailbox.c b/src/mrmailbox.c index 4cee8712..10b1184c 100644 --- a/src/mrmailbox.c +++ b/src/mrmailbox.c @@ -3078,6 +3078,8 @@ cleanup: * sending may be delayed eg. due to network problems. However, from your * view, you're done with the message. Sooner or later it will find its way. * + * To send messages of other types, see mrmailbox_send_msg(). + * * @memberof mrmailbox_t * * @param mailbox The mailbox object as returned from mrmailbox_new(). diff --git a/src/mrmsg.c b/src/mrmsg.c index b93d4402..7a76702f 100644 --- a/src/mrmsg.c +++ b/src/mrmsg.c @@ -110,7 +110,6 @@ void mrmsg_empty(mrmsg_t* msg) /** * Set the type of a message. - * Possible types are MR_MSG_TEXT, MR_MSG_IMAGE, MR_MSG_GIF,MR_MSG_AUDIO,, MR_MSG_VOICE, MR_MSG_VIDEO or MR_MSG_FILE. * * See mrmailbox_send_msg() for some examples. * @@ -119,6 +118,8 @@ void mrmsg_empty(mrmsg_t* msg) * @param msg The message object to modify. * * @param type Type to set for the message. + * Possible types are MR_MSG_TEXT (10), MR_MSG_IMAGE (20), MR_MSG_GIF (21), + * MR_MSG_AUDIO (40), MR_MSG_VOICE (41), MR_MSG_VIDEO (50) or MR_MSG_FILE (60). * * @return None. */ @@ -132,28 +133,6 @@ void mrmsg_set_type(mrmsg_t* msg, int type) } -/** - * Set the file belonging to a message. - * The file may be an image, a video, an audio file, an PDF and so on. - * This function is a shortcut for mrparam_set(msg->m_param, MRP_FILE, file) - * - * @memberof mrmsg_t - * - * @param msg The message object to modify. - * - * @param file Path, filename and extension to set for the given message. - * - * @return None. - */ -void mrmsg_set_file(mrmsg_t* msg, const char* file) -{ - if( msg == NULL ) { - return; - } - mrparam_set(msg->m_param, MRP_FILE, file); -} - - /** * Set the text of a message object. * @@ -183,58 +162,315 @@ void mrmsg_set_text(mrmsg_t* msg, const char* text) /** - * Guess message type from suffix. + * Set the file belonging to a message. + * The file may be an image, a video, an audio file, an PDF and so on. + * This function is a shortcut for mrparam_set(msg->m_param, MRP_FILE, file) * - * @private @memberof mrmsg_t + * @memberof mrmsg_t * - * @param pathNfilename Path and filename of the file to guess the type for. + * @param msg The message object to modify. * - * @param[out] ret_msgtype Guessed message type is copied here as one of the MR_MSG_* constants. + * @param file Path, filename and extension to set for the given message. * - * @param[out] ret_mime The pointer to a string buffer is set to the guessed MIME-type. May be NULL. Must be free()'d by the caller. - * - * @return None. But there are output parameters. + * @return None. */ -void mrmsg_guess_msgtype_from_suffix(const char* pathNfilename, int* ret_msgtype, char** ret_mime) +void mrmsg_set_file(mrmsg_t* msg, const char* file) { - if( pathNfilename == NULL || ret_msgtype == NULL || ret_mime == NULL) { + if( msg == NULL ) { return; } + mrparam_set(msg->m_param, MRP_FILE, file); +} - *ret_msgtype = MR_MSG_UNDEFINED; - *ret_mime = NULL; - char* s = mr_get_filesuffix_lc(pathNfilename); - if( s == NULL ) { +/******************************************************************************* + * Getters + ******************************************************************************/ + + +/** + * Get the type of the message. + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @return One of MR_MSG_TEXT (10), MR_MSG_IMAGE (20), MR_MSG_GIF (21), + * MR_MSG_AUDIO (40), MR_MSG_VOICE (41), MR_MSG_VIDEO (50), MR_MSG_FILE (60) + * or MR_MSG_UNDEFINED (0) if the type is undefined. + */ +int mrmsg_get_type(mrmsg_t* msg) +{ + if( msg == NULL ) { + return MR_MSG_UNDEFINED; + } + return msg->m_type; +} + + +/** + * Get the state of a message. + * + * Incoming message states: + * - MR_STATE_IN_FRESH (10) - Incoming _fresh_ message. Fresh messages are not noticed nor seen and are typically shown in notifications. Use mrmailbox_get_fresh_msgs() to get all fresh messages. + * - MR_STATE_IN_NOTICED (13) - Incoming _noticed_ message. Eg. chat opened but message not yet read - noticed messages are not counted as unread but did not marked as read nor resulted in MDNs. Use mrmailbox_marknoticed_chat() or mrmailbox_marknoticed_contact() to mark messages as being noticed. + * - MR_STATE_IN_SEEN (16) - Incoming message, really _seen_ by the user. Marked as read on IMAP and MDN may be send. Use mrmailbox_markseen_msgs() to mark messages as being seen. + * + * Outgoing message states: + * - MR_STATE_OUT_PENDING (20) - The user has send the "send" button but the + * message is not yet sent and is pending in some way. Maybe we're offline (no checkmark). + * - MR_STATE_OUT_ERROR (24) - _Unrecoverable_ error (_recoverable_ errors result in pending messages) + * - MR_STATE_OUT_DELIVERED (26) - Outgoing message successfully delivered to server (one checkmark). Note, that already delivered messages may get into the state MR_STATE_OUT_ERROR if we get such a hint from the server. + * If a sent message changes to this state, you'll receive the event #MR_EVENT_MSG_DELIVERED. + * - MR_STATE_OUT_MDN_RCVD (28) - Outgoing message read by the recipient (two checkmarks; this requires goodwill on the receiver's side) + * If a sent message changes to this state, you'll receive the event #MR_EVENT_MSG_READ. + * + * The state of just created message objects is MR_STATE_UNDEFINED (0). + * The state is always set by the core-library, users of the library cannot set the state directly, but it is changed implicitly eg. + * when calling mrmailbox_marknoticed_chat() or mrmailbox_markseen_msgs(). + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @return The state of the message. + */ +int mrmsg_get_state(mrmsg_t* msg) +{ + if( msg == NULL ) { + return MR_STATE_UNDEFINED; + } + return msg->m_state; +} + + +/** + * Get the text of the message. + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @return Message text. The result must be free()'d. + */ +char* mrmsg_get_text(mrmsg_t* msg) +{ + return safe_strdup(msg? msg->m_text : NULL); +} + + +/** + * Find out full path, file name and extension of the file associated with a + * message. + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @return Full path, file name and extension of the file associated with the + * message. If there is no file associated with the message, an emtpy + * string is returned. NULL is never returned and the returned value must be free()'d. + */ +char* mrmsg_get_file(mrmsg_t* msg) +{ + char* ret = NULL; + + if( msg == NULL ) { goto cleanup; } - if( strcmp(s, "mp3")==0 ) { - *ret_msgtype = MR_MSG_AUDIO; - *ret_mime = safe_strdup("audio/mpeg"); + ret = mrparam_get(msg->m_param, MRP_FILE, NULL); + +cleanup: + return ret? ret : safe_strdup(NULL); +} + + +/** + * Get base file name without path. The base file name includes the extension; the path + * is not returned. To get the full path, use mrmsg_get_file(). + * + * @param msg the message object + * + * @return base file name plus extension without part. If there is no file + * associated with the message, an empty string is returned. The returned + * value must be free()'d. + */ +char* mrmsg_get_filename(mrmsg_t* msg) +{ + char* ret = NULL, *pathNfilename = NULL; + + if( msg == NULL ) { + goto cleanup; } - else if( strcmp(s, "mp4")==0 ) { - *ret_msgtype = MR_MSG_VIDEO; - *ret_mime = safe_strdup("video/mp4"); + + pathNfilename = mrparam_get(msg->m_param, MRP_FILE, NULL); + if( pathNfilename == NULL ) { + goto cleanup; } - else if( strcmp(s, "jpg")==0 || strcmp(s, "jpeg")==0 ) { - *ret_msgtype = MR_MSG_IMAGE; - *ret_mime = safe_strdup("image/jpeg"); + + ret = mr_get_filename(pathNfilename); + +cleanup: + free(pathNfilename); + return ret? ret : safe_strdup(NULL); +} + + +/** + * Get real author and title. + * + * - For voice messages, the author is the sender and the trackname is the sending time. + * - For music messages and videos, we read the information from the filename + * (we do not read ID3 and such at this stage, the needed libraries are too complicated and oversized. + * However, this is no big problem, as the sender usually sets the filename in a way we expect it) + * + * @memberof mrmsg_t + * + * @param msg the message object + * + * @return mrpoortext_t object that contains the author as mrpoortext_t::m_text1 and the title as mrpoortext_t::m_text2. + * Both may be NULL if unknown. The returned object must be freed using mrpoortext_unref() when no longer used. + */ +mrpoortext_t* mrmsg_get_mediainfo(mrmsg_t* msg) +{ + mrpoortext_t* ret = mrpoortext_new(); + char *pathNfilename = NULL; + mrcontact_t* contact = NULL; + + if( msg == NULL || msg->m_mailbox == NULL ) { + goto cleanup; } - else if( strcmp(s, "png")==0 ) { - *ret_msgtype = MR_MSG_IMAGE; - *ret_mime = safe_strdup("image/png"); + + if( msg->m_type == MR_MSG_VOICE ) + { + if( (contact = mrmailbox_get_contact(msg->m_mailbox, msg->m_from_id))==NULL ) { + goto cleanup; + } + ret->m_text1 = safe_strdup((contact->m_name&&contact->m_name[0])? contact->m_name : contact->m_addr); + ret->m_text2 = mrstock_str(MR_STR_VOICEMESSAGE); } - else if( strcmp(s, "gif")==0 ) { - *ret_msgtype = MR_MSG_GIF; - *ret_mime = safe_strdup("image/gif"); + else + { + ret->m_text1 = mrparam_get(msg->m_param, MRP_AUTHORNAME, NULL); + ret->m_text2 = mrparam_get(msg->m_param, MRP_TRACKNAME, NULL); + if( ret->m_text1 && ret->m_text1[0] && ret->m_text2 && ret->m_text2[0] ) { + goto cleanup; + } + free(ret->m_text1); ret->m_text1 = NULL; + free(ret->m_text2); ret->m_text2 = NULL; + + pathNfilename = mrparam_get(msg->m_param, MRP_FILE, NULL); + if( pathNfilename == NULL ) { + goto cleanup; + } + mrmsg_get_authorNtitle_from_filename(pathNfilename, &ret->m_text1, &ret->m_text2); + if( ret->m_text1 == NULL && ret->m_text2 != NULL ) { + ret->m_text1 = mrstock_str(MR_STR_AUDIO); + } } cleanup: - free(s); + free(pathNfilename); + mrcontact_unref(contact); + return ret; } +/** + * Check if a padlock should be shown beside the message. + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @return 1=padlock should be shown beside message, 0=do not show a padlock beside the message. + */ +int mrmsg_get_showpadlock(mrmsg_t* msg) +{ + /* a padlock guarantees that the message is e2ee _and_ answers will be as well */ + if( msg != NULL ) { + if( msg->m_mailbox && msg->m_mailbox->m_e2ee_enabled ) { + if( mrparam_get_int(msg->m_param, MRP_GUARANTEE_E2EE, 0) != 0 ) { + return 1; + } + } + } + return 0; +} + + +/** + * Get a summary for a message. + * Typically used to display a search result. + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @param chat To speed up things, pass an already available chat object here. + * If the chat object is not yet available, it is faster to pass NULL. + * + * @return The returned summary is similar to mrchatlist_get_summary(), however, without + * "draft", "no messages" and so on. The result must be freed using mrpoortext_unref(). + */ +mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, mrchat_t* chat) +{ + mrpoortext_t* ret = mrpoortext_new(); + mrcontact_t* contact = NULL; + mrchat_t* chat_to_delete = NULL; + + if( msg==NULL ) { + goto cleanup; + } + + if( chat == NULL ) { + if( (chat=mrmailbox_get_chat(msg->m_mailbox, msg->m_chat_id)) == NULL ) { + goto cleanup; + } + chat_to_delete = chat; + } + + if( msg->m_from_id != MR_CONTACT_ID_SELF && chat->m_type == MR_CHAT_TYPE_GROUP ) { + contact = mrmailbox_get_contact(chat->m_mailbox, msg->m_from_id); + } + + mrpoortext_fill(ret, msg, chat, contact); + +cleanup: + mrcontact_unref(contact); + mrchat_unref(chat_to_delete); + return ret; +} + + +/** + * Get a message summary as a single line of text. Typically used for + * notifications. + * + * @memberof mrmsg_t + * + * @param msg The message object. + * + * @param approx_characters Rough length of the expected string. + * + * @return A summary for the given messages. The returned string must be free()'d. + */ +char* mrmsg_get_summarytext(mrmsg_t* msg, int approx_characters) +{ + if( msg==NULL ) { + return safe_strdup(NULL); + } + + return mrmsg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, approx_characters); +} + + +/******************************************************************************* + * Misc. + ******************************************************************************/ + + int mrmsg_set_from_stmt__(mrmsg_t* ths, sqlite3_stmt* row, int row_offset) /* field order must be MR_MSG_FIELDS */ { mrmsg_empty(ths); @@ -299,66 +535,55 @@ int mrmsg_load_from_db__(mrmsg_t* ths, mrmailbox_t* mailbox, uint32_t id) /** - * Get a summary for a message. The last parameter can be set to speed up - * things if the chat object is already available; if not, it is faster to pass - * NULL here. The result must be freed using mrpoortext_unref(). - * Typically used to display a search result. + * Guess message type from suffix. * - * @memberof mrmsg_t + * @private @memberof mrmsg_t * - * @return The returned summary is similar to mrchatlist_get_summary(), however, without - * "draft", "no messages" and so on. + * @param pathNfilename Path and filename of the file to guess the type for. + * + * @param[out] ret_msgtype Guessed message type is copied here as one of the MR_MSG_* constants. + * + * @param[out] ret_mime The pointer to a string buffer is set to the guessed MIME-type. May be NULL. Must be free()'d by the caller. + * + * @return None. But there are output parameters. */ -mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, mrchat_t* chat) +void mrmsg_guess_msgtype_from_suffix(const char* pathNfilename, int* ret_msgtype, char** ret_mime) { - mrpoortext_t* ret = mrpoortext_new(); - mrcontact_t* contact = NULL; - mrchat_t* chat_to_delete = NULL; + if( pathNfilename == NULL || ret_msgtype == NULL || ret_mime == NULL) { + return; + } - if( msg==NULL ) { + *ret_msgtype = MR_MSG_UNDEFINED; + *ret_mime = NULL; + + char* s = mr_get_filesuffix_lc(pathNfilename); + if( s == NULL ) { goto cleanup; } - if( chat == NULL ) { - if( (chat=mrmailbox_get_chat(msg->m_mailbox, msg->m_chat_id)) == NULL ) { - goto cleanup; - } - chat_to_delete = chat; + if( strcmp(s, "mp3")==0 ) { + *ret_msgtype = MR_MSG_AUDIO; + *ret_mime = safe_strdup("audio/mpeg"); } - - if( msg->m_from_id != MR_CONTACT_ID_SELF && chat->m_type == MR_CHAT_TYPE_GROUP ) { - contact = mrmailbox_get_contact(chat->m_mailbox, msg->m_from_id); + else if( strcmp(s, "mp4")==0 ) { + *ret_msgtype = MR_MSG_VIDEO; + *ret_mime = safe_strdup("video/mp4"); + } + else if( strcmp(s, "jpg")==0 || strcmp(s, "jpeg")==0 ) { + *ret_msgtype = MR_MSG_IMAGE; + *ret_mime = safe_strdup("image/jpeg"); + } + else if( strcmp(s, "png")==0 ) { + *ret_msgtype = MR_MSG_IMAGE; + *ret_mime = safe_strdup("image/png"); + } + else if( strcmp(s, "gif")==0 ) { + *ret_msgtype = MR_MSG_GIF; + *ret_mime = safe_strdup("image/gif"); } - - mrpoortext_fill(ret, msg, chat, contact); cleanup: - mrcontact_unref(contact); - mrchat_unref(chat_to_delete); - return ret; -} - - -/** - * Check if a padlock should be shown beside the message. - * - * @memberof mrmsg_t - * - * @param msg The message object. - * - * @return 1=padlock should be shown beside message, 0=do not show a padlock beside the message. - */ -int mrmsg_show_padlock(mrmsg_t* msg) -{ - /* a padlock guarantees that the message is e2ee _and_ answers will be as well */ - if( msg != NULL ) { - if( msg->m_mailbox && msg->m_mailbox->m_e2ee_enabled ) { - if( mrparam_get_int(msg->m_param, MRP_GUARANTEE_E2EE, 0) != 0 ) { - return 1; - } - } - } - return 0; + free(s); } @@ -380,22 +605,6 @@ void mrmsg_get_authorNtitle_from_filename(const char* pathNfilename, char** ret_ } -/** - * Get a message summary as a single line of text. Typically used for - * notifications. The returned value must be free()'d. - * - * @memberof mrmsg_t - */ -char* mrmsg_get_summarytext(mrmsg_t* msg, int approx_characters) -{ - if( msg==NULL ) { - return safe_strdup(NULL); - } - - return mrmsg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, approx_characters); -} - - char* mrmsg_get_summarytext_by_raw(int type, const char* text, mrparam_t* param, int approx_characters) { char* ret = NULL; @@ -453,124 +662,6 @@ char* mrmsg_get_summarytext_by_raw(int type, const char* text, mrparam_t* param, } -/** - * Find out full path, file name and extension of the file associated with a - * message. - * - * @param msg the message object - * - * @return full path, file name and extension of the file associated with the - * message. If there is no file associated with the message, an emtpy - * string is returned. The returned value must be free()'d. - */ -char* mrmsg_get_file(mrmsg_t* msg) -{ - char* ret = NULL; - - if( msg == NULL ) { - goto cleanup; - } - - ret = mrparam_get(msg->m_param, MRP_FILE, NULL); - -cleanup: - return ret? ret : safe_strdup(NULL); -} - - -/** - * Get base file name without path. The base file name includes the extension; the path - * is not returned. To get the full path, use mrmsg_get_file(). - * - * @param msg the message object - * - * @return base file name plus extension without part. If there is no file - * associated with the message, an empty string is returned. The returned - * value must be free()'d. - */ -char* mrmsg_get_filename(mrmsg_t* msg) -{ - char* ret = NULL, *pathNfilename = NULL; - - if( msg == NULL ) { - goto cleanup; - } - - pathNfilename = mrparam_get(msg->m_param, MRP_FILE, NULL); - if( pathNfilename == NULL ) { - goto cleanup; - } - - ret = mr_get_filename(pathNfilename); - -cleanup: - free(pathNfilename); - return ret? ret : safe_strdup(NULL); -} - - -/** - * Get real author and title. (as return.text1, this is not always the sender, NULL if - * unknown) and title (return.text2, NULL if unknown) of a message. - * - * For voice messages, the author the sender and the trackname is the sending time - * For music messages, we read the information from the filename - * We do not read ID3 and such at this stage, the needed libraries may be buggy - * and the whole stuff is way to complicated. - * However, this is not a great disadvantage, as the sender usually sets the filename in a way we expect it - - * if not, we simply print the whole filename as we do it for documents. All fine in any case :-) - * - * @memberof mrmsg_t - * - * @param msg the message object - * - * @return poortext object that must be unref'd using mrpoortext_unref() when no longer used. - */ -mrpoortext_t* mrmsg_get_mediainfo(mrmsg_t* msg) -{ - mrpoortext_t* ret = mrpoortext_new(); - char *pathNfilename = NULL; - mrcontact_t* contact = NULL; - - if( msg == NULL || msg->m_mailbox == NULL ) { - goto cleanup; - } - - if( msg->m_type == MR_MSG_VOICE ) - { - if( (contact = mrmailbox_get_contact(msg->m_mailbox, msg->m_from_id))==NULL ) { - goto cleanup; - } - ret->m_text1 = safe_strdup((contact->m_name&&contact->m_name[0])? contact->m_name : contact->m_addr); - ret->m_text2 = mrstock_str(MR_STR_VOICEMESSAGE); - } - else - { - ret->m_text1 = mrparam_get(msg->m_param, MRP_AUTHORNAME, NULL); - ret->m_text2 = mrparam_get(msg->m_param, MRP_TRACKNAME, NULL); - if( ret->m_text1 && ret->m_text1[0] && ret->m_text2 && ret->m_text2[0] ) { - goto cleanup; - } - free(ret->m_text1); ret->m_text1 = NULL; - free(ret->m_text2); ret->m_text2 = NULL; - - pathNfilename = mrparam_get(msg->m_param, MRP_FILE, NULL); - if( pathNfilename == NULL ) { - goto cleanup; - } - mrmsg_get_authorNtitle_from_filename(pathNfilename, &ret->m_text1, &ret->m_text2); - if( ret->m_text1 == NULL && ret->m_text2 != NULL ) { - ret->m_text1 = mrstock_str(MR_STR_AUDIO); - } - } - -cleanup: - free(pathNfilename); - mrcontact_unref(contact); - return ret; -} - - int mrmsg_is_increation__(const mrmsg_t* msg) { int is_increation = 0; @@ -596,6 +687,8 @@ int mrmsg_is_increation__(const mrmsg_t* msg) * `` is created then, the user should just delete * `.increation` * + * @memberof mrmsg_t + * * @param msg the message object * * @return 1=message is still in creation (`.increation` exists), diff --git a/src/mrmsg.h b/src/mrmsg.h index 5561eabc..701281d5 100644 --- a/src/mrmsg.h +++ b/src/mrmsg.h @@ -83,47 +83,21 @@ typedef struct mrmsg_t /** - * Type of the message. - * - * - MR_MSG_TEXT (10) - * - MR_MSG_IMAGE (20) - #m_param may contain MRP_FILE, MRP_WIDTH, MRP_HEIGHT - * - MR_MSG_GIF (21) - #m_param may contain MRP_FILE, MRP_WIDTH, MRP_HEIGHT - * - MR_MSG_AUDIO (40) - #m_param may contain MRP_FILE, MRP_DURATION - * - MR_MSG_VOICE (41) - #m_param may contain MRP_FILE, MRP_DURATION - * - MR_MSG_VIDEO (50) - #m_param may contain MRP_FILE, MRP_WIDTH, MRP_HEIGHT, MRP_DURATION - * - MR_MSG_FILE (60) - #m_param may contain MRP_FILE - * - * Undefined types are filed under MR_MSG_UNDEFINED (0). + * Message type. It is recommended to use mrmsg_set_type() and mrmsg_get_type() to access this field. */ int m_type; #define MR_MSG_UNDEFINED 0 #define MR_MSG_TEXT 10 - #define MR_MSG_IMAGE 20 - #define MR_MSG_GIF 21 - #define MR_MSG_AUDIO 40 - #define MR_MSG_VOICE 41 - #define MR_MSG_VIDEO 50 - #define MR_MSG_FILE 60 + #define MR_MSG_IMAGE 20 /* m_param may contain MRP_FILE, MRP_WIDTH, MRP_HEIGHT */ + #define MR_MSG_GIF 21 /* - " - */ + #define MR_MSG_AUDIO 40 /* m_param may contain MRP_FILE, MRP_DURATION */ + #define MR_MSG_VOICE 41 /* - " - */ + #define MR_MSG_VIDEO 50 /* m_param may contain MRP_FILE, MRP_WIDTH, MRP_HEIGHT, MRP_DURATION */ + #define MR_MSG_FILE 60 /* m_param may contain MRP_FILE */ /** - * Message state. - * - * Incoming message states: - * - MR_STATE_IN_FRESH (10) - Incoming _fresh_ message. Fresh messages are not noticed nor seen and are typically shown in notifications. Use mrmailbox_get_fresh_msgs() to get all fresh messages. - * - MR_STATE_IN_NOTICED (13) - Incoming _noticed_ message. Eg. chat opened but message not yet read - noticed messages are not counted as unread but did not marked as read nor resulted in MDNs. Use mrmailbox_marknoticed_chat() or mrmailbox_marknoticed_contact() to mark messages as being noticed. - * - MR_STATE_IN_SEEN (16) - Incoming message, really _seen_ by the user. Marked as read on IMAP and MDN may be send. Use mrmailbox_markseen_msgs() to mark messages as being seen. - * - * Outgoing message states: - * - MR_STATE_OUT_PENDING (20) - The user has send the "send" button but the - * message is not yet sent and is pending in some way. Maybe we're offline (no checkmark). - * - MR_STATE_OUT_ERROR (24) - _Unrecoverable_ error (_recoverable_ errors result in pending messages) - * - MR_STATE_OUT_DELIVERED (26) - Outgoing message successfully delivered to server (one checkmark). Note, that already delivered messages may get into the state MR_STATE_OUT_ERROR if we get such a hint from the server. - * If a sent message changes to this state, you'll receive the event #MR_EVENT_MSG_DELIVERED. - * - MR_STATE_OUT_MDN_RCVD (28) - Outgoing message read by the recipient (two checkmarks; this requires goodwill on the receiver's side) - * If a sent message changes to this state, you'll receive the event #MR_EVENT_MSG_READ. - * - * The state of just created message objects is MR_STATE_UNDEFINED (0). + * Message state. It is recommended to use mrmsg_get_state() to access this field. */ int m_state; #define MR_STATE_UNDEFINED 0 @@ -135,12 +109,18 @@ typedef struct mrmsg_t #define MR_STATE_OUT_DELIVERED 26 #define MR_STATE_OUT_MDN_RCVD 28 - char* m_text; /**< message text or NULL if unset */ - mrparam_t* m_param; /**< Additional paramter for the message. MRP_FILE, MRP_WIDTH, MRP_HEIGHT etc. depends on #m_type. Never a NULL-pointer. */ + /** + * Message text. NULL if unset. It is recommended to use + * mrmsg_set_text() and mrmsg_get_text() to access this field. + */ + char* m_text; + + mrparam_t* m_param; /**< Additional paramter for the message. MRP_FILE, MRP_WIDTH, MRP_HEIGHT etc. depends on the type. Never a NULL-pointer. */ int m_starred; /**< Starred-state of the message. 0=no, 1=yes. */ int m_is_msgrmsg; /**< Set to 1 if the message was sent by another messenger. 0 otherwise. */ /** @privatesection */ + mrmailbox_t* m_mailbox; /**< may be NULL, set on loading from database and on sending */ char* m_rfc724_mid; /**< The RFC-742 Message-ID */ char* m_server_folder; /**< Folder where the message was last seen on the server */ @@ -153,15 +133,19 @@ void mrmsg_unref (mrmsg_t*); void mrmsg_empty (mrmsg_t*); void mrmsg_set_type (mrmsg_t*, int type); -void mrmsg_set_file (mrmsg_t*, const char* file); void mrmsg_set_text (mrmsg_t*, const char* text); +void mrmsg_set_file (mrmsg_t*, const char* file); -mrpoortext_t* mrmsg_get_summary (mrmsg_t*, mrchat_t*); -char* mrmsg_get_summarytext (mrmsg_t*, int approx_characters); -int mrmsg_show_padlock (mrmsg_t*); +int mrmsg_get_type (mrmsg_t*); +int mrmsg_get_state (mrmsg_t*); +char* mrmsg_get_text (mrmsg_t*); char* mrmsg_get_file (mrmsg_t*); char* mrmsg_get_filename (mrmsg_t*); mrpoortext_t* mrmsg_get_mediainfo (mrmsg_t*); +int mrmsg_get_showpadlock (mrmsg_t*); +mrpoortext_t* mrmsg_get_summary (mrmsg_t*, mrchat_t*); +char* mrmsg_get_summarytext (mrmsg_t*, int approx_characters); + int mrmsg_is_increation (mrmsg_t*); void mrmsg_save_param_to_disk (mrmsg_t*);