mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 07:47:03 -05:00
moved GxsNotify classes to rsgxsnotify.h internal to gxs (not visible in API) since it is unused in GUI. Added event item in forum to handle moderator list changes
This commit is contained in:
parent
ae54e53bc1
commit
f7199f1f1c
@ -1110,6 +1110,7 @@ static void addMessageChanged(std::map<RsGxsGroupId, std::set<RsGxsMessageId> >
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
|
void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
|
||||||
{
|
{
|
||||||
std::cerr << "*********************************** RsGenExchange::receiveChanges()" << std::endl;
|
std::cerr << "*********************************** RsGenExchange::receiveChanges()" << std::endl;
|
||||||
@ -1155,6 +1156,7 @@ void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
|
|||||||
|
|
||||||
if(rsEvents) rsEvents->postEvent(std::move(evt));
|
if(rsEvents) rsEvents->postEvent(std::move(evt));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool RsGenExchange::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
|
bool RsGenExchange::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, bool subscribe)
|
||||||
{
|
{
|
||||||
@ -3263,6 +3265,7 @@ void RsGenExchange::performUpdateValidation()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RsGxsGrpMetaData *oldGrpMeta(mit->second->metaData);
|
RsGxsGrpMetaData *oldGrpMeta(mit->second->metaData);
|
||||||
|
RsNxsGrp *oldGrp(mit->second);
|
||||||
|
|
||||||
if(updateValid(*oldGrpMeta, *gu.newGrp))
|
if(updateValid(*oldGrpMeta, *gu.newGrp))
|
||||||
{
|
{
|
||||||
@ -3285,21 +3288,21 @@ void RsGenExchange::performUpdateValidation()
|
|||||||
|
|
||||||
RsGxsGroupUpdate *c = new RsGxsGroupUpdate();
|
RsGxsGroupUpdate *c = new RsGxsGroupUpdate();
|
||||||
|
|
||||||
c->mGroupId = gu.newGrp->grpId ;
|
c->mNewGroupItem = dynamic_cast<RsGxsGrpItem*>(mSerialiser->deserialise(gu.newGrp->grp.bin_data,&gu.newGrp->grp.bin_len));
|
||||||
c->mNewGroup = gu.newGrp->clone(); // make a copy because mDataStore will destroy it on update
|
c->mNewGroupItem->meta = *gu.newGrp->metaData; // gu.newGrp will be deleted because mDataStore will destroy it on update
|
||||||
c->mOldGroup = mit->second; // do not make a copy since we own the memory
|
|
||||||
|
|
||||||
mit->second = nullptr; // prevents deletion in auto delete map
|
c->mOldGroupItem = dynamic_cast<RsGxsGrpItem*>(mSerialiser->deserialise(oldGrp->grp.bin_data,&oldGrp->grp.bin_len));
|
||||||
|
c->mOldGroupItem->meta = *oldGrpMeta; // no need to delete mit->second, as it will be deleted automatically in the temporary map
|
||||||
|
|
||||||
mNotifications.push_back(c);
|
mNotifications.push_back(c);
|
||||||
|
|
||||||
// finally, add the group to
|
// finally, add the group to the list to send to mDataStore
|
||||||
|
|
||||||
grps.push_back(gu.newGrp);
|
grps.push_back(gu.newGrp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete gu.newGrp;
|
delete gu.newGrp; // delete here because mDataStore will not take care of this one. no need to delete mit->second, as it will be deleted automatically in the temporary map
|
||||||
gu.newGrp = NULL ;
|
gu.newGrp = NULL ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "rsnxsobserver.h"
|
#include "rsnxsobserver.h"
|
||||||
#include "retroshare/rsgxsservice.h"
|
#include "retroshare/rsgxsservice.h"
|
||||||
#include "rsitems/rsnxsitems.h"
|
#include "rsitems/rsnxsitems.h"
|
||||||
|
#include "gxs/rsgxsnotify.h"
|
||||||
#include "rsgxsutil.h"
|
#include "rsgxsutil.h"
|
||||||
|
|
||||||
template<class GxsItem, typename Identity = std::string>
|
template<class GxsItem, typename Identity = std::string>
|
||||||
@ -262,12 +263,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool getPublishedMsgMeta(const uint32_t& token,RsMsgMetaData& meta);
|
bool getPublishedMsgMeta(const uint32_t& token,RsMsgMetaData& meta);
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
/*!
|
/*!
|
||||||
* Gxs services should call this for automatic handling of
|
* Gxs services should call this for automatic handling of
|
||||||
* changes, send
|
* changes, send
|
||||||
* @param changes
|
* @param changes
|
||||||
*/
|
*/
|
||||||
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes);
|
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief acceptNewGroup
|
* \brief acceptNewGroup
|
||||||
@ -748,9 +751,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void processRecvdData();
|
void processRecvdData();
|
||||||
|
@ -672,6 +672,7 @@ HEADERS += rsitems/rsnxsitems.h \
|
|||||||
util/rsdbbind.h \
|
util/rsdbbind.h \
|
||||||
util/contentvalue.h \
|
util/contentvalue.h \
|
||||||
gxs/rsgxsutil.h \
|
gxs/rsgxsutil.h \
|
||||||
|
gxs/rsgxsnotify.h \
|
||||||
gxs/gxssecurity.h \
|
gxs/gxssecurity.h \
|
||||||
gxs/rsgds.h \
|
gxs/rsgds.h \
|
||||||
gxs/rsgxs.h \
|
gxs/rsgxs.h \
|
||||||
|
@ -112,6 +112,7 @@ enum class RsForumEventCode: uint8_t
|
|||||||
SUBSCRIBE_STATUS_CHANGED = 0x05, /// forum was subscribed or unsubscribed
|
SUBSCRIBE_STATUS_CHANGED = 0x05, /// forum was subscribed or unsubscribed
|
||||||
READ_STATUS_CHANGED = 0x06, /// msg was read or marked unread
|
READ_STATUS_CHANGED = 0x06, /// msg was read or marked unread
|
||||||
STATISTICS_CHANGED = 0x07, /// suppliers and how many messages they have changed
|
STATISTICS_CHANGED = 0x07, /// suppliers and how many messages they have changed
|
||||||
|
MODERATOR_LIST_CHANGED = 0x08, /// forum moderation list has changed.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RsGxsForumEvent: RsEvent
|
struct RsGxsForumEvent: RsEvent
|
||||||
@ -123,6 +124,8 @@ struct RsGxsForumEvent: RsEvent
|
|||||||
RsForumEventCode mForumEventCode;
|
RsForumEventCode mForumEventCode;
|
||||||
RsGxsGroupId mForumGroupId;
|
RsGxsGroupId mForumGroupId;
|
||||||
RsGxsMessageId mForumMsgId;
|
RsGxsMessageId mForumMsgId;
|
||||||
|
std::list<RsGxsId> mModeratorsAdded;
|
||||||
|
std::list<RsGxsId> mModeratorsRemoved;
|
||||||
|
|
||||||
///* @see RsEvent @see RsSerializable
|
///* @see RsEvent @see RsSerializable
|
||||||
void serial_process(
|
void serial_process(
|
||||||
@ -133,6 +136,9 @@ struct RsGxsForumEvent: RsEvent
|
|||||||
RS_SERIAL_PROCESS(mForumEventCode);
|
RS_SERIAL_PROCESS(mForumEventCode);
|
||||||
RS_SERIAL_PROCESS(mForumGroupId);
|
RS_SERIAL_PROCESS(mForumGroupId);
|
||||||
RS_SERIAL_PROCESS(mForumMsgId);
|
RS_SERIAL_PROCESS(mForumMsgId);
|
||||||
|
RS_SERIAL_PROCESS(mForumMsgId);
|
||||||
|
RS_SERIAL_PROCESS(mModeratorsAdded);
|
||||||
|
RS_SERIAL_PROCESS(mModeratorsRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RsGxsForumEvent() override;
|
~RsGxsForumEvent() override;
|
||||||
|
@ -116,12 +116,14 @@ struct RsGxsIface
|
|||||||
*/
|
*/
|
||||||
virtual uint16_t serviceType() const =0;
|
virtual uint16_t serviceType() const =0;
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
/*!
|
/*!
|
||||||
* Gxs services should call this for automatic handling of
|
* Gxs services should call this for automatic handling of
|
||||||
* changes, send
|
* changes, send
|
||||||
* @param changes
|
* @param changes
|
||||||
*/
|
*/
|
||||||
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
virtual void receiveChanges(std::vector<RsGxsNotify*>& changes) = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @return handle to token service for this GXS service
|
* @return handle to token service for this GXS service
|
||||||
|
@ -72,6 +72,7 @@ public:
|
|||||||
|
|
||||||
~RsGxsIfaceHelper() = default;
|
~RsGxsIfaceHelper() = default;
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
/*!
|
/*!
|
||||||
* Gxs services should call this for automatic handling of
|
* Gxs services should call this for automatic handling of
|
||||||
* changes, send
|
* changes, send
|
||||||
@ -81,6 +82,7 @@ public:
|
|||||||
{
|
{
|
||||||
mGxs.receiveChanges(changes);
|
mGxs.receiveChanges(changes);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Generic Lists */
|
/* Generic Lists */
|
||||||
|
|
||||||
|
@ -32,86 +32,6 @@ typedef uint32_t TurtleRequestId;
|
|||||||
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
|
typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > GxsMsgMetaMap;
|
||||||
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;
|
typedef std::map<RsGxsGrpMsgIdPair, std::vector<RsMsgMetaData> > GxsMsgRelatedMetaMap;
|
||||||
|
|
||||||
class RsNxsGrp;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* The aim of this class is to abstract how changes are represented so they can
|
|
||||||
* be determined outside the client API without explcitly enumerating all
|
|
||||||
* possible changes at the interface
|
|
||||||
*/
|
|
||||||
struct RsGxsNotify
|
|
||||||
{
|
|
||||||
enum NotifyType
|
|
||||||
{
|
|
||||||
TYPE_UNKNOWN = 0x00,
|
|
||||||
TYPE_PUBLISHED = 0x01,
|
|
||||||
TYPE_RECEIVED_NEW = 0x02,
|
|
||||||
TYPE_PROCESSED = 0x03,
|
|
||||||
TYPE_RECEIVED_PUBLISHKEY = 0x04,
|
|
||||||
TYPE_RECEIVED_DISTANT_SEARCH_RESULTS = 0x05,
|
|
||||||
TYPE_STATISTICS_CHANGED = 0x06,
|
|
||||||
TYPE_UPDATED = 0x07,
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual ~RsGxsNotify() {}
|
|
||||||
virtual NotifyType getType() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Relevant to group changes
|
|
||||||
*/
|
|
||||||
class RsGxsGroupChange : public RsGxsNotify
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsGxsGroupChange(NotifyType type, bool metaChange) : mNotifyType(type), mMetaChange(metaChange) {}
|
|
||||||
std::list<RsGxsGroupId> mGrpIdList;
|
|
||||||
NotifyType getType() override { return mNotifyType;}
|
|
||||||
bool metaChange() { return mMetaChange; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
NotifyType mNotifyType;
|
|
||||||
bool mMetaChange;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RsGxsGroupUpdate : public RsGxsNotify
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsGxsGroupUpdate() : mOldGroup(nullptr),mNewGroup(nullptr) {}
|
|
||||||
|
|
||||||
RsGxsGroupId mGroupId;
|
|
||||||
RsNxsGrp *mOldGroup;
|
|
||||||
RsNxsGrp *mNewGroup;
|
|
||||||
|
|
||||||
NotifyType getType() override { return RsGxsNotify::TYPE_UPDATED;}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class RsGxsDistantSearchResultChange: public RsGxsNotify
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsGxsDistantSearchResultChange(TurtleRequestId id,const RsGxsGroupId& group_id) : mRequestId(id),mGroupId(group_id){}
|
|
||||||
|
|
||||||
NotifyType getType() { return TYPE_RECEIVED_DISTANT_SEARCH_RESULTS ; }
|
|
||||||
|
|
||||||
TurtleRequestId mRequestId ;
|
|
||||||
RsGxsGroupId mGroupId;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Relevant to message changes
|
|
||||||
*/
|
|
||||||
class RsGxsMsgChange : public RsGxsNotify
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsGxsMsgChange(NotifyType type, bool metaChange) : NOTIFY_TYPE(type), mMetaChange(metaChange) {}
|
|
||||||
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgChangeMap;
|
|
||||||
NotifyType getType(){ return NOTIFY_TYPE;}
|
|
||||||
bool metaChange() { return mMetaChange; }
|
|
||||||
private:
|
|
||||||
const NotifyType NOTIFY_TYPE;
|
|
||||||
bool mMetaChange;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // RSGXSSERVICE_H
|
#endif // RSGXSSERVICE_H
|
||||||
|
@ -189,6 +189,7 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||||||
for(it = changes.begin(); it != changes.end(); ++it)
|
for(it = changes.begin(); it != changes.end(); ++it)
|
||||||
{
|
{
|
||||||
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
|
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
|
||||||
|
|
||||||
if (msgChange)
|
if (msgChange)
|
||||||
{
|
{
|
||||||
if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED) /* message received */
|
if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED) /* message received */
|
||||||
@ -328,6 +329,49 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RsGxsGroupUpdate *grpUpdate = dynamic_cast<RsGxsGroupUpdate*>(*it);
|
||||||
|
|
||||||
|
if (grpUpdate && rsEvents)
|
||||||
|
{
|
||||||
|
// Happens when the group data has changed. In this case we need to analyse the old and new group in order to detect possible notifications for clients
|
||||||
|
|
||||||
|
RsGxsForumGroupItem *old_forum_grp_item = dynamic_cast<RsGxsForumGroupItem*>(grpUpdate->mOldGroupItem);
|
||||||
|
RsGxsForumGroupItem *new_forum_grp_item = dynamic_cast<RsGxsForumGroupItem*>(grpUpdate->mNewGroupItem);
|
||||||
|
|
||||||
|
if(old_forum_grp_item == nullptr || new_forum_grp_item == nullptr)
|
||||||
|
{
|
||||||
|
RsErr() << __PRETTY_FUNCTION__ << " received GxsGroupUpdate item with mOldGroup and mNewGroup not of type RsGxsForumGroupItem. This is inconsistent!" << std::endl;
|
||||||
|
delete grpUpdate;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First of all, we check if there is a difference between the old and new list of moderators
|
||||||
|
|
||||||
|
std::list<RsGxsId> added_mods, removed_mods;
|
||||||
|
|
||||||
|
for(auto& gxs_id: new_forum_grp_item->mGroup.mAdminList.ids)
|
||||||
|
if(old_forum_grp_item->mGroup.mAdminList.ids.find(gxs_id) == old_forum_grp_item->mGroup.mAdminList.ids.end())
|
||||||
|
added_mods.push_back(gxs_id);
|
||||||
|
|
||||||
|
for(auto& gxs_id: old_forum_grp_item->mGroup.mAdminList.ids)
|
||||||
|
if(new_forum_grp_item->mGroup.mAdminList.ids.find(gxs_id) == new_forum_grp_item->mGroup.mAdminList.ids.end())
|
||||||
|
removed_mods.push_back(gxs_id);
|
||||||
|
|
||||||
|
if(!added_mods.empty() || !removed_mods.empty())
|
||||||
|
{
|
||||||
|
auto ev = std::make_shared<RsGxsForumEvent>();
|
||||||
|
|
||||||
|
ev->mForumGroupId = new_forum_grp_item->meta.mGroupId;
|
||||||
|
ev->mModeratorsAdded = added_mods;
|
||||||
|
ev->mModeratorsRemoved = removed_mods;
|
||||||
|
ev->mForumEventCode = RsForumEventCode::MODERATOR_LIST_CHANGED;
|
||||||
|
|
||||||
|
rsEvents->postEvent(ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +53,12 @@ virtual void notifyChanges(std::vector<RsGxsNotify*>& changes)
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
|
virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
|
||||||
{
|
{
|
||||||
return RsGxsIfaceHelper::receiveChanges(changes);
|
return RsGxsIfaceHelper::receiveChanges(changes);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool getBoardsInfo(const std::list<RsGxsGroupId>& boardsIds,
|
bool getBoardsInfo(const std::list<RsGxsGroupId>& boardsIds,
|
||||||
std::vector<RsPostedGroup>& groupsInfo ) override;
|
std::vector<RsPostedGroup>& groupsInfo ) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user