Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Using proper flags class for RS_MSG_[SOMETHING] #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions src/retroshare/rsmsgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,41 @@

#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 */
enum class RsMsgFlags: uint32_t
{
RS_MSG_INCOMING = 0x00000000, /* !Inbox */
RS_MSG_OUTGOING = 0x00000001, /* !Inbox */
RS_MSG_PENDING = 0x00000002, /* OutBox */
RS_MSG_DRAFT = 0x00000004, /* Draft */

RS_MSG_NEW = 0x00000010, /* New */
RS_MSG_TRASH = 0x00000020, /* Trash */
RS_MSG_UNREAD_BY_USER = 0x00000040, /* Unread by user */
RS_MSG_REPLIED = 0x00000080, /* Message is replied */
RS_MSG_FORWARDED = 0x00000100, /* Message is forwarded */
RS_MSG_STAR = 0x00000200, /* Message is marked with a star */

// system message
RS_MSG_USER_REQUEST = 0x00000400, /* user request */
RS_MSG_FRIEND_RECOMMENDATION = 0x00000800, /* friend recommendation */
RS_MSG_DISTANT = 0x00001000,/* message is distant */
RS_MSG_SIGNATURE_CHECKS = 0x00002000,/* message was signed, and signature checked */
RS_MSG_SIGNED = 0x00004000,/* message was signed and signature didn't check */
RS_MSG_LOAD_EMBEDDED_IMAGES = 0x00008000, /* load embedded images */
RS_MSG_PUBLISH_KEY = 0x00020000, /* publish key */
RS_MSG_SPAM = 0x00040000, /* Message is marked as spam */
};

RS_REGISTER_ENUM_FLAGS_TYPE(RsMsgFlags);

/* ORs of above */
#define RS_MSG_INBOX 0x00 /* Inbox */
#define RS_MSG_SENTBOX 0x01 /* Sentbox = OUTGOING */
#define RS_MSG_OUTBOX 0x03 /* Outbox = OUTGOING + PENDING */
#define RS_MSG_DRAFTBOX 0x05 /* Draftbox = OUTGOING + DRAFT */
#define RS_MSG_TRASHBOX 0x20 /* Trashbox = RS_MSG_TRASH */

#define RS_MSG_NEW 0x000010 /* New */
#define RS_MSG_TRASH 0x000020 /* Trash */
#define RS_MSG_UNREAD_BY_USER 0x000040 /* Unread by user */
#define RS_MSG_REPLIED 0x000080 /* Message is replied */
#define RS_MSG_FORWARDED 0x000100 /* Message is forwarded */
#define RS_MSG_STAR 0x000200 /* Message is marked with a star */
// system message
#define RS_MSG_USER_REQUEST 0x000400 /* user request */
#define RS_MSG_FRIEND_RECOMMENDATION 0x000800 /* friend recommendation */
#define RS_MSG_DISTANT 0x001000 /* message is distant */
#define RS_MSG_SIGNATURE_CHECKS 0x002000 /* message was signed, and signature checked */
#define RS_MSG_SIGNED 0x004000 /* message was signed and signature didn't check */
#define RS_MSG_LOAD_EMBEDDED_IMAGES 0x008000 /* load embedded images */
#define RS_MSG_PUBLISH_KEY 0x020000 /* publish key */
#define RS_MSG_SPAM 0x040000 /* Message is marked as spam */

#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION | RS_MSG_PUBLISH_KEY)
static const RsMsgFlags RS_MSG_INBOX (RsMsgFlags::RS_MSG_INCOMING); /* Inbox */
static const RsMsgFlags RS_MSG_SENTBOX (RsMsgFlags::RS_MSG_OUTGOING); /* Sentbox = OUTGOING */
static const RsMsgFlags RS_MSG_OUTBOX (RsMsgFlags::RS_MSG_OUTGOING | RsMsgFlags::RS_MSG_PENDING); /* Outbox = OUTGOING + PENDING */
static const RsMsgFlags RS_MSG_DRAFTBOX (RsMsgFlags::RS_MSG_OUTGOING | RsMsgFlags::RS_MSG_DRAFT); /* Draftbox = OUTGOING + DRAFT */
static const RsMsgFlags RS_MSG_TRASHBOX (RsMsgFlags::RS_MSG_TRASH); /* Trashbox = RS_MSG_TRASH */

static const RsMsgFlags RS_MSG_SYSTEM (RsMsgFlags::RS_MSG_USER_REQUEST | RsMsgFlags::RS_MSG_FRIEND_RECOMMENDATION | RsMsgFlags::RS_MSG_PUBLISH_KEY);

#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01
#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02
Expand Down Expand Up @@ -194,14 +201,14 @@ class MsgAddress: public RsSerializable

struct MessageInfo : RsSerializable
{
MessageInfo(): msgflags(0), size(0), count(0), ts(0) {}
MessageInfo(): msgflags(RsMsgFlags(0)), size(0), count(0), ts(0) {}

std::string msgId;

MsgAddress from;
MsgAddress to;

unsigned int msgflags;
RsMsgFlags msgflags;

std::set<MsgAddress> destinations;

Expand Down Expand Up @@ -247,13 +254,13 @@ typedef std::set<uint32_t> MsgTagInfo ;

struct MsgInfoSummary : RsSerializable
{
MsgInfoSummary() : msgflags(0), count(0), ts(0) {}
MsgInfoSummary() : msgflags(RsMsgFlags(0)), count(0), ts(0) {}

RsMailMessageId msgId;
MsgAddress from;
MsgAddress to; // specific address the message has been sent to (may be used for e.g. reply)

uint32_t msgflags;
RsMsgFlags msgflags;
MsgTagInfo msgtags;

std::string title;
Expand Down Expand Up @@ -677,7 +684,7 @@ class RsMsgs
* @param[in] systemFlag
* @return true on success
*/
virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) = 0;
virtual bool SystemMessage(const std::string &title, const std::string &message, RsMsgFlags systemFlag) = 0;

/**
* @brief MessageToDraft
Expand Down
4 changes: 2 additions & 2 deletions src/rsitems/rsmsgitems.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ RsItem *RsMsgSerialiser::create_item(uint16_t service,uint8_t type) const
void RsMsgItem::clear()
{
msgId = 0;
msgFlags = 0;
msgFlags = RsMsgItemFlags(0);
sendTime = 0;
recvTime = 0;
subject.clear();
Expand Down Expand Up @@ -132,7 +132,7 @@ void RsMsgParentId::serial_process(RsGenericSerializer::SerializeJob j,RsGeneric

void RsMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint32_t>(j,ctx,msgFlags,"msgFlags");
RsTypeSerializer::serial_process(j,ctx,msgFlags,"msgFlags");
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime");
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime");

Expand Down
59 changes: 33 additions & 26 deletions src/rsitems/rsmsgitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,37 @@ const uint8_t RS_PKT_SUBTYPE_MSG_OUTGOING_MAP_STORAGE = 0x0b;

/**************************************************************************/

const uint32_t RS_MSG_FLAGS_OUTGOING = 0x00000001;
const uint32_t RS_MSG_FLAGS_PENDING = 0x00000002;
const uint32_t RS_MSG_FLAGS_DRAFT = 0x00000004;
const uint32_t RS_MSG_FLAGS_NEW = 0x00000010;
const uint32_t RS_MSG_FLAGS_TRASH = 0x00000020;
const uint32_t RS_MSG_FLAGS_UNREAD_BY_USER = 0x00000040;
const uint32_t RS_MSG_FLAGS_REPLIED = 0x00000080;
const uint32_t RS_MSG_FLAGS_FORWARDED = 0x00000100;
const uint32_t RS_MSG_FLAGS_STAR = 0x00000200;
const uint32_t RS_MSG_FLAGS_PARTIAL = 0x00000400;
const uint32_t RS_MSG_FLAGS_USER_REQUEST = 0x00000800;
const uint32_t RS_MSG_FLAGS_FRIEND_RECOMMENDATION = 0x00001000;
const uint32_t RS_MSG_FLAGS_RETURN_RECEPT = 0x00002000;
const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x00004000;
const uint32_t RS_MSG_FLAGS_DISTANT = 0x00008000;
const uint32_t RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000;
const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000;
const uint32_t RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES = 0x00040000;
const uint32_t RS_MSG_FLAGS_DECRYPTED = 0x00080000;
const uint32_t RS_MSG_FLAGS_ROUTED = 0x00100000;
const uint32_t RS_MSG_FLAGS_PUBLISH_KEY = 0x00200000;
const uint32_t RS_MSG_FLAGS_SPAM = 0x00400000;

const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION | RS_MSG_FLAGS_PUBLISH_KEY;
enum class RsMsgItemFlags: uint32_t
{
RS_MSG_FLAGS_OUTGOING = 0x00000001,
RS_MSG_FLAGS_PENDING = 0x00000002,
RS_MSG_FLAGS_DRAFT = 0x00000004,
RS_MSG_FLAGS_NEW = 0x00000010,
RS_MSG_FLAGS_TRASH = 0x00000020,
RS_MSG_FLAGS_UNREAD_BY_USER = 0x00000040,
RS_MSG_FLAGS_REPLIED = 0x00000080,
RS_MSG_FLAGS_FORWARDED = 0x00000100,
RS_MSG_FLAGS_STAR = 0x00000200,
RS_MSG_FLAGS_PARTIAL = 0x00000400,
RS_MSG_FLAGS_USER_REQUEST = 0x00000800,
RS_MSG_FLAGS_FRIEND_RECOMMENDATION = 0x00001000,
RS_MSG_FLAGS_RETURN_RECEPT = 0x00002000,
RS_MSG_FLAGS_ENCRYPTED = 0x00004000,
RS_MSG_FLAGS_DISTANT = 0x00008000,
RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000,
RS_MSG_FLAGS_SIGNED = 0x00020000,
RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES = 0x00040000,
RS_MSG_FLAGS_DECRYPTED = 0x00080000,
RS_MSG_FLAGS_ROUTED = 0x00100000,
RS_MSG_FLAGS_PUBLISH_KEY = 0x00200000,
RS_MSG_FLAGS_SPAM = 0x00400000,
};

RS_REGISTER_ENUM_FLAGS_TYPE(RsMsgItemFlags);

const RsMsgItemFlags RS_MSG_FLAGS_SYSTEM = RsMsgItemFlags::RS_MSG_FLAGS_USER_REQUEST
| RsMsgItemFlags::RS_MSG_FLAGS_FRIEND_RECOMMENDATION
| RsMsgItemFlags::RS_MSG_FLAGS_PUBLISH_KEY;

typedef uint32_t MessageIdentifier;

Expand Down Expand Up @@ -101,7 +108,7 @@ class RsMsgItem: public RsMessageItem

// ----------- Specific fields ------------- //

uint32_t msgFlags;
RsMsgItemFlags msgFlags;
MessageIdentifier msgId;

uint32_t sendTime;
Expand Down Expand Up @@ -187,7 +194,7 @@ struct RsOutgoingMessageInfo: public RsSerializable

Rs::Msgs::MsgAddress origin;
Rs::Msgs::MsgAddress destination;
uint32_t flags;
RsMsgItemFlags flags;
GRouterMsgPropagationId grouter_id;
};

Expand Down
8 changes: 4 additions & 4 deletions src/rsserver/p3msgs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ uint32_t p3Msgs::sendMail(
trackingIds, errorMsg );
}

bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, RsMsgFlags systemFlag)
{
return mMsgSrv->SystemMessage(title, message, systemFlag);
}
Expand Down Expand Up @@ -357,17 +357,17 @@ bool p3Msgs::MessageRead(const std::string &mid, bool unreadByUser)

bool p3Msgs::MessageReplied(const std::string &mid, bool replied)
{
return mMsgSrv->setMsgFlag(mid, replied ? RS_MSG_FLAGS_REPLIED : 0, RS_MSG_FLAGS_REPLIED);
return mMsgSrv->setMsgFlag(mid, replied ? RsMsgItemFlags::RS_MSG_FLAGS_REPLIED : RsMsgItemFlags(0), RsMsgItemFlags::RS_MSG_FLAGS_REPLIED);
}

bool p3Msgs::MessageForwarded(const std::string &mid, bool forwarded)
{
return mMsgSrv->setMsgFlag(mid, forwarded ? RS_MSG_FLAGS_FORWARDED : 0, RS_MSG_FLAGS_FORWARDED);
return mMsgSrv->setMsgFlag(mid, forwarded ? RsMsgItemFlags::RS_MSG_FLAGS_FORWARDED : RsMsgItemFlags(0), RsMsgItemFlags::RS_MSG_FLAGS_FORWARDED);
}

bool p3Msgs::MessageLoadEmbeddedImages(const std::string &mid, bool load)
{
return mMsgSrv->setMsgFlag(mid, load ? RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES : 0, RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES);
return mMsgSrv->setMsgFlag(mid, load ? RsMsgItemFlags::RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES : RsMsgItemFlags(0), RsMsgItemFlags::RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES);
}

bool p3Msgs::getMessageTagTypes(MsgTagType& tags)
Expand Down
2 changes: 1 addition & 1 deletion src/rsserver/p3msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class p3Msgs: public RsMsgs

RS_DEPRECATED_FOR(sendMail)
virtual bool MessageSend(Rs::Msgs::MessageInfo &info)override ;
virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)override ;
virtual bool SystemMessage(const std::string &title, const std::string &message, RsMsgFlags systemFlag)override ;
virtual bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId)override ;
virtual bool MessageToTrash(const std::string &mid, bool bTrash)override ;
virtual bool MessageDelete(const std::string &mid)override ;
Expand Down
Loading