From 424e7be52fa566ea59356efbc0eab427360876ca Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 27 Jan 2020 23:02:04 +0100 Subject: [PATCH] added notifications for identities --- libretroshare/src/retroshare/rsevents.h | 3 ++ libretroshare/src/retroshare/rsidentity.h | 26 +++++++++++ libretroshare/src/services/p3idservice.cc | 45 ++++++++++++------- .../src/gui/Circles/CirclesDialog.cpp | 13 +----- .../src/gui/Circles/CirclesDialog.h | 26 ----------- retroshare-gui/src/gui/Identity/IdDialog.cpp | 28 ++++++++++++ retroshare-gui/src/gui/Identity/IdDialog.h | 3 ++ 7 files changed, 92 insertions(+), 52 deletions(-) diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 7d6d24505..d89846e1a 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -85,6 +85,9 @@ enum class RsEventType : uint32_t /// @see RsGxsPostedEvent GXS_POSTED = 11, + /// @see RsGxsPostedEvent + GXS_IDENTITY = 12, + MAX /// Used to detect invalid event type passed }; diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 67844cde0..2874ccc91 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -304,6 +304,32 @@ private: RsIdentityUsage(); }; +enum class RsGxsIdentityEventCode: uint8_t +{ + UNKNOWN = 0x00, + NEW_IDENTITY = 0x01, + DELETED_IDENTITY = 0x02, +}; + +struct RsGxsIdentityEvent: public RsEvent +{ + RsGxsIdentityEvent() + : RsEvent(RsEventType::GXS_IDENTITY), + mIdentityEventCode(RsGxsIdentityEventCode::UNKNOWN) {} + + RsGxsIdentityEventCode mIdentityEventCode; + RsGxsGroupId mIdentityId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx ) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mIdentityEventCode); + RS_SERIAL_PROCESS(mIdentityId); + } + + ~RsGxsIdentityEvent() override = default; +}; struct RsIdentityDetails : RsSerializable { diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index c75f8ee72..861c5c224 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -603,7 +603,6 @@ void p3IdService::notifyChanges(std::vector &changes) for(uint32_t i = 0;i(changes[i]); RsGxsMsgChange *msgChange = dynamic_cast(changes[i]); if (msgChange && !msgChange->metaChange()) @@ -614,8 +613,8 @@ void p3IdService::notifyChanges(std::vector &changes) #endif std::map > &msgChangeMap = msgChange->msgChangeMap; - std::map >::iterator mit; - for(mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) + + for(auto mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit) { #ifdef DEBUG_IDS std::cerr << "p3IdService::notifyChanges() Msgs for Group: " << mit->first; @@ -624,7 +623,8 @@ void p3IdService::notifyChanges(std::vector &changes) } } - /* shouldn't need to worry about groups - as they need to be subscribed to */ + RsGxsGroupChange *groupChange = dynamic_cast(changes[i]); + if (groupChange && !groupChange->metaChange()) { #ifdef DEBUG_IDS @@ -632,9 +632,8 @@ void p3IdService::notifyChanges(std::vector &changes) std::cerr << std::endl; #endif std::list &groupList = groupChange->mGrpIdList; - std::list::iterator git; - for(git = groupList.begin(); git != groupList.end();) + for(auto git = groupList.begin(); git != groupList.end();++git) { #ifdef DEBUG_IDS std::cerr << "p3IdService::notifyChanges() Auto Subscribe to Incoming Groups: " << *git; @@ -649,16 +648,24 @@ void p3IdService::notifyChanges(std::vector &changes) timeStampKey(RsGxsId(*git),RsIdentityUsage(serviceType(),RsIdentityUsage::IDENTITY_DATA_UPDATE)) ; - ++git; - } - else - git = groupList.erase(git) ; - } + // notify that a new identity is received, if needed - if(groupList.empty()) - { - delete changes[i] ; - changes[i] = NULL ; + switch(groupChange->getType()) + { + case RsGxsNotify::TYPE_PUBLISHED: + case RsGxsNotify::TYPE_RECEIVED_NEW: + { + auto ev = std::make_shared(); + ev->mIdentityId = *git; + ev->mIdentityEventCode = RsGxsIdentityEventCode::NEW_IDENTITY; + rsEvents->postEvent(ev); + } + break; + + default: + break; + } + } } } @@ -1070,6 +1077,14 @@ bool p3IdService::deleteIdentity(RsGxsId& id) return false; } + if(rsEvents) + { + auto ev = std::make_shared(); + ev->mIdentityId = grouId; + ev->mIdentityEventCode = RsGxsIdentityEventCode::DELETED_IDENTITY; + rsEvents->postEvent(ev); + } + return true; } diff --git a/retroshare-gui/src/gui/Circles/CirclesDialog.cpp b/retroshare-gui/src/gui/Circles/CirclesDialog.cpp index 8be03e718..64dff16df 100644 --- a/retroshare-gui/src/gui/Circles/CirclesDialog.cpp +++ b/retroshare-gui/src/gui/Circles/CirclesDialog.cpp @@ -62,9 +62,6 @@ CirclesDialog::CirclesDialog(QWidget *parent) mStateHelper->addWidget(CIRCLESDIALOG_GROUPMETA, ui.pushButton_editCircle); mStateHelper->addWidget(CIRCLESDIALOG_GROUPMETA, ui.treeWidget_membership, UISTATE_ACTIVE_ENABLED); -// mStateHelper->addWidget(CIRCLESDIALOG_GROUPMETA, ui.treeWidget_friends, UISTATE_ACTIVE_ENABLED); -// mStateHelper->addWidget(CIRCLESDIALOG_GROUPMETA, ui.treeWidget_category, UISTATE_ACTIVE_ENABLED); - mStateHelper->setWidgetEnabled(ui.pushButton_editCircle, false); /* Connect signals */ @@ -74,19 +71,13 @@ CirclesDialog::CirclesDialog(QWidget *parent) connect(ui.todoPushButton, SIGNAL(clicked()), this, SLOT(todo())); connect(ui.treeWidget_membership, SIGNAL(itemSelectionChanged()), this, SLOT(circle_selected())); -// connect(ui.treeWidget_friends, SIGNAL(itemSelectionChanged()), this, SLOT(friend_selected())); -// connect(ui.treeWidget_category, SIGNAL(itemSelectionChanged()), this, SLOT(category_selected())); /* Setup TokenQueue */ mCircleQueue = new TokenQueue(rsGxsCircles->getTokenService(), this); /* Set header resize modes and initial section sizes */ - QHeaderView * membership_header = ui.treeWidget_membership->header () ; - membership_header->resizeSection ( CIRCLEGROUP_CIRCLE_COL_GROUPNAME, 200 ); - -// QHeaderView * friends_header = ui.treeWidget_friends->header () ; -// friends_header->resizeSection ( CIRCLEGROUP_FRIEND_COL_NAME, 200 ); - + QHeaderView * membership_header = ui.treeWidget_membership->header () ; + membership_header->resizeSection ( CIRCLEGROUP_CIRCLE_COL_GROUPNAME, 200 ); } CirclesDialog::~CirclesDialog() diff --git a/retroshare-gui/src/gui/Circles/CirclesDialog.h b/retroshare-gui/src/gui/Circles/CirclesDialog.h index 7c96febad..ecaff3f29 100644 --- a/retroshare-gui/src/gui/Circles/CirclesDialog.h +++ b/retroshare-gui/src/gui/Circles/CirclesDialog.h @@ -58,35 +58,9 @@ private slots: void friend_selected(); void category_selected(); -#if 0 - void OpenOrShowAddPageDialog(); - void OpenOrShowAddGroupDialog(); - void OpenOrShowEditDialog(); - void OpenOrShowRepublishDialog(); - - void groupTreeChanged(); - - void newGroup(); - void showGroupDetails(); - void editGroupDetails(); - - void insertWikiGroups(); -#endif - private: void reloadAll(); -#if 0 - voidclearWikiPage(); - void clearGroupTree(); - - void updateWikiPage(const RsWikiSnapshot &page); - - bool getSelectedPage(std::string &groupId, std::string &pageId, std::string &origPageId); - std::string getSelectedPage(); - std::string getSelectedGroup(); -#endif - void requestGroupMeta(); void loadGroupMeta(const uint32_t &token); diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 5d8c45804..a1dc6d06d 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -35,10 +35,12 @@ #include "gui/chat/ChatDialog.h" #include "gui/Circles/CreateCircleDialog.h" #include "gui/common/UIStateHelper.h" +#include "gui/common/UserNotify.h" #include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/RsGxsUpdateBroadcastBase.h" #include "gui/msgs/MessageComposer.h" #include "gui/settings/rsharesettings.h" +#include "util/qtthreadsutils.h" #include "retroshare-gui/RsAutoUpdatePage.h" #include "util/misc.h" #include "util/QtVersion.h" @@ -148,6 +150,9 @@ IdDialog::IdDialog(QWidget *parent) : mIdQueue = NULL; + mEventHandlerId = 0; + rsEvents->registerEventsHandler(RsEventType::GXS_IDENTITY, [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); + // This is used to grab the broadcast of changes from p3GxsCircles, which is discarded by the current dialog, since it expects data for p3Identity only. mCirclesBroadcastBase = new RsGxsUpdateBroadcastBase(rsGxsCircles, this); connect(mCirclesBroadcastBase, SIGNAL(fillDisplay(bool)), this, SLOT(updateCirclesDisplay(bool))); @@ -398,6 +403,29 @@ IdDialog::IdDialog(QWidget *parent) : tmer->start(10000) ; // update every 10 secs. } +void IdDialog::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType != RsEventType::GXS_IDENTITY) + return; + + const RsGxsIdentityEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mIdentityEventCode) + { + case RsGxsIdentityEventCode::DELETED_IDENTITY: + case RsGxsIdentityEventCode::NEW_IDENTITY: + + requestIdList(); + getUserNotify()->updateIcon(); + + default: + break; + } +} + void IdDialog::clearPerson() { QFontMetricsF f(ui->avLabel_Person->font()) ; diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index 30f2d0641..92ba76ee1 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -158,6 +158,9 @@ private: RsGxsGroupId mIdToNavigate; int filter; + void handleEvent_main_thread(std::shared_ptr event); + RsEventsHandlerId_t mEventHandlerId; + /* UI - Designer */ Ui::IdDialog *ui; };