mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
hide implementation details of mrmsg_t
This commit is contained in:
parent
bebe6c53e1
commit
bc8c6d1738
6 changed files with 162 additions and 78 deletions
|
@ -198,30 +198,32 @@ static void log_msglist(mrmailbox_t* mailbox, mrarray_t* msglist)
|
|||
if( lines_out==0 ) { mrmailbox_log_info(mailbox, 0, "--------------------------------------------------------------------------------"); lines_out++; }
|
||||
|
||||
mrmsg_t* msg = mrmailbox_get_msg(mailbox, msg_id);
|
||||
mrcontact_t* contact = mrmailbox_get_contact(mailbox, msg->m_from_id);
|
||||
mrcontact_t* contact = mrmailbox_get_contact(mailbox, mrmsg_get_from_id(msg));
|
||||
const char* contact_name = (contact && contact->m_name)? contact->m_name : "ErrName";
|
||||
int contact_id = contact? contact->m_id : 0;
|
||||
|
||||
const char* statestr = "";
|
||||
switch( msg->m_state ) {
|
||||
switch( mrmsg_get_state(msg) ) {
|
||||
case MR_STATE_OUT_PENDING: statestr = " o"; break;
|
||||
case MR_STATE_OUT_DELIVERED: statestr = " √"; break;
|
||||
case MR_STATE_OUT_MDN_RCVD: statestr = " √√"; break;
|
||||
case MR_STATE_OUT_ERROR: statestr = " ERR"; break;
|
||||
}
|
||||
|
||||
char* temp2 = mr_timestamp_to_str(msg->m_timestamp);
|
||||
char* temp2 = mr_timestamp_to_str(mrmsg_get_timestamp(msg));
|
||||
char* msgtext = mrmsg_get_text(msg);
|
||||
mrmailbox_log_info(mailbox, 0, "Msg#%i: %s (Contact#%i): %s %s%s%s%s%s [%s]",
|
||||
(int)msg->m_id,
|
||||
(int)mrmsg_get_id(msg),
|
||||
contact_name,
|
||||
contact_id,
|
||||
msg->m_text,
|
||||
msgtext,
|
||||
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]")),
|
||||
mrmsg_is_starred(msg)? " \xE2\x98\x85" : "",
|
||||
mrmsg_get_from_id(msg)==1? "" : (mrmsg_get_state(msg)==MR_STATE_IN_SEEN? "[SEEN]" : (mrmsg_get_state(msg)==MR_STATE_IN_NOTICED? "[NOTICED]":"[FRESH]")),
|
||||
mrmsg_is_systemcmd(msg)? "[SYSTEM]" : "",
|
||||
statestr,
|
||||
temp2);
|
||||
free(msgtext);
|
||||
free(temp2);
|
||||
|
||||
mrcontact_unref(contact);
|
||||
|
|
|
@ -37,6 +37,7 @@ extern "C" {
|
|||
#include "mrchat-internal.h"
|
||||
#include "mrchatlist-internal.h"
|
||||
#include "mrlot-internal.h"
|
||||
#include "mrmsg-internal.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
|||
|
||||
|
||||
|
||||
typedef struct mrmsg_t mrmsg_t;
|
||||
typedef struct _mrmsg mrmsg_t;
|
||||
typedef struct _mrchat mrchat_t;
|
||||
typedef struct mrmailbox_t mrmailbox_t;
|
||||
|
||||
|
|
90
src/mrmsg-internal.h
Normal file
90
src/mrmsg-internal.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Delta Chat Core
|
||||
* Copyright (C) 2017 Björn Petersen
|
||||
* Contact: r10s@b44t.com, http://b44t.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see http://www.gnu.org/licenses/ .
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#ifndef __MRMSG_INTERNAL_H__
|
||||
#define __MRMSG_INTERNAL_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** the structure behind mrmsg_t */
|
||||
struct _mrmsg
|
||||
{
|
||||
/** @privatesection */
|
||||
|
||||
uint32_t m_magic;
|
||||
|
||||
/**
|
||||
* Message ID. Never 0.
|
||||
*/
|
||||
uint32_t m_id;
|
||||
|
||||
|
||||
/**
|
||||
* Contact ID of the sender. Never 0. See mrcontact_t::m_id for special IDs.
|
||||
* Use mrmailbox_get_contact() to load details about this contact.
|
||||
*/
|
||||
uint32_t m_from_id;
|
||||
|
||||
|
||||
/**
|
||||
* Contact ID of the recipient. Never 0. See mrcontact_t::m_id for special IDs.
|
||||
* Use mrmailbox_get_contact() to load details about this contact.
|
||||
*/
|
||||
uint32_t m_to_id;
|
||||
|
||||
|
||||
/**
|
||||
* Chat ID the message belongs to. Never 0. See mrchat_t::m_id for special IDs.
|
||||
* Use mrmailbox_get_chat() to load details about the chat.
|
||||
*/
|
||||
uint32_t m_chat_id;
|
||||
|
||||
|
||||
/*
|
||||
* The mailbox object the chat belongs to. Never NULL.
|
||||
*/
|
||||
//mrmailbox_t* m_mailbox;
|
||||
|
||||
|
||||
int m_type; /**< Message type. It is recommended to use mrmsg_set_type() and mrmsg_get_type() to access this field. */
|
||||
|
||||
int m_state; /**< Message state. It is recommended to use mrmsg_get_state() to access this field. */
|
||||
|
||||
time_t m_timestamp; /**< Unix time the message was sended or received. 0 if unset. */
|
||||
char* m_text; /**< Message text. NULL if unset. It is recommended to use mrmsg_set_text() and mrmsg_get_text() to access this field. */
|
||||
|
||||
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 */
|
||||
uint32_t m_server_uid; /**< UID last seen on the server for this message */
|
||||
int m_is_msgrmsg; /**< Set to 1 if the message was sent by another messenger. 0 otherwise. */
|
||||
int m_starred; /**< Starred-state of the message. 0=no, 1=yes. */
|
||||
mrparam_t* m_param; /**< Additional paramter for the message. Never a NULL-pointer. It is recommended to use setters and getters instead of accessing this field directly. */
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* /extern "C" */
|
||||
#endif
|
||||
#endif /* __MRMSG_INTERNAL_H__ */
|
37
src/mrmsg.c
37
src/mrmsg.c
|
@ -113,6 +113,43 @@ void mrmsg_empty(mrmsg_t* msg)
|
|||
******************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* Get the ID of the message.
|
||||
*
|
||||
* @memberof mrmsg_t
|
||||
*
|
||||
* @param msg The message object.
|
||||
*
|
||||
* @return the ID of the message, 0 on errors.
|
||||
*/
|
||||
uint32_t mrmsg_get_id(mrmsg_t* msg)
|
||||
{
|
||||
if( msg == NULL || msg->m_magic != MR_MSG_MAGIC ) {
|
||||
return 0;
|
||||
}
|
||||
return msg->m_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the ID of contact who wrote the message.
|
||||
* To get details about the contact, pass the returned ID to mrmailbox_get_contact().
|
||||
*
|
||||
* @memberof mrmsg_t
|
||||
*
|
||||
* @param msg The message object.
|
||||
*
|
||||
* @return the ID of the contact who wrote the message, MR_CONTACT_ID_SELF (1) if this is an outgoing message, 0 on errors.
|
||||
*/
|
||||
uint32_t mrmsg_get_from_id(mrmsg_t* msg)
|
||||
{
|
||||
if( msg == NULL || msg->m_magic != MR_MSG_MAGIC ) {
|
||||
return 0;
|
||||
}
|
||||
return msg->m_from_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of the message.
|
||||
*
|
||||
|
|
94
src/mrmsg.h
94
src/mrmsg.h
|
@ -33,89 +33,43 @@ typedef struct sqlite3_stmt sqlite3_stmt;
|
|||
|
||||
|
||||
/**
|
||||
* @class mrmsg_t
|
||||
*
|
||||
* An object representing a single message in memory. The message
|
||||
* object is not updated. If you want an update, you have to recreate the
|
||||
* object.
|
||||
*/
|
||||
typedef struct mrmsg_t
|
||||
{
|
||||
uint32_t m_magic; /**< @private */
|
||||
typedef struct _mrmsg mrmsg_t;
|
||||
|
||||
/**
|
||||
* Message ID. Never 0.
|
||||
*/
|
||||
uint32_t m_id;
|
||||
#define MR_MSG_ID_MARKER1 1
|
||||
#define MR_MSG_ID_DAYMARKER 9
|
||||
#define MR_MSG_ID_LAST_SPECIAL 9
|
||||
#define MR_MSG_ID_MARKER1 1
|
||||
#define MR_MSG_ID_DAYMARKER 9
|
||||
#define MR_MSG_ID_LAST_SPECIAL 9
|
||||
|
||||
#define MR_MSG_UNDEFINED 0
|
||||
#define MR_MSG_TEXT 10
|
||||
#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 */
|
||||
|
||||
/**
|
||||
* Contact ID of the sender. Never 0. See mrcontact_t::m_id for special IDs.
|
||||
* Use mrmailbox_get_contact() to load details about this contact.
|
||||
*/
|
||||
uint32_t m_from_id;
|
||||
|
||||
|
||||
/**
|
||||
* Contact ID of the recipient. Never 0. See mrcontact_t::m_id for special IDs.
|
||||
* Use mrmailbox_get_contact() to load details about this contact.
|
||||
*/
|
||||
uint32_t m_to_id;
|
||||
|
||||
|
||||
/**
|
||||
* Chat ID the message belongs to. Never 0. See mrchat_t::m_id for special IDs.
|
||||
* Use mrmailbox_get_chat() to load details about the chat.
|
||||
*/
|
||||
uint32_t m_chat_id;
|
||||
|
||||
|
||||
/*
|
||||
* The mailbox object the chat belongs to. Never NULL.
|
||||
*/
|
||||
//mrmailbox_t* m_mailbox;
|
||||
|
||||
|
||||
/** @privatesection */
|
||||
|
||||
int m_type; /**< Message type. It is recommended to use mrmsg_set_type() and mrmsg_get_type() to access this field. */
|
||||
#define MR_MSG_UNDEFINED 0
|
||||
#define MR_MSG_TEXT 10
|
||||
#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 */
|
||||
|
||||
int m_state; /**< Message state. It is recommended to use mrmsg_get_state() to access this field. */
|
||||
#define MR_STATE_UNDEFINED 0
|
||||
#define MR_STATE_IN_FRESH 10
|
||||
#define MR_STATE_IN_NOTICED 13
|
||||
#define MR_STATE_IN_SEEN 16
|
||||
#define MR_STATE_OUT_PENDING 20
|
||||
#define MR_STATE_OUT_ERROR 24
|
||||
#define MR_STATE_OUT_DELIVERED 26 /* to check if a mail was sent, use mrmsg_is_sent() */
|
||||
#define MR_STATE_OUT_MDN_RCVD 28
|
||||
|
||||
time_t m_timestamp; /**< Unix time the message was sended or received. 0 if unset. */
|
||||
char* m_text; /**< Message text. NULL if unset. It is recommended to use mrmsg_set_text() and mrmsg_get_text() to access this field. */
|
||||
|
||||
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 */
|
||||
uint32_t m_server_uid; /**< UID last seen on the server for this message */
|
||||
int m_is_msgrmsg; /**< Set to 1 if the message was sent by another messenger. 0 otherwise. */
|
||||
int m_starred; /**< Starred-state of the message. 0=no, 1=yes. */
|
||||
mrparam_t* m_param; /**< Additional paramter for the message. Never a NULL-pointer. It is recommended to use setters and getters instead of accessing this field directly. */
|
||||
} mrmsg_t;
|
||||
#define MR_STATE_UNDEFINED 0
|
||||
#define MR_STATE_IN_FRESH 10
|
||||
#define MR_STATE_IN_NOTICED 13
|
||||
#define MR_STATE_IN_SEEN 16
|
||||
#define MR_STATE_OUT_PENDING 20
|
||||
#define MR_STATE_OUT_ERROR 24
|
||||
#define MR_STATE_OUT_DELIVERED 26 /* to check if a mail was sent, use mrmsg_is_sent() */
|
||||
#define MR_STATE_OUT_MDN_RCVD 28
|
||||
|
||||
|
||||
mrmsg_t* mrmsg_new ();
|
||||
void mrmsg_unref (mrmsg_t*);
|
||||
void mrmsg_empty (mrmsg_t*);
|
||||
|
||||
uint32_t mrmsg_get_id (mrmsg_t*);
|
||||
uint32_t mrmsg_get_from_id (mrmsg_t*);
|
||||
int mrmsg_get_type (mrmsg_t*);
|
||||
int mrmsg_get_state (mrmsg_t*);
|
||||
time_t mrmsg_get_timestamp (mrmsg_t*);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue