mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 10:39:27 +02:00
rename mrpoortext_t to the more general mrlot_t
This commit is contained in:
parent
516b259da5
commit
366c70f7dc
11 changed files with 249 additions and 234 deletions
|
@ -469,6 +469,9 @@
|
|||
<Unit filename="src/mrloginparam.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="src/mrlot.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="src/mrmailbox.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
@ -507,9 +510,6 @@
|
|||
<Unit filename="src/mrpgp.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="src/mrpoortext.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="src/mrsaxparser.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
@ -31,7 +31,7 @@ typedef struct mrmailbox_t mrmailbox_t;
|
|||
|
||||
|
||||
/**
|
||||
* An object representing a simple array.
|
||||
* An object containing a simple array.
|
||||
* This object is used in several placed where functions need to return an array.
|
||||
* The items of the array are typically IDs.
|
||||
* To free an array object, use mrarray_unref().
|
||||
|
|
|
@ -159,34 +159,32 @@ uint32_t mrchatlist_get_msg_id(mrchatlist_t* chatlist, size_t index)
|
|||
/**
|
||||
* Get a summary for a chatlist index.
|
||||
*
|
||||
* The summary is returned by a mrpoortext_t object with the following fields:
|
||||
* The summary is returned by a mrlot_t object with the following fields:
|
||||
*
|
||||
* - m_text1: contains the username or the strings "Me", "Draft" and so on.
|
||||
* - mrlot_t::m_text1: contains the username or the strings "Me", "Draft" and so on.
|
||||
* The string may be colored by having a look at m_text1_meaning.
|
||||
* If there is no such name, the element is NULL (eg. for "No messages")
|
||||
* If there is no such name or it should not be displayed, the element is NULL.
|
||||
*
|
||||
* - m_text1_meaning: one of the MR_TEXT1_* constants
|
||||
* - mrlot_t::m_text1_meaning: one of MR_TEXT1_USERNAME, MR_TEXT1_SELF or MR_TEXT1_DRAFT.
|
||||
* Typically used to show mrlot_t::m_text1 with different colors. 0 if not applicable.
|
||||
*
|
||||
* - m_text2: contains an excerpt of the message text or strings as
|
||||
* "No messages". may be NULL of there is no such text (eg. for the archive)
|
||||
* - mrlot_t::m_text2: contains an excerpt of the message text or strings as
|
||||
* "No messages". May be NULL of there is no such text (eg. for the archive link)
|
||||
*
|
||||
* - m_timestamp: the timestamp of the message. May be 0 if there is no message
|
||||
* - mrlot_t::m_timestamp: the timestamp of the message. 0 if not applicable.
|
||||
*
|
||||
* - m_state: the state of the message as one of the MR_STATE_* identifiers. 0 if there is no message.
|
||||
* - mrlot_t::m_state: The state of the message as one of the MR_STATE_* constants (see #mrmsg_get_state()). 0 if not applicable.
|
||||
*
|
||||
* @memberof mrchatlist_t
|
||||
*
|
||||
* @param chatlist The chatlist to query as returned eg. from mrmailbox_get_chatlist().
|
||||
*
|
||||
* @param index The index to query in the chatlist.
|
||||
* @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.
|
||||
*
|
||||
* @param chat Giving the correct chat object here, this this will speed up
|
||||
* things a little. If the chat object is not available by you, it is faster to pass
|
||||
* NULL here.
|
||||
*
|
||||
* @return The result must be freed using mrpoortext_unref(). The function never returns NULL.
|
||||
* @return The summary as an mrlot_t object. Must be freed using mrlot_unref(). NULL is never returned.
|
||||
*/
|
||||
mrpoortext_t* mrchatlist_get_summary(mrchatlist_t* chatlist, size_t index, mrchat_t* chat /*may be NULL*/)
|
||||
mrlot_t* mrchatlist_get_summary(mrchatlist_t* chatlist, size_t index, mrchat_t* chat /*may be NULL*/)
|
||||
{
|
||||
/* The summary is created by the chat, not by the last message.
|
||||
This is because we may want to display drafts here or stuff as
|
||||
|
@ -194,7 +192,7 @@ mrpoortext_t* mrchatlist_get_summary(mrchatlist_t* chatlist, size_t index, mrcha
|
|||
Also, sth. as "No messages" would not work if the summary comes from a
|
||||
message. */
|
||||
|
||||
mrpoortext_t* ret = mrpoortext_new(); /* the function never returns NULL */
|
||||
mrlot_t* ret = mrlot_new(); /* the function never returns NULL */
|
||||
int locked = 0;
|
||||
uint32_t lastmsg_id = 0;
|
||||
mrmsg_t* lastmsg = NULL;
|
||||
|
@ -263,7 +261,7 @@ mrpoortext_t* mrchatlist_get_summary(mrchatlist_t* chatlist, size_t index, mrcha
|
|||
else
|
||||
{
|
||||
/* show the last message */
|
||||
mrpoortext_fill(ret, lastmsg, chat, lastcontact);
|
||||
mrlot_fill(ret, lastmsg, chat, lastcontact);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
|
|
@ -28,7 +28,7 @@ extern "C" {
|
|||
|
||||
|
||||
typedef struct mrmailbox_t mrmailbox_t;
|
||||
typedef struct mrpoortext_t mrpoortext_t;
|
||||
typedef struct mrlot_t mrlot_t;
|
||||
typedef struct mrchat_t mrchat_t;
|
||||
typedef struct mrarray_t mrarray_t;
|
||||
|
||||
|
@ -57,7 +57,7 @@ void mrchatlist_unref (mrchatlist_t*);
|
|||
size_t mrchatlist_get_cnt (mrchatlist_t*);
|
||||
uint32_t mrchatlist_get_chat_id (mrchatlist_t*, size_t index);
|
||||
uint32_t mrchatlist_get_msg_id (mrchatlist_t*, size_t index);
|
||||
mrpoortext_t* mrchatlist_get_summary (mrchatlist_t*, size_t index, mrchat_t*);
|
||||
mrlot_t* mrchatlist_get_summary (mrchatlist_t*, size_t index, mrchat_t*);
|
||||
|
||||
/* library-internal */
|
||||
int mrchatlist_load_from_db__ (mrchatlist_t*, int listflags, const char* query);
|
||||
|
|
122
src/mrlot.c
Normal file
122
src/mrlot.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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/ .
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#include "mrmailbox_internal.h"
|
||||
|
||||
|
||||
mrlot_t* mrlot_new()
|
||||
{
|
||||
mrlot_t* ths = NULL;
|
||||
|
||||
if( (ths=calloc(1, sizeof(mrlot_t)))==NULL ) {
|
||||
exit(27); /* cannot allocate little memory, unrecoverable error */
|
||||
}
|
||||
|
||||
ths->m_text1_meaning = 0;
|
||||
|
||||
return ths;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Frees an object containing a set of parameters.
|
||||
* If the set object contains strings, the strings are also freed with this function.
|
||||
* Set objects are created eg. by mrchatlist_get_summary(), mrmsg_get_summary or by
|
||||
* mrmsg_get_mediainfo().
|
||||
*
|
||||
* @memberof mrlot_t
|
||||
*
|
||||
* @param set The object to free.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void mrlot_unref(mrlot_t* set)
|
||||
{
|
||||
if( set==NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
mrlot_empty(set);
|
||||
free(set);
|
||||
}
|
||||
|
||||
|
||||
void mrlot_empty(mrlot_t* ths)
|
||||
{
|
||||
if( ths == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(ths->m_text1);
|
||||
ths->m_text1 = NULL;
|
||||
ths->m_text1_meaning = 0;
|
||||
|
||||
free(ths->m_text2);
|
||||
ths->m_text2 = NULL;
|
||||
|
||||
ths->m_timestamp = 0;
|
||||
ths->m_state = 0;
|
||||
}
|
||||
|
||||
|
||||
void mrlot_fill(mrlot_t* ths, const mrmsg_t* msg, const mrchat_t* chat, const mrcontact_t* contact)
|
||||
{
|
||||
if( ths == NULL || msg == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( msg->m_from_id == MR_CONTACT_ID_SELF )
|
||||
{
|
||||
ths->m_text1 = mrstock_str(MR_STR_SELF);
|
||||
ths->m_text1_meaning = MR_TEXT1_SELF;
|
||||
}
|
||||
else if( chat == NULL )
|
||||
{
|
||||
free(ths->m_text1);
|
||||
ths->m_text1 = NULL;
|
||||
ths->m_text1_meaning = 0;
|
||||
}
|
||||
else if( chat->m_type==MR_CHAT_TYPE_GROUP )
|
||||
{
|
||||
if( contact==NULL ) {
|
||||
free(ths->m_text1);
|
||||
ths->m_text1 = NULL;
|
||||
ths->m_text1_meaning = 0;
|
||||
}
|
||||
else if( contact->m_name && contact->m_name[0] ) {
|
||||
ths->m_text1 = mrcontact_get_first_name(contact->m_name);
|
||||
ths->m_text1_meaning = MR_TEXT1_USERNAME;
|
||||
}
|
||||
else if( contact->m_addr && contact->m_addr[0] ) {
|
||||
ths->m_text1 = safe_strdup(contact->m_addr);
|
||||
ths->m_text1_meaning = MR_TEXT1_USERNAME;
|
||||
}
|
||||
else {
|
||||
ths->m_text1 = safe_strdup("Unnamed contact");
|
||||
ths->m_text1_meaning = MR_TEXT1_USERNAME;
|
||||
}
|
||||
}
|
||||
|
||||
ths->m_text2 = mrmsg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, MR_SUMMARY_CHARACTERS);
|
||||
ths->m_timestamp = msg->m_timestamp;
|
||||
ths->m_state = msg->m_state;
|
||||
}
|
64
src/mrlot.h
Normal file
64
src/mrlot.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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 __MRLOT_H__
|
||||
#define __MRLOT_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* An object containing a set of values. The meaning of the values is defined by the function returning the set object.
|
||||
* Set objects are created eg. by mrchatlist_get_summary(), mrmsg_get_summary() or by mrmsg_get_mediainfo().
|
||||
*
|
||||
* NB: _Lot_ is used in the meaning _heap_ here.
|
||||
*/
|
||||
typedef struct mrlot_t
|
||||
{
|
||||
int m_text1_meaning; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */
|
||||
char* m_text1; /**< The meaning of this string is defined by the creator of the object. The string is freed with mrlot_unref(). NULL if not applicable. */
|
||||
char* m_text2; /**< The meaning of this string is defined by the creator of the object. The string is freed with mrlot_unref(). NULL if not applicable. */
|
||||
time_t m_timestamp; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */
|
||||
int m_state; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */
|
||||
} mrlot_t;
|
||||
|
||||
|
||||
#define MR_TEXT1_DRAFT 1
|
||||
#define MR_TEXT1_USERNAME 2
|
||||
#define MR_TEXT1_SELF 3
|
||||
|
||||
|
||||
mrlot_t* mrlot_new ();
|
||||
void mrlot_empty (mrlot_t*);
|
||||
void mrlot_unref (mrlot_t*);
|
||||
|
||||
|
||||
/* library-internal */
|
||||
#define MR_SUMMARY_CHARACTERS 160 /* in practice, the user additionally cuts the string himself pixel-accurate */
|
||||
void mrlot_fill (mrlot_t*, const mrmsg_t*, const mrchat_t*, const mrcontact_t*);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* /extern "C" */
|
||||
#endif
|
||||
#endif /* __MRLOT_H__ */
|
|
@ -144,7 +144,7 @@ extern "C" {
|
|||
#include "mrchat.h"
|
||||
#include "mrmsg.h"
|
||||
#include "mrcontact.h"
|
||||
#include "mrpoortext.h"
|
||||
#include "mrlot.h"
|
||||
#include "mrparam.h"
|
||||
#include "mrevent.h"
|
||||
|
||||
|
@ -344,6 +344,8 @@ int mrmailbox_get_thread_index (void);
|
|||
|
||||
/* deprecated functions */
|
||||
int mrchat_set_draft (mrchat_t*, const char* msg); /* deprecated - use mrmailbox_set_draft() instead */
|
||||
#define mrpoortext_t mrlot_t
|
||||
#define mrpoortext_unref mrlot_unref
|
||||
|
||||
|
||||
/* library-internal */
|
||||
|
|
50
src/mrmsg.c
50
src/mrmsg.c
|
@ -337,22 +337,27 @@ cleanup:
|
|||
/**
|
||||
* 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)
|
||||
* The information is returned by a mrlot_t object with the following fields:
|
||||
*
|
||||
* - mrlot_t::m_text1: Author of the media. For voice messages, this is the sender.
|
||||
* For music messages, the information are read from the filename. NULL if unknown.
|
||||
*
|
||||
* - mrlot_t::m_text2: Title of the media. For voice messages, this is the date.
|
||||
* For music messages, the information are read from the filename. NULL if unknown.
|
||||
*
|
||||
* Currently, 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.
|
||||
* @return Media information as an mrlot_t object. Must be freed using mrlot_unref(). NULL is never returned.
|
||||
*/
|
||||
mrpoortext_t* mrmsg_get_mediainfo(mrmsg_t* msg)
|
||||
mrlot_t* mrmsg_get_mediainfo(mrmsg_t* msg)
|
||||
{
|
||||
mrpoortext_t* ret = mrpoortext_new();
|
||||
char *pathNfilename = NULL;
|
||||
mrlot_t* ret = mrlot_new();
|
||||
char* pathNfilename = NULL;
|
||||
mrcontact_t* contact = NULL;
|
||||
|
||||
if( msg == NULL || msg->m_mailbox == NULL ) {
|
||||
|
@ -491,7 +496,23 @@ int mrmsg_get_showpadlock(mrmsg_t* msg)
|
|||
|
||||
/**
|
||||
* Get a summary for a message.
|
||||
* Typically used to display a search result.
|
||||
*
|
||||
* The summary is returned by a mrlot_t object with the following fields:
|
||||
*
|
||||
* - mrlot_t::m_text1: contains the username or the string "Me".
|
||||
* The string may be colored by having a look at m_text1_meaning.
|
||||
* If the name should not be displayed, the element is NULL.
|
||||
*
|
||||
* - mrlot_t::m_text1_meaning: one of MR_TEXT1_USERNAME or MR_TEXT1_SELF.
|
||||
* Typically used to show mrlot_t::m_text1 with different colors. 0 if not applicable.
|
||||
*
|
||||
* - mrlot_t::m_text2: contains an excerpt of the message text.
|
||||
*
|
||||
* - mrlot_t::m_timestamp: the timestamp of the message.
|
||||
*
|
||||
* - mrlot_t::m_state: The state of the message as one of the MR_STATE_* constants (see #mrmsg_get_state()).
|
||||
*
|
||||
* Typically used to display a search result. See also mrchatlist_get_summary() to display a list of chats.
|
||||
*
|
||||
* @memberof mrmsg_t
|
||||
*
|
||||
|
@ -500,12 +521,11 @@ int mrmsg_get_showpadlock(mrmsg_t* msg)
|
|||
* @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().
|
||||
* @return The summary as an mrlot_t object. Must be freed using mrlot_unref(). NULL is never returned.
|
||||
*/
|
||||
mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, mrchat_t* chat)
|
||||
mrlot_t* mrmsg_get_summary(mrmsg_t* msg, mrchat_t* chat)
|
||||
{
|
||||
mrpoortext_t* ret = mrpoortext_new();
|
||||
mrlot_t* ret = mrlot_new();
|
||||
mrcontact_t* contact = NULL;
|
||||
mrchat_t* chat_to_delete = NULL;
|
||||
|
||||
|
@ -524,7 +544,7 @@ mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, mrchat_t* chat)
|
|||
contact = mrmailbox_get_contact(chat->m_mailbox, msg->m_from_id);
|
||||
}
|
||||
|
||||
mrpoortext_fill(ret, msg, chat, contact);
|
||||
mrlot_fill(ret, msg, chat, contact);
|
||||
|
||||
cleanup:
|
||||
mrcontact_unref(contact);
|
||||
|
|
|
@ -122,12 +122,12 @@ char* mrmsg_get_file (mrmsg_t*);
|
|||
char* mrmsg_get_filename (mrmsg_t*);
|
||||
char* mrmsg_get_filemime (mrmsg_t*);
|
||||
uint64_t mrmsg_get_filebytes (mrmsg_t*);
|
||||
mrpoortext_t* mrmsg_get_mediainfo (mrmsg_t*);
|
||||
mrlot_t* mrmsg_get_mediainfo (mrmsg_t*);
|
||||
int mrmsg_get_width (mrmsg_t*);
|
||||
int mrmsg_get_height (mrmsg_t*);
|
||||
int mrmsg_get_duration (mrmsg_t*);
|
||||
int mrmsg_get_showpadlock (mrmsg_t*);
|
||||
mrpoortext_t* mrmsg_get_summary (mrmsg_t*, mrchat_t*);
|
||||
mrlot_t* mrmsg_get_summary (mrmsg_t*, mrchat_t*);
|
||||
char* mrmsg_get_summarytext (mrmsg_t*, int approx_characters);
|
||||
int mrmsg_is_starred (mrmsg_t*);
|
||||
int mrmsg_is_forwarded (mrmsg_t*);
|
||||
|
|
125
src/mrpoortext.c
125
src/mrpoortext.c
|
@ -1,125 +1,2 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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/ .
|
||||
*
|
||||
******************************************************************************/
|
||||
/* deprecated */
|
||||
|
||||
|
||||
#include "mrmailbox_internal.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Main interface
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
mrpoortext_t* mrpoortext_new()
|
||||
{
|
||||
mrpoortext_t* ths = NULL;
|
||||
|
||||
if( (ths=calloc(1, sizeof(mrpoortext_t)))==NULL ) {
|
||||
exit(27); /* cannot allocate little memory, unrecoverable error */
|
||||
}
|
||||
|
||||
ths->m_text1_meaning = MR_TEXT1_NORMAL;
|
||||
|
||||
return ths;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Frees a poortext object. Poortext objects are typically created by mrchatlist_get_summary() or by
|
||||
* mrmsg_get_summary(). This also frees the strings objects.
|
||||
*
|
||||
* @memberof mrpoortext_t
|
||||
*
|
||||
* @param poortext The mrpoortext_t object to free.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void mrpoortext_unref(mrpoortext_t* poortext)
|
||||
{
|
||||
if( poortext==NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
mrpoortext_empty(poortext);
|
||||
free(poortext);
|
||||
}
|
||||
|
||||
|
||||
void mrpoortext_empty(mrpoortext_t* ths)
|
||||
{
|
||||
if( ths == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(ths->m_text1);
|
||||
ths->m_text1 = NULL;
|
||||
ths->m_text1_meaning = MR_TEXT1_NORMAL;
|
||||
|
||||
free(ths->m_text2);
|
||||
ths->m_text2 = NULL;
|
||||
|
||||
ths->m_timestamp = 0;
|
||||
ths->m_state = 0;
|
||||
}
|
||||
|
||||
|
||||
void mrpoortext_fill(mrpoortext_t* ths, const mrmsg_t* msg, const mrchat_t* chat, const mrcontact_t* contact)
|
||||
{
|
||||
if( ths == NULL || msg == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( msg->m_from_id == MR_CONTACT_ID_SELF )
|
||||
{
|
||||
ths->m_text1 = mrstock_str(MR_STR_SELF);
|
||||
ths->m_text1_meaning = MR_TEXT1_SELF;
|
||||
}
|
||||
else if( chat == NULL )
|
||||
{
|
||||
free(ths->m_text1);
|
||||
ths->m_text1 = NULL;
|
||||
ths->m_text1_meaning = MR_TEXT1_NORMAL;
|
||||
}
|
||||
else if( chat->m_type==MR_CHAT_TYPE_GROUP )
|
||||
{
|
||||
if( contact==NULL ) {
|
||||
free(ths->m_text1);
|
||||
ths->m_text1 = NULL;
|
||||
ths->m_text1_meaning = MR_TEXT1_NORMAL;
|
||||
}
|
||||
else if( contact->m_name && contact->m_name[0] ) {
|
||||
ths->m_text1 = mrcontact_get_first_name(contact->m_name);
|
||||
ths->m_text1_meaning = MR_TEXT1_USERNAME;
|
||||
}
|
||||
else if( contact->m_addr && contact->m_addr[0] ) {
|
||||
ths->m_text1 = safe_strdup(contact->m_addr);
|
||||
ths->m_text1_meaning = MR_TEXT1_USERNAME;
|
||||
}
|
||||
else {
|
||||
ths->m_text1 = safe_strdup("Unnamed contact");
|
||||
ths->m_text1_meaning = MR_TEXT1_USERNAME;
|
||||
}
|
||||
}
|
||||
|
||||
ths->m_text2 = mrmsg_get_summarytext_by_raw(msg->m_type, msg->m_text, msg->m_param, MR_SUMMARY_CHARACTERS);
|
||||
ths->m_timestamp = msg->m_timestamp;
|
||||
ths->m_state = msg->m_state;
|
||||
}
|
||||
|
|
|
@ -1,70 +1,2 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 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/ .
|
||||
*
|
||||
******************************************************************************/
|
||||
/* deprecated */
|
||||
|
||||
|
||||
#ifndef __MRPOORTEXT_H__
|
||||
#define __MRPOORTEXT_H__
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* An object representing text with some attributes. A poortext object
|
||||
* contains some strings together with their meaning and some attributes.
|
||||
* Poortext objects are returned eg. from mrchatlist_get_summary() or mrmsg_get_summary().
|
||||
*/
|
||||
typedef struct mrpoortext_t
|
||||
{
|
||||
/** Defines the meaning of the m_text1 string.
|
||||
* - MR_TEXT1_NORMAL (0) = m_text1 is a normal text field.
|
||||
* - MR_TEXT1_DRAFT = m_text1 is the string "Draft", typically, this is shown in another color.
|
||||
* - MR_TEXT1_USERNAME = m_text1 is a username, typically, this is shown in another color.
|
||||
* - MR_TEXT1_SELF = m_text1 is the string "Me", typically, this is shown in another color.
|
||||
*/
|
||||
int m_text1_meaning;
|
||||
|
||||
char* m_text1; /**< The meaning is defined by m_text1_meaning and by the creator of the object. May be NULL. */
|
||||
char* m_text2; /**< The meaning is defined by the creator of the object. May be NULL. */
|
||||
time_t m_timestamp; /**< Typically a message timestamp. The concrete meaning is defined by the creator of the object. May be 0. */
|
||||
int m_state; /**< Typically a MR_MSG_STATE_* constant. May be 0. */
|
||||
} mrpoortext_t;
|
||||
|
||||
|
||||
#define MR_TEXT1_NORMAL 0
|
||||
#define MR_TEXT1_DRAFT 1
|
||||
#define MR_TEXT1_USERNAME 2
|
||||
#define MR_TEXT1_SELF 3
|
||||
|
||||
|
||||
mrpoortext_t* mrpoortext_new ();
|
||||
void mrpoortext_empty (mrpoortext_t*);
|
||||
void mrpoortext_unref (mrpoortext_t*);
|
||||
|
||||
|
||||
#define MR_SUMMARY_CHARACTERS 160 /**< @private in practice, the user additionally cuts the string himself pixel-accurate */
|
||||
void mrpoortext_fill (mrpoortext_t*, const mrmsg_t*, const mrchat_t*, const mrcontact_t*);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* /extern "C" */
|
||||
#endif
|
||||
#endif /* __MRPOORTEXT_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue