mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-04 07:05:26 -04:00
Moved the tag feature in messages from the gui to the libretroshare.
Changed rsmsg interface and item classes so need full recompile. Created new notifier for tag changes - NOTIFY_LIST_MESSAGE_TAGS. Changed serialiser tests for message items. After that all tags are reset to standard and all assigned tags to messages are lost. Please delete the file msg_locale.cfg in your profile directory. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3381 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
340982b996
commit
52183a0c75
18 changed files with 708 additions and 515 deletions
|
@ -216,16 +216,17 @@ class NotifyBase
|
|||
virtual std::string askForPassword(const std::string& /* key_details */ ,bool /* prev_is_bad */ ) { return "" ;}
|
||||
};
|
||||
|
||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||
const int NOTIFY_LIST_FRIENDS = 2;
|
||||
const int NOTIFY_LIST_SEARCHLIST = 4;
|
||||
const int NOTIFY_LIST_MESSAGELIST = 5;
|
||||
const int NOTIFY_LIST_CHANNELLIST = 6;
|
||||
const int NOTIFY_LIST_TRANSFERLIST = 7;
|
||||
const int NOTIFY_LIST_CONFIG = 8;
|
||||
const int NOTIFY_LIST_DIRLIST_LOCAL = 9;
|
||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||
const int NOTIFY_LIST_FRIENDS = 2;
|
||||
const int NOTIFY_LIST_SEARCHLIST = 4;
|
||||
const int NOTIFY_LIST_MESSAGELIST = 5;
|
||||
const int NOTIFY_LIST_CHANNELLIST = 6;
|
||||
const int NOTIFY_LIST_TRANSFERLIST = 7;
|
||||
const int NOTIFY_LIST_CONFIG = 8;
|
||||
const int NOTIFY_LIST_DIRLIST_LOCAL = 9;
|
||||
const int NOTIFY_LIST_DIRLIST_FRIENDS = 10;
|
||||
const int NOTIFY_LIST_FORUMLIST_LOCKED = 11; // use connect with Qt::QueuedConnection
|
||||
const int NOTIFY_LIST_MESSAGE_TAGS = 12;
|
||||
|
||||
const int NOTIFY_TYPE_SAME = 0x01;
|
||||
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */
|
||||
|
|
|
@ -37,18 +37,26 @@
|
|||
|
||||
#define RS_MSG_BOXMASK 0x000f /* Mask for determining Box */
|
||||
|
||||
#define RS_MSG_OUTGOING 0x0001 /* !Inbox */
|
||||
#define RS_MSG_PENDING 0x0002 /* OutBox */
|
||||
#define RS_MSG_DRAFT 0x0004 /* Draft */
|
||||
#define RS_MSG_OUTGOING 0x0001 /* !Inbox */
|
||||
#define RS_MSG_PENDING 0x0002 /* OutBox */
|
||||
#define RS_MSG_DRAFT 0x0004 /* Draft */
|
||||
|
||||
/* ORs of above */
|
||||
#define RS_MSG_INBOX 0x00 /* Inbox */
|
||||
#define RS_MSG_SENTBOX 0x01 /* Sentbox */
|
||||
#define RS_MSG_OUTBOX 0x03 /* Outbox */
|
||||
#define RS_MSG_DRAFTBOX 0x05 /* Draftbox */
|
||||
#define RS_MSG_INBOX 0x00 /* Inbox */
|
||||
#define RS_MSG_SENTBOX 0x01 /* Sentbox */
|
||||
#define RS_MSG_OUTBOX 0x03 /* Outbox */
|
||||
#define RS_MSG_DRAFTBOX 0x05 /* Draftbox */
|
||||
|
||||
#define RS_MSG_NEW 0x0010 /* New */
|
||||
#define RS_MSG_TRASH 0x0020 /* Trash */
|
||||
#define RS_MSG_NEW 0x0010 /* New */
|
||||
#define RS_MSG_TRASH 0x0020 /* Trash */
|
||||
#define RS_MSG_UNREAD_BY_USER 0x0040 /* Unread by user */
|
||||
|
||||
#define RS_MSGTAGTYPE_IMPORTANT 1
|
||||
#define RS_MSGTAGTYPE_WORK 2
|
||||
#define RS_MSGTAGTYPE_PERSONAL 3
|
||||
#define RS_MSGTAGTYPE_TODO 4
|
||||
#define RS_MSGTAGTYPE_LATER 5
|
||||
#define RS_MSGTAGTYPE_USER 100
|
||||
|
||||
class MessageInfo
|
||||
{
|
||||
|
@ -96,8 +104,8 @@ class MsgTagInfo
|
|||
public:
|
||||
MsgTagInfo() {}
|
||||
|
||||
uint32_t tagId;
|
||||
std::string msgId;
|
||||
std::list<uint32_t> tagIds;
|
||||
};
|
||||
|
||||
class MsgTagType
|
||||
|
@ -105,7 +113,7 @@ class MsgTagType
|
|||
public:
|
||||
MsgTagType() {}
|
||||
|
||||
/* map containing tagid-> pair (text, rgb color) */
|
||||
/* map containing tagId -> pair (text, rgb color) */
|
||||
std::map<uint32_t, std::pair<std::string, uint32_t> > types;
|
||||
|
||||
};
|
||||
|
@ -151,15 +159,19 @@ virtual bool MessageToDraft(MessageInfo &info) = 0;
|
|||
virtual bool MessageToTrash(std::string mid, bool bTrash) = 0;
|
||||
|
||||
virtual bool MessageDelete(std::string mid) = 0;
|
||||
virtual bool MessageRead(std::string mid) = 0;
|
||||
virtual bool MessageRead(std::string mid, bool bUnreadByUser) = 0;
|
||||
|
||||
/* message tagging */
|
||||
|
||||
virtual bool MessageGetTagTypes(MsgTagType& tags) = 0;
|
||||
virtual bool MessageGetMsgTag(std::string msgId, MsgTagInfo& info) = 0;
|
||||
virtual bool getMessageTagTypes(MsgTagType& tags) = 0;
|
||||
/* set == false && tagId == 0 --> remove all */
|
||||
virtual bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color) = 0;
|
||||
virtual bool removeMessageTagType(uint32_t tagId) = 0;
|
||||
|
||||
virtual bool MessageSetTagType(std::string& text, uint32_t tag_id, uint32_t rgb_color) = 0;
|
||||
virtual bool MessageSetMsgTag(MsgTagInfo& ) = 0;
|
||||
virtual bool getMessageTag(std::string msgId, MsgTagInfo& info) = 0;
|
||||
virtual bool setMessageTag(std::string msgId, uint32_t tagId, bool set) = 0;
|
||||
|
||||
virtual bool resetMessageStandardTagTypes(MsgTagType& tags) = 0;
|
||||
|
||||
/****************************************/
|
||||
/* Chat */
|
||||
|
|
|
@ -92,39 +92,45 @@ bool p3Msgs::MessageDelete(std::string mid)
|
|||
//std::cerr << "p3Msgs::MessageDelete() ";
|
||||
//std::cerr << "mid: " << mid << std::endl;
|
||||
|
||||
mMsgSrv -> removeMsgId(mid);
|
||||
|
||||
return 1;
|
||||
return mMsgSrv -> removeMsgId(mid);
|
||||
}
|
||||
|
||||
bool p3Msgs::MessageRead(std::string mid)
|
||||
bool p3Msgs::MessageRead(std::string mid, bool bUnreadByUser)
|
||||
{
|
||||
//std::cerr << "p3Msgs::MessageRead() ";
|
||||
//std::cerr << "mid: " << mid << std::endl;
|
||||
|
||||
mMsgSrv -> markMsgIdRead(mid);
|
||||
|
||||
return 1;
|
||||
return mMsgSrv -> markMsgIdRead(mid, bUnreadByUser);
|
||||
}
|
||||
|
||||
bool p3Msgs::MessageGetTagTypes(MsgTagType& tags)
|
||||
bool p3Msgs::getMessageTagTypes(MsgTagType& tags)
|
||||
{
|
||||
mMsgSrv->MessageGetTagTypes(tags);
|
||||
return mMsgSrv->getMessageTagTypes(tags);
|
||||
}
|
||||
|
||||
bool p3Msgs::MessageGetMsgTag(std::string msgId, MsgTagInfo& info)
|
||||
bool p3Msgs::setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color)
|
||||
{
|
||||
mMsgSrv->MessageGetMsgTag(msgId, info);
|
||||
return mMsgSrv->setMessageTagType(tagId, text, rgb_color);
|
||||
}
|
||||
|
||||
bool p3Msgs::MessageSetTagType(std::string& text, uint32_t tag_id, uint32_t rgb_color)
|
||||
bool p3Msgs::removeMessageTagType(uint32_t tagId)
|
||||
{
|
||||
mMsgSrv->MessageSetTagType(text, tag_id, rgb_color);
|
||||
return mMsgSrv->removeMessageTagType(tagId);
|
||||
}
|
||||
|
||||
bool p3Msgs::MessageSetMsgTag(MsgTagInfo& tagInfo)
|
||||
bool p3Msgs::getMessageTag(std::string msgId, MsgTagInfo& info)
|
||||
{
|
||||
mMsgSrv->MessageSetMsgTag(tagInfo);
|
||||
return mMsgSrv->getMessageTag(msgId, info);
|
||||
}
|
||||
|
||||
bool p3Msgs::setMessageTag(std::string msgId, uint32_t tagId, bool set)
|
||||
{
|
||||
return mMsgSrv->setMessageTag(msgId, tagId, set);
|
||||
}
|
||||
|
||||
bool p3Msgs::resetMessageStandardTagTypes(MsgTagType& tags)
|
||||
{
|
||||
return mMsgSrv->resetMessageStandardTagTypes(tags);
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
|
|
@ -61,13 +61,17 @@ class p3Msgs: public RsMsgs
|
|||
virtual bool MessageToDraft(MessageInfo &info);
|
||||
virtual bool MessageToTrash(std::string mid, bool bTrash);
|
||||
virtual bool MessageDelete(std::string mid);
|
||||
virtual bool MessageRead(std::string mid);
|
||||
virtual bool MessageRead(std::string mid, bool bUnreadByUser);
|
||||
|
||||
virtual bool MessageGetTagTypes(MsgTagType& tags);
|
||||
virtual bool MessageGetMsgTag(std::string msgId, MsgTagInfo& info);
|
||||
virtual bool getMessageTagTypes(MsgTagType& tags);
|
||||
virtual bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color);
|
||||
virtual bool removeMessageTagType(uint32_t tagId);
|
||||
|
||||
virtual bool MessageSetTagType(std::string& text, uint32_t tag_id, uint32_t rgb_color);
|
||||
virtual bool MessageSetMsgTag(MsgTagInfo& );
|
||||
virtual bool getMessageTag(std::string msgId, MsgTagInfo& info);
|
||||
/* set == false && tagId == 0 --> remove all */
|
||||
virtual bool setMessageTag(std::string msgId, uint32_t tagId, bool set);
|
||||
|
||||
virtual bool resetMessageStandardTagTypes(MsgTagType& tags);
|
||||
|
||||
/*!
|
||||
* gets avatar from peer, image data in jpeg format
|
||||
|
|
|
@ -422,8 +422,8 @@ void RsMsgTagType::clear()
|
|||
|
||||
void RsMsgTags::clear()
|
||||
{
|
||||
msgId.clear();
|
||||
tagId = 0;
|
||||
msgId = 0;
|
||||
tagIds.clear();
|
||||
}
|
||||
|
||||
std::ostream& RsMsgTagType::print(std::ostream &out, uint16_t indent)
|
||||
|
@ -698,8 +698,8 @@ uint32_t RsMsgSerialiser::sizeMsgTagItem(RsMsgTags* item)
|
|||
{
|
||||
uint32_t s = 8; /* header */
|
||||
|
||||
s += GetTlvStringSize(item->msgId);
|
||||
s += 4; /* tag id */
|
||||
s += 4; /* msgId */
|
||||
s += item->tagIds.size() * 4; /* tagIds */
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -726,8 +726,13 @@ bool RsMsgSerialiser::serialiseMsgTagItem(RsMsgTags *item, void *data, uint32_t*
|
|||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_MSGID, item->msgId);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, item->tagId);
|
||||
ok &= setRawUInt32(data,tlvsize,&offset, item->msgId);
|
||||
|
||||
std::list<uint32_t>::iterator mit = item->tagIds.begin();
|
||||
for(;mit != item->tagIds.end(); mit++)
|
||||
{
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, *mit);
|
||||
}
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -773,8 +778,17 @@ RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(void* data, uint32_t* pktsize)
|
|||
|
||||
|
||||
/* get mandatory parts first */
|
||||
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_MSGID,item->msgId);
|
||||
ok &= getRawUInt32(data, rssize, &offset, &(item->tagId));
|
||||
ok &= getRawUInt32(data, rssize, &offset, &item->msgId);
|
||||
|
||||
uint32_t tagId;
|
||||
while (offset != rssize)
|
||||
{
|
||||
tagId = 0;
|
||||
|
||||
ok &= getRawUInt32(data, rssize, &offset, &tagId);
|
||||
|
||||
item->tagIds.push_back(tagId);
|
||||
}
|
||||
|
||||
if (offset != rssize)
|
||||
{
|
||||
|
|
|
@ -144,11 +144,12 @@ class RsChatSerialiser: public RsSerialType
|
|||
|
||||
/**************************************************************************/
|
||||
|
||||
const uint32_t RS_MSG_FLAGS_OUTGOING = 0x0001;
|
||||
const uint32_t RS_MSG_FLAGS_PENDING = 0x0002;
|
||||
const uint32_t RS_MSG_FLAGS_DRAFT = 0x0004;
|
||||
const uint32_t RS_MSG_FLAGS_NEW = 0x0010;
|
||||
const uint32_t RS_MSG_FLAGS_TRASH = 0x0020;
|
||||
const uint32_t RS_MSG_FLAGS_OUTGOING = 0x0001;
|
||||
const uint32_t RS_MSG_FLAGS_PENDING = 0x0002;
|
||||
const uint32_t RS_MSG_FLAGS_DRAFT = 0x0004;
|
||||
const uint32_t RS_MSG_FLAGS_NEW = 0x0010;
|
||||
const uint32_t RS_MSG_FLAGS_TRASH = 0x0020;
|
||||
const uint32_t RS_MSG_FLAGS_UNREAD_BY_USER = 0x0040;
|
||||
|
||||
class RsMsgItem: public RsItem
|
||||
{
|
||||
|
@ -216,8 +217,8 @@ public:
|
|||
virtual ~RsMsgTags();
|
||||
virtual void clear();
|
||||
|
||||
std::string msgId;
|
||||
uint32_t tagId;
|
||||
uint32_t msgId;
|
||||
std::list<uint32_t> tagIds;
|
||||
};
|
||||
|
||||
class RsMsgSerialiser: public RsSerialType
|
||||
|
|
|
@ -300,7 +300,7 @@ bool p3MsgService::saveConfiguration()
|
|||
written = written && pa_out -> SendItem(mit->second) ;
|
||||
|
||||
std::map<uint32_t, RsMsgTagType* >::iterator mit2;
|
||||
std::map<std::string, RsMsgTags* >::iterator mit3;
|
||||
std::map<uint32_t, RsMsgTags* >::iterator mit3;
|
||||
|
||||
|
||||
for(mit2 = mTags.begin(); mit2 != mTags.end(); mit2++)
|
||||
|
@ -324,6 +324,47 @@ bool p3MsgService::saveConfiguration()
|
|||
return true;
|
||||
}
|
||||
|
||||
// build list of standard tag types
|
||||
static void getStandardTagTypes(MsgTagType &tags)
|
||||
{
|
||||
/* create standard tag types, the text must be translated in the GUI */
|
||||
tags.types [RS_MSGTAGTYPE_IMPORTANT] = std::pair<std::string, uint32_t> ("Important", 0xFF0000);
|
||||
tags.types [RS_MSGTAGTYPE_WORK] = std::pair<std::string, uint32_t> ("Work", 0xFF9900);
|
||||
tags.types [RS_MSGTAGTYPE_PERSONAL] = std::pair<std::string, uint32_t> ("Personal", 0x009900);
|
||||
tags.types [RS_MSGTAGTYPE_TODO] = std::pair<std::string, uint32_t> ("Todo", 0x3333FF);
|
||||
tags.types [RS_MSGTAGTYPE_LATER] = std::pair<std::string, uint32_t> ("Later", 0x993399);
|
||||
}
|
||||
|
||||
// Initialize the standard tag types after load
|
||||
void p3MsgService::initStandardTagTypes()
|
||||
{
|
||||
bool bChanged = false;
|
||||
std::string ownId = mConnMgr->getOwnId();
|
||||
|
||||
MsgTagType tags;
|
||||
getStandardTagTypes(tags);
|
||||
|
||||
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator tit;
|
||||
for (tit = tags.types.begin(); tit != tags.types.end(); tit++) {
|
||||
std::map<uint32_t, RsMsgTagType*>::iterator mit = mTags.find(tit->first);
|
||||
if (mit == mTags.end()) {
|
||||
RsMsgTagType* tagType = new RsMsgTagType();
|
||||
tagType->PeerId (ownId);
|
||||
tagType->tagId = tit->first;
|
||||
tagType->text = tit->second.first;
|
||||
tagType->rgb_color = tit->second.second;
|
||||
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType*>(tit->first, tagType));
|
||||
|
||||
bChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (bChanged) {
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
}
|
||||
|
||||
bool p3MsgService::loadConfiguration(std::string &loadHash)
|
||||
{
|
||||
std::string msgfile = Filename();
|
||||
|
@ -360,7 +401,7 @@ bool p3MsgService::loadConfiguration(std::string &loadHash)
|
|||
}
|
||||
else if(NULL != (mti = dynamic_cast<RsMsgTags *>(item)))
|
||||
{
|
||||
mMsgTags.insert(std::pair<std::string, RsMsgTags* >(mti->msgId, mti));
|
||||
mMsgTags.insert(std::pair<uint32_t, RsMsgTags* >(mti->msgId, mti));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -437,6 +478,9 @@ bool p3MsgService::loadConfiguration(std::string &loadHash)
|
|||
|
||||
setHash(hashin);
|
||||
|
||||
/* Initialize standard tag types */
|
||||
initStandardTagTypes();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -507,7 +551,7 @@ bool p3MsgService::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
|
|||
}
|
||||
|
||||
|
||||
bool p3MsgService::getMessage(std::string mId, MessageInfo &msg)
|
||||
bool p3MsgService::getMessage(std::string &mId, MessageInfo &msg)
|
||||
{
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
||||
uint32_t msgId = atoi(mId.c_str());
|
||||
|
@ -574,11 +618,16 @@ void p3MsgService::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxN
|
|||
}
|
||||
|
||||
/* remove based on the unique mid (stored in sid) */
|
||||
bool p3MsgService::removeMsgId(std::string mid)
|
||||
bool p3MsgService::removeMsgId(std::string &mid)
|
||||
{
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
||||
uint32_t msgId = atoi(mid.c_str());
|
||||
bool changed = false ;
|
||||
if (msgId == 0) {
|
||||
std::cerr << "p3MsgService::removeMsgId: Unknown msgId " << msgId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -586,15 +635,10 @@ bool p3MsgService::removeMsgId(std::string mid)
|
|||
mit = imsg.find(msgId);
|
||||
if (mit != imsg.end())
|
||||
{
|
||||
changed = true ;
|
||||
changed = true;
|
||||
RsMsgItem *mi = mit->second;
|
||||
imsg.erase(mit);
|
||||
delete mi;
|
||||
// msgChanged.IndicateChanged();
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
mit = msgOutgoing.find(msgId);
|
||||
|
@ -604,25 +648,25 @@ bool p3MsgService::removeMsgId(std::string mid)
|
|||
RsMsgItem *mi = mit->second;
|
||||
msgOutgoing.erase(mit);
|
||||
delete mi;
|
||||
// msgChanged.IndicateChanged();
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(changed)
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
||||
if(changed) {
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
return false;
|
||||
setMessageTag(mid, 0, false);
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool p3MsgService::markMsgIdRead(std::string mid)
|
||||
bool p3MsgService::markMsgIdRead(std::string &mid, bool bUnreadByUser)
|
||||
{
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
||||
uint32_t msgId = atoi(mid.c_str());
|
||||
bool changed = false ;
|
||||
bool changed = false;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -630,20 +674,35 @@ bool p3MsgService::markMsgIdRead(std::string mid)
|
|||
mit = imsg.find(msgId);
|
||||
if (mit != imsg.end())
|
||||
{
|
||||
changed = true ;
|
||||
RsMsgItem *mi = mit->second;
|
||||
mi -> msgFlags &= ~(RS_MSG_FLAGS_NEW);
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
uint32_t msgFlags = mi->msgFlags;
|
||||
|
||||
/* remove new state */
|
||||
mi->msgFlags &= ~(RS_MSG_FLAGS_NEW);
|
||||
|
||||
/* set state from user */
|
||||
if (bUnreadByUser) {
|
||||
mi->msgFlags |= RS_MSG_FLAGS_UNREAD_BY_USER;
|
||||
} else {
|
||||
mi->msgFlags &= ~RS_MSG_FLAGS_UNREAD_BY_USER;
|
||||
}
|
||||
|
||||
if (mi->msgFlags != msgFlags)
|
||||
{
|
||||
changed = true;
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} /* UNLOCKED */
|
||||
|
||||
if (changed) {
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
||||
}
|
||||
|
||||
if(changed) {
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
@ -760,12 +819,13 @@ bool p3MsgService::MessageToDraft(MessageInfo &info)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool p3MsgService::MessageGetTagTypes(MsgTagType& tags)
|
||||
bool p3MsgService::getMessageTagTypes(MsgTagType& tags)
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<uint32_t, RsMsgTagType*>::iterator mit;
|
||||
|
||||
for(mit = mTags.begin(); mit != mTags.end(); mit++)
|
||||
{
|
||||
for(mit = mTags.begin(); mit != mTags.end(); mit++) {
|
||||
std::pair<std::string, uint32_t> p(mit->second->text, mit->second->rgb_color);
|
||||
tags.types.insert(std::pair<uint32_t, std::pair<std::string, uint32_t> >(mit->first, p));
|
||||
}
|
||||
|
@ -773,47 +833,243 @@ bool p3MsgService::MessageGetTagTypes(MsgTagType& tags)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3MsgService::MessageGetMsgTag(std::string msgId, MsgTagInfo& info)
|
||||
bool p3MsgService::setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color)
|
||||
{
|
||||
int nNotifyType = 0;
|
||||
|
||||
std::map<std::string, RsMsgTags*>::iterator mit;
|
||||
|
||||
|
||||
if(mMsgTags.end() != (mit = mMsgTags.find(msgId)))
|
||||
{
|
||||
info.msgId = mit->second->msgId;
|
||||
info.tagId = mit->second->tagId;
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<uint32_t, RsMsgTagType*>::iterator mit;
|
||||
mit = mTags.find(tagId);
|
||||
|
||||
if (mit == mTags.end()) {
|
||||
if (tagId < RS_MSGTAGTYPE_USER) {
|
||||
std::cerr << "p3MsgService::MessageSetTagType: Standard tag type " << tagId << " cannot be inserted" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* new tag */
|
||||
RsMsgTagType* tagType = new RsMsgTagType();
|
||||
tagType->PeerId (mConnMgr->getOwnId());
|
||||
tagType->rgb_color = rgb_color;
|
||||
tagType->tagId = tagId;
|
||||
tagType->text = text;
|
||||
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType*>(tagId, tagType));
|
||||
|
||||
nNotifyType = NOTIFY_TYPE_ADD;
|
||||
} else {
|
||||
if (mit->second->text != text || mit->second->rgb_color != rgb_color) {
|
||||
/* modify existing tag */
|
||||
if (tagId >= RS_MSGTAGTYPE_USER) {
|
||||
mit->second->text = text;
|
||||
} else {
|
||||
/* don't change text for standard tag types */
|
||||
if (mit->second->text != text) {
|
||||
std::cerr << "p3MsgService::MessageSetTagType: Text " << text << " for standard tag type " << tagId << " cannot be changed" << std::endl;
|
||||
}
|
||||
}
|
||||
mit->second->rgb_color = rgb_color;
|
||||
|
||||
nNotifyType = NOTIFY_TYPE_MOD;
|
||||
}
|
||||
}
|
||||
|
||||
} /* UNLOCKED */
|
||||
|
||||
if (nNotifyType) {
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGE_TAGS, nNotifyType);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "p3MsgService::MessageGetMsgTag: no tag found for msgId " << msgId << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3MsgService::MessageSetTagType(std::string& text, uint32_t tagId, uint32_t rgb_color)
|
||||
bool p3MsgService::removeMessageTagType(uint32_t tagId)
|
||||
{
|
||||
if (tagId < RS_MSGTAGTYPE_USER) {
|
||||
std::cerr << "p3MsgService::MessageRemoveTagType: Can't delete standard tag type " << tagId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
RsMsgTagType* tagType = new RsMsgTagType();
|
||||
tagType->rgb_color = rgb_color;
|
||||
tagType->tagId = tagId;
|
||||
tagType->text = text;
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
mTags.insert(std::pair<uint32_t, RsMsgTagType*>(tagId, tagType));
|
||||
std::map<uint32_t, RsMsgTagType*>::iterator mit;
|
||||
mit = mTags.find(tagId);
|
||||
|
||||
if (mit == mTags.end()) {
|
||||
/* tag id not found */
|
||||
std::cerr << "p3MsgService::MessageRemoveTagType: Tag Id not found " << tagId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* search for messages with this tag type */
|
||||
std::map<uint32_t, RsMsgTags*>::iterator mit1;
|
||||
for (mit1 = mMsgTags.begin(); mit1 != mMsgTags.end(); ) {
|
||||
RsMsgTags* tag = mit1->second;
|
||||
|
||||
std::list<uint32_t>::iterator lit;
|
||||
lit = std::find(tag->tagIds.begin(), tag->tagIds.end(), tagId);
|
||||
if (lit != tag->tagIds.end()) {
|
||||
tag->tagIds.erase(lit);
|
||||
|
||||
if (tag->tagIds.size() == 0) {
|
||||
/* remove empty tag */
|
||||
delete(tag);
|
||||
|
||||
std::map<uint32_t, RsMsgTags*>::iterator mit2 = mit1;
|
||||
mit1++;
|
||||
mMsgTags.erase(mit2);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
mit1++;
|
||||
}
|
||||
|
||||
/* remove tag type */
|
||||
delete(mit->second);
|
||||
mTags.erase(mit);
|
||||
|
||||
} /* UNLOCKED */
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGE_TAGS, NOTIFY_TYPE_DEL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3MsgService::MessageSetMsgTag(MsgTagInfo& tagInfo)
|
||||
bool p3MsgService::getMessageTag(std::string &msgId, MsgTagInfo& info)
|
||||
{
|
||||
RsMsgTags* tag = new RsMsgTags();
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
tag->msgId = tagInfo.msgId;
|
||||
tag->tagId = tagInfo.tagId;
|
||||
uint32_t mid = atoi(msgId.c_str());
|
||||
if (mid == 0) {
|
||||
std::cerr << "p3MsgService::MessageGetMsgTag: Unknown msgId " << msgId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
mMsgTags.insert(std::pair<std::string, RsMsgTags*>(tag->msgId, tag));
|
||||
std::map<uint32_t, RsMsgTags*>::iterator mit;
|
||||
|
||||
if(mMsgTags.end() != (mit = mMsgTags.find(mid))) {
|
||||
std::ostringstream out;
|
||||
out << mit->second->msgId;
|
||||
|
||||
info.msgId = out.str();
|
||||
info.tagIds = mit->second->tagIds;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* set == false && tagId == 0 --> remove all */
|
||||
bool p3MsgService::setMessageTag(std::string &msgId, uint32_t tagId, bool set)
|
||||
{
|
||||
uint32_t mid = atoi(msgId.c_str());
|
||||
if (mid == 0) {
|
||||
std::cerr << "p3MsgService::MessageSetMsgTag: Unknown msgId " << msgId << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tagId == 0) {
|
||||
if (set == true) {
|
||||
std::cerr << "p3MsgService::MessageSetMsgTag: No valid tagId given " << tagId << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int nNotifyType = 0;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
std::map<uint32_t, RsMsgTags*>::iterator mit;
|
||||
mit = mMsgTags.find(mid);
|
||||
|
||||
if (mit == mMsgTags.end()) {
|
||||
if (set) {
|
||||
/* new msg */
|
||||
RsMsgTags* tag = new RsMsgTags();
|
||||
tag->PeerId (mConnMgr->getOwnId());
|
||||
|
||||
tag->msgId = mid;
|
||||
tag->tagIds.push_back(tagId);
|
||||
|
||||
mMsgTags.insert(std::pair<uint32_t, RsMsgTags*>(tag->msgId, tag));
|
||||
|
||||
nNotifyType = NOTIFY_TYPE_ADD;
|
||||
}
|
||||
} else {
|
||||
RsMsgTags* tag = mit->second;
|
||||
|
||||
/* search existing tagId */
|
||||
std::list<uint32_t>::iterator lit;
|
||||
if (tagId) {
|
||||
lit = std::find(tag->tagIds.begin(), tag->tagIds.end(), tagId);
|
||||
} else {
|
||||
lit = tag->tagIds.end();
|
||||
}
|
||||
|
||||
if (set) {
|
||||
if (lit == tag->tagIds.end()) {
|
||||
tag->tagIds.push_back(tagId);
|
||||
/* keep the list sorted */
|
||||
tag->tagIds.sort();
|
||||
nNotifyType = NOTIFY_TYPE_ADD;
|
||||
}
|
||||
} else {
|
||||
if (tagId == 0) {
|
||||
/* remove all */
|
||||
delete(tag);
|
||||
mMsgTags.erase(mit);
|
||||
nNotifyType = NOTIFY_TYPE_DEL;
|
||||
} else {
|
||||
if (lit != tag->tagIds.end()) {
|
||||
tag->tagIds.erase(lit);
|
||||
nNotifyType = NOTIFY_TYPE_DEL;
|
||||
|
||||
if (tag->tagIds.size() == 0) {
|
||||
/* remove empty tag */
|
||||
delete(tag);
|
||||
mMsgTags.erase(mit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* UNLOCKED */
|
||||
|
||||
if (nNotifyType) {
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
|
||||
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGE_TAGS, nNotifyType);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3MsgService::resetMessageStandardTagTypes(MsgTagType& tags)
|
||||
{
|
||||
MsgTagType standardTags;
|
||||
getStandardTagTypes(standardTags);
|
||||
|
||||
std::map<uint32_t, std::pair<std::string, uint32_t> >::iterator mit;
|
||||
for (mit = standardTags.types.begin(); mit != standardTags.types.end(); mit++) {
|
||||
tags.types[mit->first] = mit->second;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* move message to trash based on the unique mid */
|
||||
bool p3MsgService::MessageToTrash(std::string mid, bool bTrash)
|
||||
|
@ -902,6 +1158,14 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
|||
{
|
||||
mi.msgflags |= RS_MSG_NEW;
|
||||
}
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_TRASH)
|
||||
{
|
||||
mi.msgflags |= RS_MSG_TRASH;
|
||||
}
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_UNREAD_BY_USER)
|
||||
{
|
||||
mi.msgflags |= RS_MSG_UNREAD_BY_USER;
|
||||
}
|
||||
|
||||
mi.ts = msg->sendTime;
|
||||
mi.srcId = msg->PeerId();
|
||||
|
@ -985,6 +1249,10 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
|
|||
{
|
||||
mis.msgflags |= RS_MSG_TRASH;
|
||||
}
|
||||
if (msg->msgFlags & RS_MSG_FLAGS_UNREAD_BY_USER)
|
||||
{
|
||||
mis.msgflags |= RS_MSG_UNREAD_BY_USER;
|
||||
}
|
||||
|
||||
mis.srcId = msg->PeerId();
|
||||
{
|
||||
|
|
|
@ -56,21 +56,25 @@ bool MsgNotifications(); /* popup - messages */
|
|||
bool getMessageNotifications(std::list<MsgInfoSummary> ¬eList);
|
||||
|
||||
bool getMessageSummaries(std::list<MsgInfoSummary> &msgList);
|
||||
bool getMessage(std::string mid, MessageInfo &msg);
|
||||
bool getMessage(std::string &mid, MessageInfo &msg);
|
||||
void getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox);
|
||||
|
||||
bool removeMsgId(std::string mid);
|
||||
bool markMsgIdRead(std::string mid);
|
||||
bool removeMsgId(std::string &mid);
|
||||
bool markMsgIdRead(std::string &mid, bool bUnreadByUser);
|
||||
|
||||
bool MessageSend(MessageInfo &info);
|
||||
bool MessageToDraft(MessageInfo &info);
|
||||
bool MessageToTrash(std::string mid, bool bTrash);
|
||||
|
||||
bool MessageGetTagTypes(MsgTagType& tags);
|
||||
bool MessageGetMsgTag(std::string msgId, MsgTagInfo& info);
|
||||
bool getMessageTagTypes(MsgTagType& tags);
|
||||
bool setMessageTagType(uint32_t tagId, std::string& text, uint32_t rgb_color);
|
||||
bool removeMessageTagType(uint32_t tagId);
|
||||
|
||||
bool MessageSetTagType(std::string& text, uint32_t tag_id, uint32_t rgb_color);
|
||||
bool MessageSetMsgTag(MsgTagInfo& );
|
||||
bool getMessageTag(std::string &msgId, MsgTagInfo& info);
|
||||
/* set == false && tagId == 0 --> remove all */
|
||||
bool setMessageTag(std::string &msgId, uint32_t tagId, bool set);
|
||||
|
||||
bool resetMessageStandardTagTypes(MsgTagType& tags);
|
||||
|
||||
void loadWelcomeMsg(); /* startup message */
|
||||
|
||||
|
@ -100,6 +104,8 @@ void initRsMI(RsMsgItem *msg, MessageInfo &mi);
|
|||
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
|
||||
RsMsgItem *initMIRsMsg(MessageInfo &info, std::string to);
|
||||
|
||||
void initStandardTagTypes();
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
|
||||
/* Mutex Required for stuff below */
|
||||
|
@ -117,7 +123,7 @@ RsMsgItem *initMIRsMsg(MessageInfo &info, std::string to);
|
|||
/* maps for tags types and msg tags */
|
||||
|
||||
std::map<uint32_t, RsMsgTagType*> mTags;
|
||||
std::map<std::string, RsMsgTags*> mMsgTags;
|
||||
std::map<uint32_t, RsMsgTags*> mMsgTags;
|
||||
|
||||
|
||||
Indicator msgChanged;
|
||||
|
|
|
@ -94,8 +94,12 @@ RsSerialType* init_item(RsMsgTagType& mtt)
|
|||
|
||||
RsSerialType* init_item(RsMsgTags& mt)
|
||||
{
|
||||
randString(SHORT_STR, mt.msgId);
|
||||
mt.tagId = rand()%3334;
|
||||
mt.msgId = rand()%3334;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 10; i++) {
|
||||
mt.tagIds.push_back(rand()%21341);
|
||||
}
|
||||
|
||||
return new RsMsgSerialiser();
|
||||
}
|
||||
|
@ -173,7 +177,7 @@ bool operator ==(const RsMsgTagType& mttLeft, const RsMsgTagType& mttRight)
|
|||
bool operator ==(const RsMsgTags& mtLeft, const RsMsgTags& mtRight)
|
||||
{
|
||||
if(mtLeft.msgId != mtRight.msgId) return false;
|
||||
if(mtLeft.tagId != mtRight.tagId) return false;
|
||||
if(mtLeft.tagIds != mtRight.tagIds) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue