Added read/unread state to channel service (copied from forum service).

Added new and missing tests of the RsItems.
Added new notifier on channel changes.
Reworked fill of channels in ChannelFeed. Now the channel tree is updated and not refilled.
Show unread message count in channels tree.
Fixed memory leak in context menu.
Show a new tray icon and action icon in MainWindow, when new channel messages are available.

Recompile of the GUI needed.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3626 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-10-07 00:17:42 +00:00
parent df20d69b29
commit fc0ff38206
22 changed files with 1181 additions and 653 deletions

View file

@ -34,6 +34,10 @@
#include "rstypes.h"
#include "rsdistrib.h" /* For FLAGS */
#define CHANNEL_MSG_STATUS_MASK 0x000f
#define CHANNEL_MSG_STATUS_READ 0x0001
#define CHANNEL_MSG_STATUS_UNREAD_BY_USER 0x0002
//! Stores information for a give channel id
/*!
* Stores all information for a given channel id
@ -167,6 +171,31 @@ virtual bool getChannelMsgList(std::string cId, std::list<ChannelMsgSummary> &ms
*/
virtual bool getChannelMessage(std::string cId, std::string mId, ChannelMsgInfo &msg) = 0;
/*!
* set message status
* @param cId channel id
* @param mId message id
* @param status status to set
* @param statusMask bitmask to modify
*/
virtual bool setMessageStatus(const std::string& cId,const std::string& mId, const uint32_t status, const uint32_t statusMask) = 0;
/*!
* set message status
* @param cId channel id
* @param mId message id
* @param status status
*/
virtual bool getMessageStatus(const std::string& cId, const std::string& mId, uint32_t& status) = 0;
/*!
* count the new and unread messages
* @param cId channel id
* @param newCount count of new messages
* @param unreadCount count of unread messages
*/
virtual bool getMessageCount(const std::string cId, unsigned int &newCount, unsigned int &unreadCount) = 0;
/*!
* send message contain in message info to the id indicated within it (make sure you set the channel id of the message info)
* @param info message to be sent

View file

@ -198,6 +198,7 @@ class NotifyBase
virtual void notifyPeerStatusChanged(const std::string& /* peer_id */, uint32_t /* status */) {}
/* one or more peers has changed the states */
virtual void notifyPeerStatusChangedSummary() {}
virtual void notifyChannelMsgReadSatusChanged(const std::string& /* channelId */, const std::string& /* msgId */, uint32_t /* status */) {}
virtual std::string askForPassword(const std::string& /* key_details */ ,bool /* prev_is_bad */ ) { return "" ;}
};
@ -217,6 +218,7 @@ const int NOTIFY_LIST_PUBLIC_CHAT = 13;
const int NOTIFY_LIST_PRIVATE_INCOMING_CHAT = 14;
const int NOTIFY_LIST_PRIVATE_OUTGOING_CHAT = 15;
const int NOTIFY_LIST_GROUPLIST = 16;
const int NOTIFY_LIST_CHANNELLIST_LOCKED = 17; // use connect with Qt::QueuedConnection
const int NOTIFY_TYPE_SAME = 0x01;
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */

View file

@ -74,6 +74,45 @@ std::ostream &RsChannelMsg::print(std::ostream &out, uint16_t indent)
return out;
}
void RsChannelReadStatus::clear()
{
RsDistribChildConfig::clear();
channelId.clear();
msgReadStatus.clear();
return;
}
std::ostream& RsChannelReadStatus::print(std::ostream &out, uint16_t indent = 0)
{
printRsItemBase(out, "RsChannelMsg", indent);
uint16_t int_Indent = indent + 2;
RsDistribChildConfig::print(out, int_Indent);
printIndent(out, int_Indent);
out << "ChannelId: " << channelId << std::endl;
std::map<std::string, uint32_t>::iterator mit = msgReadStatus.begin();
for(; mit != msgReadStatus.end(); mit++)
{
printIndent(out, int_Indent);
out << "msgId : " << mit->first << std::endl;
printIndent(out, int_Indent);
out << " status : " << mit->second << std::endl;
}
printRsItemEnd(out, "RsChannelMsg", indent);
return out;
}
/*************************************************************************/
/*************************************************************************/
@ -204,19 +243,207 @@ RsChannelMsg *RsChannelSerialiser::deserialiseMsg(void *data, uint32_t *pktsize)
}
uint32_t RsChannelSerialiser::sizeReadStatus(RsChannelReadStatus *item)
{
uint32_t s = 8; /* header */
/* RsDistribChildConfig stuff */
s += 4; /* save_type */
/* RsChannelReadStatus stuff */
s += GetTlvStringSize(item->channelId);
std::map<std::string, uint32_t>::iterator mit = item->msgReadStatus.begin();
for(; mit != item->msgReadStatus.end(); mit++)
{
s += GetTlvStringSize(mit->first); /* key */
s += 4; /* value */
}
return s;
}
/* serialise the data to the buffer */
bool RsChannelSerialiser::serialiseReadStatus(RsChannelReadStatus *item, void *data, uint32_t *pktsize)
{
uint32_t tlvsize = sizeReadStatus(item);
uint32_t offset = 0;
if (*pktsize < tlvsize)
return false; /* not enough space */
*pktsize = tlvsize;
bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize);
std::cerr << "RsChannelSerialiser::serialiseReadStatus() Header: " << ok << std::endl;
std::cerr << "RsChannelSerialiser::serialiseReadStatus() Size: " << tlvsize << std::endl;
/* skip the header */
offset += 8;
/* RsDistribMsg first */
ok &= setRawUInt32(data, tlvsize, &offset, item->save_type);
std::cerr << "RsChannelSerialiser::serialiseReadStatus() save_type: " << ok << std::endl;
/* RsChannelMsg */
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_GROUPID, item->channelId);
std::cerr << "RsChannelSerialiser::serialiseReadStatus() channelId: " << ok << std::endl;
std::map<std::string, uint32_t>::iterator mit = item->msgReadStatus.begin();
for(; mit != item->msgReadStatus.end(); mit++)
{
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSGID, mit->first); /* key */
ok &= setRawUInt32(data, tlvsize, &offset, mit->second); /* value */
}
std::cerr << "RsChannelSerialiser::serialiseReadStatus() msgReadStatus: " << ok << std::endl;
if (offset != tlvsize)
{
ok = false;
std::cerr << "RsChannelSerialiser::serialiseReadStatus() Size Error! " << std::endl;
}
return ok;
}
RsChannelReadStatus *RsChannelSerialiser::deserialiseReadStatus(void *data, uint32_t *pktsize)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_CHANNEL != getRsItemService(rstype)) ||
(RS_PKT_SUBTYPE_CHANNEL_READ_STATUS != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*pktsize < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*pktsize = rssize;
bool ok = true;
/* ready to load */
RsChannelReadStatus *item = new RsChannelReadStatus();
item->clear();
/* skip the header */
offset += 8;
/* RsDistribMsg first */
ok &= getRawUInt32(data, rssize, &offset, &(item->save_type));
/* RschannelMsg */
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_GROUPID, item->channelId);
std::string key;
uint32_t value;
while(offset != rssize)
{
key.clear();
value = 0;
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSGID, key); /* key */
/* incomplete key value pair? then fail*/
if(offset == rssize)
{
delete item;
return NULL;
}
ok &= getRawUInt32(data, rssize, &offset, &value); /* value */
item->msgReadStatus.insert(std::pair<std::string, uint32_t>(key, value));
}
if (!ok)
{
delete item;
return NULL;
}
return item;
}
/************************************************************/
uint32_t RsChannelSerialiser::size(RsItem *item)
{
return sizeMsg((RsChannelMsg *) item);
RsChannelMsg* dcm;
RsChannelReadStatus* drs;
if( NULL != ( dcm = dynamic_cast<RsChannelMsg*>(item)))
{
return sizeMsg(dcm);
}
else if(NULL != (drs = dynamic_cast<RsChannelReadStatus* >(item)))
{
return sizeReadStatus(drs);
}
return false;
}
bool RsChannelSerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize)
{
return serialiseMsg((RsChannelMsg *) item, data, pktsize);
RsChannelMsg* dcm;
RsChannelReadStatus* drs;
if( NULL != ( dcm = dynamic_cast<RsChannelMsg*>(item)))
{
return serialiseMsg(dcm, data, pktsize);
}
else if(NULL != (drs = dynamic_cast<RsChannelReadStatus* >(item)))
{
return serialiseReadStatus(drs, data, pktsize);
}
return false;
}
RsItem *RsChannelSerialiser::deserialise(void *data, uint32_t *pktsize)
{
return deserialiseMsg(data, pktsize);
/* get the type and size */
uint32_t rstype = getRsItemId(data);
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) ||
(RS_SERVICE_TYPE_CHANNEL != getRsItemService(rstype)))
{
return NULL; /* wrong type */
}
switch(getRsItemSubType(rstype))
{
case RS_PKT_SUBTYPE_CHANNEL_MSG:
return deserialiseMsg(data, pktsize);
case RS_PKT_SUBTYPE_CHANNEL_READ_STATUS:
return deserialiseReadStatus(data, pktsize);
default:
return NULL;
}
return NULL;
}

View file

@ -35,7 +35,8 @@
#include "serialiser/rsdistribitems.h"
const uint8_t RS_PKT_SUBTYPE_CHANNEL_MSG = 0x01;
const uint8_t RS_PKT_SUBTYPE_CHANNEL_MSG = 0x01;
const uint8_t RS_PKT_SUBTYPE_CHANNEL_READ_STATUS = 0x02;
/**************************************************************************/
@ -63,6 +64,29 @@ virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
};
/*!
* This is used to keep track of whether a message has been read
* by client
*/
class RsChannelReadStatus : public RsDistribChildConfig
{
public:
RsChannelReadStatus()
: RsDistribChildConfig(RS_SERVICE_TYPE_CHANNEL, RS_PKT_SUBTYPE_CHANNEL_READ_STATUS)
{ return; }
virtual ~RsChannelReadStatus() {return; }
virtual void clear();
virtual std::ostream& print(std::ostream &out, uint16_t indent);
std::string channelId;
/// a map which contains the read for messages within a forum
std::map<std::string, uint32_t> msgReadStatus;
};
class RsChannelSerialiser: public RsSerialType
{
public:
@ -83,6 +107,10 @@ virtual uint32_t sizeMsg(RsChannelMsg *);
virtual bool serialiseMsg(RsChannelMsg *item, void *data, uint32_t *size);
virtual RsChannelMsg *deserialiseMsg(void *data, uint32_t *size);
virtual uint32_t sizeReadStatus(RsChannelReadStatus* );
virtual bool serialiseReadStatus(RsChannelReadStatus* item, void* data, uint32_t *size);
virtual RsChannelReadStatus *deserialiseReadStatus(void* data, uint32_t *size);
};
/**************************************************************************/

View file

@ -25,6 +25,7 @@
#include "services/p3channels.h"
#include "util/rsdir.h"
#include "retroshare/rsiface.h"
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info)
{
@ -182,14 +183,14 @@ bool p3Channels::getChannelMsgList(std::string cId, std::list<ChannelMsgSummary>
return true;
}
bool p3Channels::getChannelMessage(std::string fId, std::string mId, ChannelMsgInfo &info)
bool p3Channels::getChannelMessage(std::string cId, std::string mId, ChannelMsgInfo &info)
{
std::list<std::string> msgIds;
std::list<std::string>::iterator it;
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
RsDistribMsg *msg = locked_getGroupMsg(fId, mId);
RsDistribMsg *msg = locked_getGroupMsg(cId, mId);
RsChannelMsg *cmsg = dynamic_cast<RsChannelMsg *>(msg);
if (!cmsg)
return false;
@ -285,9 +286,181 @@ bool p3Channels::ChannelMessageSend(ChannelMsgInfo &info)
std::string msgId = publishMsg(cmsg, toSign);
if (msgId.empty()) {
return false;
}
return setMessageStatus(info.channelId, msgId, CHANNEL_MSG_STATUS_READ, CHANNEL_MSG_STATUS_MASK);
}
bool p3Channels::setMessageStatus(const std::string& cId,const std::string& mId,const uint32_t status, const uint32_t statusMask)
{
bool changed = false;
uint32_t newStatus = 0;
{
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
std::list<RsChannelReadStatus *>::iterator lit = mReadStatus.begin();
for(; lit != mReadStatus.end(); lit++)
{
if((*lit)->channelId == cId)
{
RsChannelReadStatus* rsi = *lit;
uint32_t oldStatus = rsi->msgReadStatus[mId];
rsi->msgReadStatus[mId] &= ~statusMask;
rsi->msgReadStatus[mId] |= (status & statusMask);
newStatus = rsi->msgReadStatus[mId];
if (oldStatus != newStatus) {
changed = true;
}
break;
}
}
// if channel id does not exist create one
if(lit == mReadStatus.end())
{
RsChannelReadStatus* rsi = new RsChannelReadStatus();
rsi->channelId = cId;
rsi->msgReadStatus[mId] = status & statusMask;
mReadStatus.push_back(rsi);
saveList.push_back(rsi);
newStatus = rsi->msgReadStatus[mId];
changed = true;
}
if (changed) {
IndicateConfigChanged();
}
} /******* UNLOCKED ********/
if (changed) {
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHANNELLIST_LOCKED, NOTIFY_TYPE_MOD);
rsicontrol->getNotify().notifyChannelMsgReadSatusChanged(cId, mId, newStatus);
}
return true;
}
bool p3Channels::getMessageStatus(const std::string& cId, const std::string& mId, uint32_t& status)
{
status = 0;
RsStackMutex stack(distribMtx);
std::list<RsChannelReadStatus *>::iterator lit = mReadStatus.begin();
for(; lit != mReadStatus.end(); lit++)
{
if((*lit)->channelId == cId)
{
break;
}
}
if(lit == mReadStatus.end())
{
return false;
}
std::map<std::string, uint32_t >::iterator mit = (*lit)->msgReadStatus.find(mId);
if(mit != (*lit)->msgReadStatus.end())
{
status = mit->second;
return true;
}
return false;
}
bool p3Channels::getMessageCount(const std::string cId, unsigned int &newCount, unsigned int &unreadCount)
{
newCount = 0;
unreadCount = 0;
std::list<std::string> grpIds;
if (cId.empty()) {
// count all messages of all subscribed channels
getAllGroupList(grpIds);
} else {
// count all messages of one channels
grpIds.push_back(cId);
}
std::list<std::string>::iterator git;
for (git = grpIds.begin(); git != grpIds.end(); git++) {
std::string cId = *git;
uint32_t grpFlags;
{
// only flag is needed
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
GroupInfo *gi = locked_getGroupInfo(cId);
if (gi == NULL) {
return false;
}
grpFlags = gi->flags;
} /******* UNLOCKED ********/
if (grpFlags & (RS_DISTRIB_ADMIN | RS_DISTRIB_SUBSCRIBED)) {
std::list<std::string> msgIds;
if (getAllMsgList(cId, msgIds)) {
std::list<std::string>::iterator mit;
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
std::list<RsChannelReadStatus *>::iterator lit;
for(lit = mReadStatus.begin(); lit != mReadStatus.end(); lit++) {
if ((*lit)->channelId == cId) {
break;
}
}
if (lit == mReadStatus.end()) {
// no status available -> all messages are new
newCount += msgIds.size();
unreadCount += msgIds.size();
continue;
}
for (mit = msgIds.begin(); mit != msgIds.end(); mit++) {
std::map<std::string, uint32_t >::iterator rit = (*lit)->msgReadStatus.find(*mit);
if (rit == (*lit)->msgReadStatus.end()) {
// no status available -> message is new
newCount++;
unreadCount++;
continue;
}
if (rit->second & CHANNEL_MSG_STATUS_READ) {
// message is not new
if (rit->second & CHANNEL_MSG_STATUS_UNREAD_BY_USER) {
// message is unread
unreadCount++;
}
} else {
newCount++;
unreadCount++;
}
}
} /******* UNLOCKED ********/
}
}
return true;
}
bool p3Channels::channelExtraFileHash(std::string path, std::string chId, FileInfo& fInfo){
@ -636,7 +809,6 @@ bool p3Channels::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::stri
return locked_eventDuplicateMsg(grp, msg, id);
}
void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
{
std::string grpId = grp.grpId;
@ -655,12 +827,14 @@ void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
std::cerr << "p3Channels::locked_notifyGroupChanged() NEW UPDATE" << std::endl;
#endif
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAN_NEW, grpId, msgId, nullId);
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHANNELLIST_LOCKED, NOTIFY_TYPE_ADD);
break;
case GRP_UPDATE:
#ifdef CHANNEL_DEBUG
std::cerr << "p3Channels::locked_notifyGroupChanged() UPDATE" << std::endl;
#endif
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAN_UPDATE, grpId, msgId, nullId);
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHANNELLIST_LOCKED, NOTIFY_TYPE_MOD);
break;
case GRP_LOAD_KEY:
#ifdef CHANNEL_DEBUG
@ -671,6 +845,7 @@ void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
#ifdef CHANNEL_DEBUG
std::cerr << "p3Channels::locked_notifyGroupChanged() NEW MSG" << std::endl;
#endif
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHANNELLIST_LOCKED, NOTIFY_TYPE_ADD);
break;
case GRP_SUBSCRIBED:
#ifdef CHANNEL_DEBUG
@ -690,11 +865,13 @@ void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
/* check if downloads need to be started? */
}
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHANNELLIST_LOCKED, NOTIFY_TYPE_ADD);
break;
case GRP_UNSUBSCRIBED:
#ifdef CHANNEL_DEBUG
std::cerr << "p3Channels::locked_notifyGroupChanged() UNSUBSCRIBED" << std::endl;
#endif
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_CHANNELLIST_LOCKED, NOTIFY_TYPE_DEL);
/* won't stop downloads... */
@ -778,6 +955,24 @@ void p3Channels::cleanUpOldFiles(){
//TODO: if you want to config saving and loading for channel distrib service implement this method further
bool p3Channels::childLoadList(std::list<RsItem* >& configSaves)
{
RsChannelReadStatus* drs = NULL;
std::list<RsItem* >::iterator it;
for(it = configSaves.begin(); it != configSaves.end(); it++)
{
if(NULL != (drs = dynamic_cast<RsChannelReadStatus* >(*it)))
{
mReadStatus.push_back(drs);
saveList.push_back(drs);
}
else
{
std::cerr << "p3Channels::childLoadList(): Configs items loaded were incorrect!"
<< std::endl;
return false;
}
}
return true;
}

View file

@ -67,6 +67,10 @@ virtual bool getChannelMsgList(std::string cId, std::list<ChannelMsgSummary> &ms
virtual bool getChannelMessage(std::string cId, std::string mId, ChannelMsgInfo &msg);
virtual bool ChannelMessageSend(ChannelMsgInfo &info);
virtual bool setMessageStatus(const std::string& cId, const std::string& mId, const uint32_t status, const uint32_t statusMask);
virtual bool getMessageStatus(const std::string& cId, const std::string& mId, uint32_t& status);
virtual bool getMessageCount(const std::string cId, unsigned int &newCount, unsigned int &unreadCount);
virtual bool channelSubscribe(std::string cId, bool subscribe);
virtual bool channelExtraFileHash(std::string path, std::string chId, FileInfo& fInfo);
@ -106,6 +110,7 @@ bool cpyMsgFileToChFldr(std::string path, std::string fname, std::string chId, b
std::string mChannelsDir;
std::list<RsItem *> saveList;
std::list<RsChannelReadStatus *> mReadStatus;
};

View file

@ -564,9 +564,11 @@ void p3Forums::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_ADD);
break;
case GRP_SUBSCRIBED:
case GRP_UNSUBSCRIBED:
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_ADD);
break;
case GRP_UNSUBSCRIBED:
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_FORUMLIST_LOCKED, NOTIFY_TYPE_DEL);
break;
}
return p3GroupDistrib::locked_notifyGroupChanged(grp, flags);
}

View file

@ -276,6 +276,51 @@ bool operator==(const RsForumReadStatus& frs1, const RsForumReadStatus& frs2)
RsSerialType* init_item(RsChannelReadStatus& fRdStatus)
{
randString(SHORT_STR, fRdStatus.channelId);
fRdStatus.save_type = rand()%42;
std::map<std::string, uint32_t>::iterator mit = fRdStatus.msgReadStatus.begin();
std::string id;
uint32_t status = 0;
int numMaps = rand()%12;
for(int i = 0; i < numMaps; i++)
{
randString(SHORT_STR, id);
status = rand()%23;
fRdStatus.msgReadStatus.insert(std::pair<std::string, uint32_t>(id, status));
}
return new RsChannelSerialiser();
}
bool operator==(const RsChannelReadStatus& frs1, const RsChannelReadStatus& frs2)
{
if(frs1.channelId != frs2.channelId) return false;
if(frs1.save_type != frs2.save_type) return false;
if(frs1.msgReadStatus.size() != frs2.msgReadStatus.size()) return false;
std::map<std::string, uint32_t>::const_iterator mit
= frs1.msgReadStatus.begin();
for(;mit != frs1.msgReadStatus.end(); mit++)
{
if(mit->second != frs2.msgReadStatus.find(mit->first)->second) return false;
}
return true;
}
bool operator==(const RsBlogMsg& bMsg1,const RsBlogMsg& bMsg2)
{
@ -307,6 +352,7 @@ int main(){
test_RsItem<RsDistribGrpKey>(); REPORT("Serialise/Deserialise RsDistribGrpKey");
test_RsItem<RsDistribSignedMsg>(); REPORT("Serialise/Deserialise RsDistribSignedMsg");
test_RsItem<RsChannelMsg>(); REPORT("Serialise/Deserialise RsChannelMsg");
test_RsItem<RsChannelReadStatus>(); REPORT("Serialise/Deserialise RsChannelReadStatus");
test_RsItem<RsForumMsg>(); REPORT("Serialise/Deserialise RsForumMsg");
test_RsItem<RsForumReadStatus>(); REPORT("Serialise/Deserialise RsForumReadStatus");
test_RsItem<RsBlogMsg>(); REPORT("Serialise/Deserialise RsBlogMsg");

View file

@ -42,6 +42,18 @@ RsSerialType* init_item(RsChatMsgItem& cmi)
return new RsChatSerialiser();
}
RsSerialType* init_item(RsPrivateChatMsgConfigItem& pcmi)
{
randString(SHORT_STR, pcmi.configPeerId);
pcmi.chatFlags = rand()%34;
pcmi.configFlags = rand()%21;
pcmi.sendTime = rand()%422224;
randString(LARGE_STR, pcmi.message);
pcmi.recvTime = rand()%344443;
return new RsChatSerialiser();
}
RsSerialType* init_item(RsChatStatusItem& csi)
{
@ -123,6 +135,19 @@ bool operator ==(const RsChatMsgItem& cmiLeft,const RsChatMsgItem& cmiRight)
return true;
}
bool operator ==(const RsPrivateChatMsgConfigItem& pcmiLeft,const RsPrivateChatMsgConfigItem& pcmiRight)
{
if(pcmiLeft.configPeerId != pcmiRight.configPeerId) return false;
if(pcmiLeft.chatFlags != pcmiRight.chatFlags) return false;
if(pcmiLeft.configFlags != pcmiRight.configFlags) return false;
if(pcmiLeft.message != pcmiRight.message) return false;
if(pcmiLeft.sendTime != pcmiRight.sendTime) return false;
if(pcmiLeft.recvTime != pcmiRight.recvTime) return false;
return true;
}
bool operator ==(const RsChatStatusItem& csiLeft, const RsChatStatusItem& csiRight)
{
if(csiLeft.flags != csiRight.flags) return false;
@ -201,6 +226,7 @@ bool operator ==(const RsMsgSrcId& msLeft, const RsMsgSrcId& msRight)
int main()
{
test_RsItem<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsChatMsgItem");
test_RsItem<RsChatMsgItem >(); REPORT("Serialise/Deserialise RsPrivateChatMsgConfigItem");
test_RsItem<RsChatStatusItem >(); REPORT("Serialise/Deserialise RsChatStatusItem");
test_RsItem<RsChatAvatarItem >(); REPORT("Serialise/Deserialise RsChatAvatarItem");
test_RsItem<RsMsgItem >(); REPORT("Serialise/Deserialise RsMsgItem");