mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
finished cleaning GxsCircle Notifications
This commit is contained in:
parent
26dd716967
commit
32baccae97
8 changed files with 160 additions and 172 deletions
|
@ -45,25 +45,23 @@ extern RsGxsCircles* rsGxsCircles;
|
|||
|
||||
enum class RsGxsCircleType : uint32_t // 32 bit overkill, just for retrocompat
|
||||
{
|
||||
UNKNOWN = 0, /// Used to detect uninizialized values.
|
||||
PUBLIC = 1, /// Public distribution
|
||||
EXTERNAL = 2, /// Restricted to an external circle
|
||||
UNKNOWN = 0, /// Used to detect uninizialized values.
|
||||
PUBLIC = 1, /// Public distribution, based on GxsIds
|
||||
EXTERNAL = 2, /// Restricted to an external circle, based on GxsIds
|
||||
|
||||
/** Restricted to a group of friend nodes, the administrator of the circle
|
||||
* behave as a hub for them */
|
||||
NODES_GROUP = 3,
|
||||
NODES_GROUP = 3, /// Restricted to a group of friend nodes, the administrator of the circle behave as a hub for them
|
||||
/// Based on PGP nodes ids.
|
||||
|
||||
LOCAL = 4, /// not distributed at all
|
||||
|
||||
/** Self-restricted. Used only at creation time of self-restricted circles
|
||||
* when the circle id isn't known yet. Once the circle id is known the type
|
||||
* is set to EXTERNAL, and the external circle id is set to the id of the
|
||||
* circle itself.
|
||||
* circle itself. Based on GxsIds.
|
||||
*/
|
||||
EXT_SELF = 5,
|
||||
|
||||
/// distributed to nodes signed by your own PGP key only.
|
||||
YOUR_EYES_ONLY = 6
|
||||
YOUR_EYES_ONLY = 6 /// distributed to nodes signed by your own PGP key only.
|
||||
};
|
||||
|
||||
// TODO: convert to enum class
|
||||
|
@ -121,15 +119,29 @@ struct RsGxsCircleMsg : RsSerializable
|
|||
|
||||
struct RsGxsCircleDetails : RsSerializable
|
||||
{
|
||||
RsGxsCircleDetails() :
|
||||
mCircleType(static_cast<uint32_t>(RsGxsCircleType::EXTERNAL)),
|
||||
mAmIAllowed(false),mAmIAdmin(false) {}
|
||||
RsGxsCircleDetails() : mCircleType(RsGxsCircleType::EXTERNAL), mAmIAllowed(false),mAmIAdmin(false) {}
|
||||
~RsGxsCircleDetails() override;
|
||||
|
||||
// helper functions.
|
||||
bool isIdInCircle(const RsGxsId& id) const { return mAllowedGxsIds.find(id) != mAllowedGxsIds.end(); }
|
||||
bool isIdInInviteeList(const RsGxsId& id) const
|
||||
{
|
||||
auto it = mSubscriptionFlags.find(id);
|
||||
return (it != mSubscriptionFlags.end()) && (it->second & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST );
|
||||
}
|
||||
bool isIdRequestingMembership(const RsGxsId& id) const
|
||||
{
|
||||
auto it = mSubscriptionFlags.find(id);
|
||||
return it != mSubscriptionFlags.end() && (it->second & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED );
|
||||
}
|
||||
bool isGxsIdBased() const { return mCircleType==RsGxsCircleType::PUBLIC || mCircleType==RsGxsCircleType::EXTERNAL || mCircleType==RsGxsCircleType::EXT_SELF; }
|
||||
|
||||
// Members
|
||||
|
||||
RsGxsCircleId mCircleId;
|
||||
std::string mCircleName;
|
||||
|
||||
uint32_t mCircleType;
|
||||
RsGxsCircleType mCircleType;
|
||||
RsGxsCircleId mRestrictedCircleId;
|
||||
|
||||
/** true when one of load GXS ids belong to the circle allowed list (admin
|
||||
|
@ -165,39 +177,6 @@ struct RsGxsCircleDetails : RsSerializable
|
|||
|
||||
enum class RsGxsCircleEventCode: uint8_t
|
||||
{
|
||||
// Notications received depending on wether you got a membership request, if you
|
||||
// are admin of that circle, etc.
|
||||
//
|
||||
// Message-based notifications:
|
||||
//
|
||||
// +---------------------------+----------------------------+
|
||||
// | Membership request | Membership cancellation |
|
||||
// +-------------+-------------+-------------+--------------+
|
||||
// | Admin | Not admin | Admin | Not admin |
|
||||
// +--------------------+-------------+-------------+----------------------------+
|
||||
// | in invitee list | 0x04 | 0x04 | 0x03 | 0x03 |
|
||||
// +--------------------+-------------+-------------+-------------+--------------+
|
||||
// |not in invitee list | 0x01 | X | X | X |
|
||||
// +--------------------+-------------+-------------+-------------+--------------+
|
||||
//
|
||||
// Note: in this case, the GxsId never belongs to you, since you dont need to handle
|
||||
// notifications for actions you took yourself (leave/join a circle)
|
||||
//
|
||||
// Group-based notifications, the GxsId belongs to you:
|
||||
//
|
||||
// +---------------------------+----------------------------+
|
||||
// | GxsId joins invitee list | GxsId leaves invitee list |
|
||||
// +-------------+-------------+-------------+--------------+
|
||||
// | Id is yours| Id is not | Id is yours | Id is not |
|
||||
// +--------------------+-------------+-------------+-------------+--------------+
|
||||
// | Has Member request | 0x06 | 0x04 | 0x05 | 0x03 |
|
||||
// +--------------------+-------------+-------------+-------------+--------------+
|
||||
// | No Member request | 0x02 | X | 0x05 | X |
|
||||
// +--------------------+-------------+-------------+-------------+--------------+
|
||||
//
|
||||
// Note: In this case you're never an admin of the circle, since these notification
|
||||
// would be a direct consequence of your own actions.
|
||||
|
||||
// Notifications be only have 4 different possibilities:
|
||||
//
|
||||
// invitee list join/leave and
|
||||
|
@ -215,37 +194,37 @@ enum class RsGxsCircleEventCode: uint8_t
|
|||
* Sent when we receive a membership request msg for a particular circle.
|
||||
*
|
||||
* mCircleId contains the circle id and mGxsId is the id requesting membership */
|
||||
CIRCLE_MEMBERSHIP_REQUEST = 0x01,
|
||||
CIRCLE_MEMBERSHIP_REQUEST = 0x01,
|
||||
|
||||
/**
|
||||
* Sent when the ID has been added to the circle invitee list.
|
||||
*
|
||||
* mCircleId is the circle that invites me, and mGxsId is my own Id that is invited */
|
||||
CIRCLE_MEMBERSHIP_INVITE = 0x02,
|
||||
CIRCLE_MEMBERSHIP_ID_ADDED_TO_INVITEE_LIST = 0x02,
|
||||
|
||||
/**
|
||||
* Sent when a GxsId annouces its will to not be in the circle.
|
||||
*
|
||||
* mCircleId contains the circle id and mGxsId is the id dropping membership */
|
||||
CIRCLE_MEMBERSHIP_LEAVE = 0x03,
|
||||
CIRCLE_MEMBERSHIP_LEAVE = 0x03,
|
||||
|
||||
/**
|
||||
* Sent when the Id has been removed from the invitee list.
|
||||
*
|
||||
* mCircleId contains the circle id and mGxsId is the id that was revoqued * by admin */
|
||||
CIRCLE_MEMBERSHIP_REVOKED = 0x05,
|
||||
CIRCLE_MEMBERSHIP_ID_REMOVED_FROM_INVITEE_LIST = 0x04,
|
||||
|
||||
/**
|
||||
* Means a new circle has been received.
|
||||
*
|
||||
* mCircleId contains the circle id */
|
||||
NEW_CIRCLE = 0x07,
|
||||
NEW_CIRCLE = 0x05,
|
||||
|
||||
/**
|
||||
* Means that the circle cache has updated, and membership status that is displayed should probably be updated to.
|
||||
*
|
||||
* no additional information. Simply means that the info previously from the cache has changed. */
|
||||
CACHE_DATA_UPDATED = 0x08,
|
||||
CACHE_DATA_UPDATED = 0x06,
|
||||
};
|
||||
|
||||
struct RsGxsCircleEvent: RsEvent
|
||||
|
|
|
@ -115,11 +115,13 @@ const uint32_t RS_FEED_ITEM_CHAT_NEW = RS_FEED_TYPE_CHAT | 0x0001;
|
|||
const uint32_t RS_FEED_ITEM_MESSAGE = RS_FEED_TYPE_MSG | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_FILES_NEW = RS_FEED_TYPE_FILES | 0x0001;
|
||||
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REQ = RS_FEED_TYPE_CIRCLE | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_INVIT_REC = RS_FEED_TYPE_CIRCLE | 0x0002;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_LEAVE = RS_FEED_TYPE_CIRCLE | 0x0003;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_JOIN = RS_FEED_TYPE_CIRCLE | 0x0004;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REVOKED = RS_FEED_TYPE_CIRCLE | 0x0005;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REQ = RS_FEED_TYPE_CIRCLE | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_INVITE_REC = RS_FEED_TYPE_CIRCLE | 0x0002;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_LEAVE = RS_FEED_TYPE_CIRCLE | 0x0003;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_JOIN = RS_FEED_TYPE_CIRCLE | 0x0004;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_ACCEPTED = RS_FEED_TYPE_CIRCLE | 0x0005;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REVOKED = RS_FEED_TYPE_CIRCLE | 0x0006;
|
||||
const uint32_t RS_FEED_ITEM_CIRCLE_INVITE_CANCELLED= RS_FEED_TYPE_CIRCLE | 0x0007;
|
||||
|
||||
const uint32_t RS_MESSAGE_CONNECT_ATTEMPT = 0x0001;
|
||||
|
||||
|
|
|
@ -566,13 +566,15 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||
ev->mGxsId = msg.mMeta.mAuthorId;
|
||||
|
||||
if (msg.stuff == "SUBSCRIPTION_REQUEST_UNSUBSCRIBE")
|
||||
{
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE;
|
||||
else if(details.mAllowedGxsIds.find(msg.mMeta.mAuthorId) != details.mAllowedGxsIds.end())
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN;
|
||||
else
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
else if(msg.stuff == "SUBSCRIPTION_REQUEST_SUBSCRIBE")
|
||||
{
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST;
|
||||
|
||||
rsEvents->postEvent(ev);
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
}
|
||||
|
||||
mCircleCache.erase(circle_id);
|
||||
|
@ -615,13 +617,6 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||
|
||||
if(rsEvents)
|
||||
{
|
||||
std::list<RsGxsId> own_ids_lst;
|
||||
rsIdentity->getOwnIds(own_ids_lst,false); // retrieve own identities
|
||||
|
||||
std::set<RsGxsId> own_ids;
|
||||
for(auto& id:own_ids_lst)
|
||||
own_ids.insert(id); // put them in a std::set for O(log(n)) search
|
||||
|
||||
if(c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW|| c->getType() == RsGxsNotify::TYPE_PUBLISHED)
|
||||
{
|
||||
auto ev = std::make_shared<RsGxsCircleEvent>();
|
||||
|
@ -634,17 +629,11 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||
|
||||
RsGxsCircleGroupItem *new_circle_grp_item = dynamic_cast<RsGxsCircleGroupItem*>(groupChange->mNewGroupItem);
|
||||
|
||||
std::list<RsGxsId> added_identities;
|
||||
|
||||
for(auto& gxs_id: new_circle_grp_item->gxsIdSet.ids)
|
||||
if(own_ids.find(gxs_id)!=own_ids.end())
|
||||
added_identities.push_back(gxs_id);
|
||||
|
||||
for(auto& gxs_id:added_identities)
|
||||
{
|
||||
auto ev = std::make_shared<RsGxsCircleEvent>();
|
||||
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE;
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_ID_ADDED_TO_INVITEE_LIST;
|
||||
ev->mCircleId = RsGxsCircleId(*git);
|
||||
ev->mGxsId = gxs_id;
|
||||
|
||||
|
@ -669,36 +658,29 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||
|
||||
// First of all, we check if there is a difference between the old and new list of invited members
|
||||
|
||||
std::list<RsGxsId> added_identities, removed_identities;
|
||||
|
||||
for(auto& gxs_id: new_circle_grp_item->gxsIdSet.ids)
|
||||
if(old_circle_grp_item->gxsIdSet.ids.find(gxs_id) == old_circle_grp_item->gxsIdSet.ids.end() && own_ids.find(gxs_id)!=own_ids.end())
|
||||
added_identities.push_back(gxs_id);
|
||||
if(old_circle_grp_item->gxsIdSet.ids.find(gxs_id) == old_circle_grp_item->gxsIdSet.ids.end())
|
||||
{
|
||||
auto ev = std::make_shared<RsGxsCircleEvent>();
|
||||
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_ID_ADDED_TO_INVITEE_LIST;
|
||||
ev->mCircleId = circle_id;
|
||||
ev->mGxsId = gxs_id;
|
||||
|
||||
rsEvents->sendEvent(ev);
|
||||
}
|
||||
|
||||
for(auto& gxs_id: old_circle_grp_item->gxsIdSet.ids)
|
||||
if(new_circle_grp_item->gxsIdSet.ids.find(gxs_id) == old_circle_grp_item->gxsIdSet.ids.end() && own_ids.find(gxs_id)!=own_ids.end())
|
||||
removed_identities.push_back(gxs_id);
|
||||
if(new_circle_grp_item->gxsIdSet.ids.find(gxs_id) == old_circle_grp_item->gxsIdSet.ids.end())
|
||||
{
|
||||
auto ev = std::make_shared<RsGxsCircleEvent>();
|
||||
|
||||
for(auto& gxs_id:added_identities)
|
||||
{
|
||||
auto ev = std::make_shared<RsGxsCircleEvent>();
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_ID_REMOVED_FROM_INVITEE_LIST;
|
||||
ev->mCircleId = circle_id;
|
||||
ev->mGxsId = gxs_id;
|
||||
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE;
|
||||
ev->mCircleId = circle_id;
|
||||
ev->mGxsId = gxs_id;
|
||||
|
||||
rsEvents->sendEvent(ev);
|
||||
}
|
||||
for(auto& gxs_id:removed_identities)
|
||||
{
|
||||
auto ev = std::make_shared<RsGxsCircleEvent>();
|
||||
|
||||
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOKED;
|
||||
ev->mCircleId = circle_id;
|
||||
ev->mGxsId = gxs_id;
|
||||
|
||||
rsEvents->sendEvent(ev);
|
||||
}
|
||||
rsEvents->sendEvent(ev);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -720,8 +702,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||
/******************* RsCircles Interface ***************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
bool p3GxsCircles::getCircleDetails(
|
||||
const RsGxsCircleId& id, RsGxsCircleDetails& details)
|
||||
bool p3GxsCircles::getCircleDetails(const RsGxsCircleId& id, RsGxsCircleDetails& details)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_CIRCLES
|
||||
|
@ -818,7 +799,7 @@ int p3GxsCircles::canSend(const RsGxsCircleId &circleId, const RsPgpId &id, bool
|
|||
if (mCircleCache.is_cached(circleId))
|
||||
{
|
||||
RsGxsCircleCache &data = mCircleCache.ref(circleId);
|
||||
should_encrypt = (data.mCircleType == GXS_CIRCLE_TYPE_EXTERNAL);
|
||||
should_encrypt = (data.mCircleType == RsGxsCircleType::EXTERNAL);
|
||||
|
||||
if (data.isAllowedPeer(id))
|
||||
return 1;
|
||||
|
@ -1051,7 +1032,7 @@ RsGenExchange::ServiceCreate_Return p3GxsCircles::service_CreateGroup(RsGxsGrpIt
|
|||
|
||||
RsGxsCircleCache::RsGxsCircleCache()
|
||||
{
|
||||
mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
|
||||
mCircleType = RsGxsCircleType::EXTERNAL;
|
||||
mIsExternal = true;
|
||||
mUpdateTime = 0;
|
||||
mGroupStatus = 0;
|
||||
|
@ -1070,8 +1051,8 @@ bool RsGxsCircleCache::loadBaseCircle(const RsGxsCircleGroup &circle)
|
|||
mUpdateTime = time(NULL);
|
||||
// mProcessedCircles.insert(mCircleId);
|
||||
|
||||
mCircleType = circle.mMeta.mCircleType;
|
||||
mIsExternal = (mCircleType != GXS_CIRCLE_TYPE_LOCAL);
|
||||
mCircleType = static_cast<RsGxsCircleType>(circle.mMeta.mCircleType);
|
||||
mIsExternal = (mCircleType != RsGxsCircleType::LOCAL);
|
||||
mGroupStatus = circle.mMeta.mGroupStatus;
|
||||
mGroupSubscribeFlags = circle.mMeta.mSubscribeFlags;
|
||||
mOriginator = circle.mMeta.mOriginator ;
|
||||
|
|
|
@ -145,7 +145,7 @@ class RsGxsCircleCache
|
|||
RsGxsCircleId mCircleId;
|
||||
std::string mCircleName;
|
||||
|
||||
uint32_t mCircleType;
|
||||
RsGxsCircleType mCircleType;
|
||||
bool mIsExternal;
|
||||
RsGxsCircleId mRestrictedCircleId ; // circle ID that circle is restricted to.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue