From dc2f2f5eb492ca242e346792f2b89b8ff7d0342e Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 29 Dec 2019 13:49:56 +0100 Subject: [PATCH 01/11] fixed ambiguous variable --- libretroshare/src/turtle/p3turtle.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 328b04772..677b282cd 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1886,11 +1886,15 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item) // because there is not too much file hashes to be active at a time, // and this mostly prevents from sending the hash back in the tunnel. - bool found = false ; +#ifdef P3TURTLE_DEBUG + bool ext_found = false ; +#endif for(std::map::iterator it(_incoming_file_hashes.begin());it!=_incoming_file_hashes.end();++it) if(it->second.last_request == item->request_id) { - found = true ; +#ifdef P3TURTLE_DEBUG + ext_found = true ; +#endif { // add the tunnel uniquely @@ -1917,7 +1921,7 @@ void p3turtle::handleTunnelResult(RsTurtleTunnelOkItem *item) } } #ifdef P3TURTLE_DEBUG - if(!found) + if(!ext_found) std::cerr << "p3turtle: error. Could not find hash that emmitted tunnel request " << reinterpret_cast(item->tunnel_id) << std::endl ; #endif } From c544b1da7c09e01756d888b27091fa516909cb73 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 29 Dec 2019 13:50:54 +0100 Subject: [PATCH 02/11] changed RsEvents so that it takes event types when registering handlers, which limits the number of handlers called for each event --- .../src/gossipdiscovery/p3gossipdiscovery.cc | 6 +-- .../src/retroshare/rsbroadcastdiscovery.h | 25 +++++++---- libretroshare/src/retroshare/rsevents.h | 10 +++-- .../src/retroshare/rsgossipdiscovery.h | 16 +++++-- libretroshare/src/retroshare/rsmsgs.h | 18 ++++---- libretroshare/src/rsitems/rsposteditems.cc | 4 +- libretroshare/src/rsserver/p3msgs.cc | 4 +- .../src/services/broadcastdiscoveryservice.cc | 12 ++++-- libretroshare/src/services/p3msgservice.cc | 14 +++--- libretroshare/src/services/rseventsservice.cc | 43 +++++++++++++++---- libretroshare/src/services/rseventsservice.h | 10 +++-- retroshare-gui/src/gui/NewsFeed.cpp | 24 ++++++++--- retroshare-gui/src/gui/NewsFeed.h | 3 +- .../src/gui/common/NewFriendList.cpp | 11 ++--- .../src/gui/gxschannels/GxsChannelDialog.cpp | 25 +++++------ .../gui/gxschannels/GxsChannelPostsWidget.cpp | 35 +++++++-------- .../gui/gxsforums/GxsForumThreadWidget.cpp | 35 +++++++-------- .../src/gui/gxsforums/GxsForumsDialog.cpp | 25 +++++------ .../src/util/RsGxsUpdateBroadcast.cpp | 6 +-- 19 files changed, 186 insertions(+), 140 deletions(-) diff --git a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc index d7cf5f1a7..a6a24f79c 100644 --- a/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc +++ b/libretroshare/src/gossipdiscovery/p3gossipdiscovery.cc @@ -112,6 +112,7 @@ p3discovery2::p3discovery2( if(rsEvents) rsEvents->registerEventsHandler( + RsEventType::GOSSIP_DISCOVERY, [this](std::shared_ptr event) { rsEventsHandler(*event); @@ -1348,8 +1349,3 @@ void p3discovery2::rsEventsHandler(const RsEvent& event) // // /* ignore other operations */ // } - -// (cyril) do we still need this?? -RsGossipDiscoveryFriendInviteReceivedEvent::RsGossipDiscoveryFriendInviteReceivedEvent(const std::string& invite) : - RsEvent(RsEventType::GOSSIP_DISCOVERY_INVITE_RECEIVED), - mInvite(invite) {} diff --git a/libretroshare/src/retroshare/rsbroadcastdiscovery.h b/libretroshare/src/retroshare/rsbroadcastdiscovery.h index 1bb1e1cc6..92b0e5b0e 100644 --- a/libretroshare/src/retroshare/rsbroadcastdiscovery.h +++ b/libretroshare/src/retroshare/rsbroadcastdiscovery.h @@ -71,23 +71,32 @@ struct RsBroadcastDiscoveryResult : RsSerializable * @brief Event emitted when a non friend new peer is found in the local network * @see RsEvents */ -struct RsBroadcastDiscoveryPeerFoundEvent : RsEvent -{ - RsBroadcastDiscoveryPeerFoundEvent( - const RsBroadcastDiscoveryResult& eventData ) : - RsEvent(RsEventType::BROADCAST_DISCOVERY_PEER_FOUND), mData(eventData) {} +enum class RsBroadcastDiscoveryEventType: uint32_t { + UNKNOWN = 0x00, + PEER_FOUND = 0x01 +}; - RsBroadcastDiscoveryResult mData; +struct RsBroadcastDiscoveryEvent : RsEvent +{ + RsBroadcastDiscoveryEvent() + : RsEvent(RsEventType::BROADCAST_DISCOVERY), + mDiscoveryEventType(RsBroadcastDiscoveryEventType::UNKNOWN) + {} + + virtual ~RsBroadcastDiscoveryEvent() override = default; + + RsBroadcastDiscoveryEventType mDiscoveryEventType; + RsBroadcastDiscoveryResult mData; /// @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx) override { RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mDiscoveryEventType); RS_SERIAL_PROCESS(mData); } - - ~RsBroadcastDiscoveryPeerFoundEvent() override; }; diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index 249a6f50b..f46218313 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -50,10 +50,10 @@ enum class RsEventType : uint32_t NONE = 0, /// Used to detect uninitialized event /// @see RsBroadcastDiscovery - BROADCAST_DISCOVERY_PEER_FOUND = 1, + BROADCAST_DISCOVERY = 1, /// @see RsDiscPendingPgpReceivedEvent - GOSSIP_DISCOVERY_INVITE_RECEIVED = 2, + GOSSIP_DISCOVERY = 2, /// @see AuthSSL AUTHSSL_CONNECTION_AUTENTICATION = 3, @@ -61,14 +61,14 @@ enum class RsEventType : uint32_t /// @see pqissl PEER_CONNECTION = 4, - /// @see RsGxsChanges // this one should probably be removed because it's not used anywhere + /// @see RsGxsChanges // this one is used in RsGxsBroadcast GXS_CHANGES = 5, /// Emitted when a peer state changes, @see RsPeers PEER_STATE_CHANGED = 6, /// @see RsMailStatusEvent - MAIL_STATUS_CHANGE = 7, + MAIL_STATUS = 7, /// @see RsGxsCircleEvent GXS_CIRCLES = 8, @@ -160,6 +160,7 @@ public: * Every time an event is dispatced the registered events handlers will get * their method handleEvent called with the event passed as paramether. * @jsonapi{development,manualwrapper} + * @param eventType Type of event for which the callback is called * @param multiCallback Function that will be called each time an event * is dispatched. * @param[inout] hId Optional storage for handler id, useful to @@ -170,6 +171,7 @@ public: * @return False on error, true otherwise. */ virtual bool registerEventsHandler( + RsEventType eventType, std::function)> multiCallback, RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0) ) = 0; diff --git a/libretroshare/src/retroshare/rsgossipdiscovery.h b/libretroshare/src/retroshare/rsgossipdiscovery.h index c9dc9924a..ca1ab0d7c 100644 --- a/libretroshare/src/retroshare/rsgossipdiscovery.h +++ b/libretroshare/src/retroshare/rsgossipdiscovery.h @@ -45,11 +45,18 @@ extern std::shared_ptr rsGossipDiscovery; /** * @brief Emitted when a pending PGP certificate is received */ -struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent -{ - RsGossipDiscoveryFriendInviteReceivedEvent( - const std::string& invite ); +enum class RsGossipDiscoveryEventType: uint32_t { + UNKNOWN = 0x00, + PEER_INVITE_RECEIVED = 0x01 +}; + +struct RsGossipDiscoveryEvent : RsEvent +{ + RsGossipDiscoveryEvent(): RsEvent(RsEventType::GOSSIP_DISCOVERY) {} + virtual ~RsGossipDiscoveryEvent() override {} + + RsGossipDiscoveryEventType mGossipDiscoveryEventType; std::string mInvite; /// @see RsSerializable @@ -57,6 +64,7 @@ struct RsGossipDiscoveryFriendInviteReceivedEvent : RsEvent RsGenericSerializer::SerializeContext& ctx ) { RsEvent::serial_process(j,ctx); + RS_SERIAL_PROCESS(mGossipDiscoveryEventType); RS_SERIAL_PROCESS(mInvite); } }; diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index cbdd525bc..ea2af0d4a 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -296,19 +296,19 @@ struct MsgTagType : RsSerializable } //namespace Rs } //namespace Msgs -struct RsMailStatusEvent : RsEvent -{ - RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {} - - enum MailStatusEventCode: uint8_t { +enum class RsMailStatusEventType: uint8_t { NEW_MESSAGE = 0x00, MESSAGE_REMOVED = 0x01, MESSAGE_SENT = 0x02, MESSAGE_RECEIVED_ACK = 0x03, // means the peer received the message FAILED_SIGNATURE = 0x04, // means the signature of the message cannot be verified - }; +}; - MailStatusEventCode mMailStatusEventCode; +struct RsMailStatusEvent : RsEvent +{ + RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS) {} + + RsMailStatusEventType mMailStatusEventCode; std::set mChangedMsgIds; /// @see RsEvent @@ -320,7 +320,7 @@ struct RsMailStatusEvent : RsEvent RS_SERIAL_PROCESS(mMailStatusEventCode); } - ~RsMailStatusEvent() override; + ~RsMailStatusEvent() override = default; }; #define RS_CHAT_PUBLIC 0x0001 @@ -329,7 +329,7 @@ struct RsMailStatusEvent : RsEvent #define RS_DISTANT_CHAT_STATUS_UNKNOWN 0x0000 #define RS_DISTANT_CHAT_STATUS_TUNNEL_DN 0x0001 -#define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0002 +#define RS_DISTANT_CHAT_STATUS_CAN_TALK 0x0002 #define RS_DISTANT_CHAT_STATUS_REMOTELY_CLOSED 0x0003 #define RS_DISTANT_CHAT_ERROR_NO_ERROR 0x0000 diff --git a/libretroshare/src/rsitems/rsposteditems.cc b/libretroshare/src/rsitems/rsposteditems.cc index 23fb6633b..3c16ff5bd 100644 --- a/libretroshare/src/rsitems/rsposteditems.cc +++ b/libretroshare/src/rsitems/rsposteditems.cc @@ -33,8 +33,8 @@ void RsGxsPostedPostItem::serial_process(RsGenericSerializer::SerializeJob j,RsG // and do not expect to deserialize mImage member if the data block has been consummed entirely (keeps compatibility // of new RS with older posts. - if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize) - return ; + if(j == RsGenericSerializer::DESERIALIZE && ctx.mOffset == ctx.mSize) + return ; if((j == RsGenericSerializer::SIZE_ESTIMATE || j == RsGenericSerializer::SERIALIZE) && mImage.empty()) return ; diff --git a/libretroshare/src/rsserver/p3msgs.cc b/libretroshare/src/rsserver/p3msgs.cc index ad74dbdde..48a694fb0 100644 --- a/libretroshare/src/rsserver/p3msgs.cc +++ b/libretroshare/src/rsserver/p3msgs.cc @@ -538,8 +538,7 @@ bool p3Msgs::initiateDistantChatConnexion( const RsGxsId& to_gxs_id, const RsGxsId& from_gxs_id, DistantChatPeerId& pid, uint32_t& error_code, bool notify ) { - return mChatSrv->initiateDistantChatConnexion( to_gxs_id, from_gxs_id, - pid, error_code, notify ); + return mChatSrv->initiateDistantChatConnexion( to_gxs_id, from_gxs_id, pid, error_code, notify ); } bool p3Msgs::getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info) { @@ -559,7 +558,6 @@ uint32_t p3Msgs::getDistantChatPermissionFlags() } RsMsgs::~RsMsgs() = default; -RsMailStatusEvent::~RsMailStatusEvent() = default; Rs::Msgs::MessageInfo::~MessageInfo() = default; MsgInfoSummary::~MsgInfoSummary() = default; VisibleChatLobbyRecord::~VisibleChatLobbyRecord() = default; diff --git a/libretroshare/src/services/broadcastdiscoveryservice.cc b/libretroshare/src/services/broadcastdiscoveryservice.cc index d49e04a17..9b39e302e 100644 --- a/libretroshare/src/services/broadcastdiscoveryservice.cc +++ b/libretroshare/src/services/broadcastdiscoveryservice.cc @@ -182,10 +182,15 @@ void BroadcastDiscoveryService::data_tick() } else if(!isFriend) { - typedef RsBroadcastDiscoveryPeerFoundEvent Evt_t; if(rsEvents) - rsEvents->postEvent( - std::shared_ptr(new Evt_t(rbdr)) ); + { + auto ev = std::make_shared(); + + ev->mDiscoveryEventType = RsBroadcastDiscoveryEventType::PEER_FOUND; + ev->mData = rbdr; + + rsEvents->postEvent(ev); + } } } } @@ -307,5 +312,4 @@ bool BroadcastDiscoveryService::assertMulticastLockIsvalid() RsBroadcastDiscovery::~RsBroadcastDiscovery() = default; RsBroadcastDiscoveryResult::~RsBroadcastDiscoveryResult() = default; -RsBroadcastDiscoveryPeerFoundEvent::~RsBroadcastDiscoveryPeerFoundEvent() = default; BroadcastDiscoveryPack::~BroadcastDiscoveryPack() = default; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index dc67a0f60..49640330b 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -178,7 +178,7 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi) if (rsEvents) { auto ev = std::make_shared(); - ev->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; + ev->mMailStatusEventCode = RsMailStatusEventType::NEW_MESSAGE; ev->mChangedMsgIds.insert(std::to_string(mi->msgId)); rsEvents->sendEvent(ev); @@ -338,7 +338,7 @@ int p3MsgService::checkOutgoingMessages() std::list output_queue; auto pEvent = std::make_shared(); - pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; + pEvent->mMailStatusEventCode = RsMailStatusEventType::MESSAGE_SENT; { RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -900,7 +900,7 @@ bool p3MsgService::removeMsgId(const std::string &mid) auto pEvent = std::make_shared(); - pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_REMOVED; + pEvent->mMailStatusEventCode = RsMailStatusEventType::MESSAGE_REMOVED; { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ @@ -1269,7 +1269,7 @@ uint32_t p3MsgService::sendMail( uint32_t ret = 0; auto pEvent = std::make_shared(); - pEvent->mMailStatusEventCode = RsMailStatusEvent::MESSAGE_SENT; + pEvent->mMailStatusEventCode = RsMailStatusEventType::MESSAGE_SENT; auto pSend = [&](const std::set& sDest) { @@ -2085,7 +2085,7 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id, auto pEvent = std::make_shared(); - pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; + pEvent->mMailStatusEventCode = RsMailStatusEventType::NEW_MESSAGE; pEvent->mChangedMsgIds.insert(std::to_string(msg_id)); if(rsEvents) rsEvents->postEvent(pEvent); @@ -2189,7 +2189,7 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, if( status == GxsTransSendStatus::RECEIPT_RECEIVED ) { - pEvent->mMailStatusEventCode = RsMailStatusEvent::NEW_MESSAGE; + pEvent->mMailStatusEventCode = RsMailStatusEventType::NEW_MESSAGE; uint32_t msg_id; { @@ -2244,7 +2244,7 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE ) { uint32_t msg_id; - pEvent->mMailStatusEventCode = RsMailStatusEvent::FAILED_SIGNATURE; + pEvent->mMailStatusEventCode = RsMailStatusEventType::FAILED_SIGNATURE; { RS_STACK_MUTEX(gxsOngoingMutex); diff --git a/libretroshare/src/services/rseventsservice.cc b/libretroshare/src/services/rseventsservice.cc index 2dfc12d48..8d1a28fa3 100644 --- a/libretroshare/src/services/rseventsservice.cc +++ b/libretroshare/src/services/rseventsservice.cc @@ -99,22 +99,42 @@ RsEventsHandlerId_t RsEventsService::generateUniqueHandlerId_unlocked() } bool RsEventsService::registerEventsHandler( + RsEventType eventType, std::function)> multiCallback, RsEventsHandlerId_t& hId ) { RS_STACK_MUTEX(mHandlerMapMtx); - if(!hId) hId = generateUniqueHandlerId_unlocked(); - mHandlerMap[hId] = multiCallback; + + if( (int)eventType > mHandlerMaps.size() + 10) + { + RsErr() << "Cannot register an event handler for an event type larger than 10 plus the max pre-defined event (value passed was " << (int)eventType << " whereas max is " << (int)RsEventType::MAX << ")" << std::endl; + return false; + } + + if( (int)eventType >= mHandlerMaps.size()) + mHandlerMaps.resize( (int)eventType +1 ); + + if(!hId) + hId = generateUniqueHandlerId_unlocked(); + + mHandlerMaps[(int)eventType][hId] = multiCallback; return true; } bool RsEventsService::unregisterEventsHandler(RsEventsHandlerId_t hId) { RS_STACK_MUTEX(mHandlerMapMtx); - auto it = mHandlerMap.find(hId); - if(it == mHandlerMap.end()) return false; - mHandlerMap.erase(it); - return true; + + for(uint32_t i=0;i event) { std::function)> mCallback; + uint32_t event_type_index = (uint32_t)event->mType; + mHandlerMapMtx.lock(); - auto cbpt = mHandlerMap.begin(); + if(event_type_index >= mHandlerMaps.size() || event_type_index < 1) + { + RsErr() << "Cannot handle an event of type " << event_type_index << ": out of scope!" << std::endl; + return; + } + auto cbpt = mHandlerMaps[event_type_index].begin(); mHandlerMapMtx.unlock(); getHandlerFromMapLock: mHandlerMapMtx.lock(); - if(cbpt != mHandlerMap.end()) + if(cbpt != mHandlerMaps[event_type_index].end()) { mCallback = cbpt->second; ++cbpt; diff --git a/libretroshare/src/services/rseventsservice.h b/libretroshare/src/services/rseventsservice.h index 05fff772e..182a73f6b 100644 --- a/libretroshare/src/services/rseventsservice.h +++ b/libretroshare/src/services/rseventsservice.h @@ -35,6 +35,7 @@ class RsEventsService : public: RsEventsService(): mHandlerMapMtx("RsEventsService::mHandlerMapMtx"), mLastHandlerId(1), + mHandlerMaps(static_cast(RsEventType::MAX)), mEventQueueMtx("RsEventsService::mEventQueueMtx") {} /// @see RsEvents @@ -54,6 +55,7 @@ public: /// @see RsEvents bool registerEventsHandler( + RsEventType eventType, std::function)> multiCallback, RsEventsHandlerId_t& hId = RS_DEFAULT_STORAGE_PARAM(RsEventsHandlerId_t, 0) ) override; @@ -64,9 +66,11 @@ public: protected: RsMutex mHandlerMapMtx; RsEventsHandlerId_t mLastHandlerId; - std::map< - RsEventsHandlerId_t, - std::function)> > mHandlerMap; + + std::vector< + std::map< + RsEventsHandlerId_t, + std::function)> > > mHandlerMaps; RsMutex mEventQueueMtx; std::deque< std::shared_ptr > mEventQueue; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index ac44de06b..7f3504055 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -72,8 +72,21 @@ static NewsFeed *instance = NULL; /** Constructor */ NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed) { - mEventHandlerId =0; // needed to force intialization by registerEventsHandler() - rsEvents->registerEventsHandler( [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerId ); + mEventTypes = { + RsEventType::AUTHSSL_CONNECTION_AUTENTICATION, + RsEventType::PEER_CONNECTION , + RsEventType::GXS_CIRCLES , + RsEventType::GXS_CHANNELS , + RsEventType::GXS_FORUMS , + RsEventType::GXS_POSTED , + RsEventType::MAIL_STATUS + }; + + for(uint32_t i=0;iregisterEventsHandler(mEventTypes[i], [this](std::shared_ptr event) { handleEvent(event); }, mEventHandlerIds.back() ); + } /* Invoke the Qt Designer generated object setup routine */ ui->setupUi(this); @@ -117,7 +130,8 @@ QString hlp_str = tr( NewsFeed::~NewsFeed() { - rsEvents->unregisterEventsHandler(mEventHandlerId); + for(uint32_t i=0;iunregisterEventsHandler(mEventHandlerIds[i]); // save settings processSettings(false); @@ -190,7 +204,7 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) handleMailEvent(event); - if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MSG)) + if(event->mType == RsEventType::MAIL_STATUS && (flags & RS_FEED_TYPE_MSG)) handlePostedEvent(event); } @@ -202,7 +216,7 @@ void NewsFeed::handleMailEvent(std::shared_ptr event) switch(pe->mMailStatusEventCode) { - case RsMailStatusEvent::NEW_MESSAGE: + case RsMailStatusEventType::NEW_MESSAGE: for(auto msgid: pe->mChangedMsgIds) addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false)); break; diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index c255d56ac..79208e344 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -118,7 +118,8 @@ private: /* UI - from Designer */ Ui::NewsFeed *ui; - RsEventsHandlerId_t mEventHandlerId; + std::vector mEventHandlerIds; + std::vector mEventTypes; }; #endif diff --git a/retroshare-gui/src/gui/common/NewFriendList.cpp b/retroshare-gui/src/gui/common/NewFriendList.cpp index 7b07f9086..cb4c68030 100644 --- a/retroshare-gui/src/gui/common/NewFriendList.cpp +++ b/retroshare-gui/src/gui/common/NewFriendList.cpp @@ -178,7 +178,7 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) ui->filterLineEdit->showFilterIcon(); mEventHandlerId=0; // forces initialization - rsEvents->registerEventsHandler( [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId ); + rsEvents->registerEventsHandler( RsEventType::PEER_CONNECTION, [this](std::shared_ptr e) { handleEvent(e); }, mEventHandlerId ); mModel = new RsFriendListModel(); mProxyModel = new FriendListSortFilterProxyModel(ui->peerTreeWidget->header(),this); @@ -258,13 +258,10 @@ NewFriendList::NewFriendList(QWidget *parent) : /* RsAutoUpdatePage(5000,parent) void NewFriendList::handleEvent(std::shared_ptr e) { - if(e->mType == RsEventType::PEER_CONNECTION) - { - // /!\ The function we're in is called from a different thread. It's very important - // to use this trick in order to avoid data races. + // /!\ The function we're in is called from a different thread. It's very important + // to use this trick in order to avoid data races. - RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ; - } + RsQThreadUtils::postToObject( [=]() { forceUpdateDisplay() ; }, this ) ; } NewFriendList::~NewFriendList() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 137f37f26..d0b5044c6 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -52,26 +52,23 @@ GxsChannelDialog::GxsChannelDialog(QWidget *parent) { mEventHandlerId = 0; // Needs to be asynced because this function is likely to be called by another thread! - rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); + rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); } void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr event) { - if(event->mType == RsEventType::GXS_CHANNELS) - { - const RsGxsChannelEvent *e = dynamic_cast(event.get()); + const RsGxsChannelEvent *e = dynamic_cast(event.get()); - if(!e) - return; + if(!e) + return; - switch(e->mChannelEventCode) - { - case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); - break; - default: - break; - } - } + switch(e->mChannelEventCode) + { + case RsGxsChannelEvent::ChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + break; + default: + break; + } } GxsChannelDialog::~GxsChannelDialog() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 02abc3ba5..dfa322934 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -132,31 +132,28 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid mEventHandlerId = 0; // Needs to be asynced because this function is likely to be called by another thread! - rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); + rsEvents->registerEventsHandler(RsEventType::GXS_CHANNELS, [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); } void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr event) { - if(event->mType == RsEventType::GXS_CHANNELS) - { - const RsGxsChannelEvent *e = dynamic_cast(event.get()); + const RsGxsChannelEvent *e = dynamic_cast(event.get()); - if(!e) - return; + if(!e) + return; - switch(e->mChannelEventCode) - { - case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: - case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: - case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: - case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: - if(e->mChannelGroupId == mChannelGroupId) - updateDisplay(true); - break; - default: - break; - } - } + switch(e->mChannelEventCode) + { + case RsGxsChannelEvent::ChannelEventCode::UPDATED_CHANNEL: + case RsGxsChannelEvent::ChannelEventCode::NEW_CHANNEL: + case RsGxsChannelEvent::ChannelEventCode::UPDATED_MESSAGE: + case RsGxsChannelEvent::ChannelEventCode::NEW_MESSAGE: + if(e->mChannelGroupId == mChannelGroupId) + updateDisplay(true); + break; + default: + break; + } } GxsChannelPostsWidget::~GxsChannelPostsWidget() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 5b02a977e..e46c67273 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -436,31 +436,28 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget mEventHandlerId = 0; // Needs to be asynced because this function is likely to be called by another thread! - rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); + rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); } void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr event) { - if(event->mType == RsEventType::GXS_FORUMS) - { - const RsGxsForumEvent *e = dynamic_cast(event.get()); + const RsGxsForumEvent *e = dynamic_cast(event.get()); - if(!e) - return; + if(!e) + return; - switch(e->mForumEventCode) - { - case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: - case RsGxsForumEvent::ForumEventCode::NEW_FORUM: - case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: - case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: - if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) - updateDisplay(true); - break; - default: - break; - } - } + switch(e->mForumEventCode) + { + case RsGxsForumEvent::ForumEventCode::UPDATED_FORUM: + case RsGxsForumEvent::ForumEventCode::NEW_FORUM: + case RsGxsForumEvent::ForumEventCode::UPDATED_MESSAGE: + case RsGxsForumEvent::ForumEventCode::NEW_MESSAGE: + if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) + updateDisplay(true); + break; + default: + break; + } } void GxsForumThreadWidget::blank() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp index 0e0a8447a..80f83bd5e 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp @@ -45,26 +45,23 @@ GxsForumsDialog::GxsForumsDialog(QWidget *parent) mEventHandlerId = 0; // Needs to be asynced because this function is likely to be called by another thread! - rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); + rsEvents->registerEventsHandler(RsEventType::GXS_FORUMS, [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); } void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr event) { - if(event->mType == RsEventType::GXS_FORUMS) - { - const RsGxsForumEvent *e = dynamic_cast(event.get()); + const RsGxsForumEvent *e = dynamic_cast(event.get()); - if(!e) - return; + if(!e) + return; - switch(e->mForumEventCode) - { - case RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); - break; - default: - break; - } - } + switch(e->mForumEventCode) + { + case RsGxsForumEvent::ForumEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true); + break; + default: + break; + } } GxsForumsDialog::~GxsForumsDialog() diff --git a/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp b/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp index bd2d647f5..934226da4 100644 --- a/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp +++ b/retroshare-gui/src/util/RsGxsUpdateBroadcast.cpp @@ -39,11 +39,9 @@ RsGxsUpdateBroadcast::RsGxsUpdateBroadcast(RsGxsIfaceHelper *ifaceImpl) : { mEventHandlerId = 0; // forces initialization in registerEventsHandler() - rsEvents->registerEventsHandler( [this](std::shared_ptr event) + rsEvents->registerEventsHandler(RsEventType::GXS_CHANGES, [this](std::shared_ptr event) { - if(event->mType == RsEventType::GXS_CHANGES) - onChangesReceived(*dynamic_cast(event.get())); - + onChangesReceived(*dynamic_cast(event.get())); }, mEventHandlerId ); } From f12ec2b5351289c75af0ea12cbbeadf995cbf6f0 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 8 Jan 2020 14:24:46 +0100 Subject: [PATCH 03/11] JSON API service and RsThread fixups --- libretroshare/src/jsonapi/jsonapi.cpp | 62 +++++++++++++----------- libretroshare/src/jsonapi/jsonapi.h | 11 ++++- libretroshare/src/retroshare/rsjsonapi.h | 20 +++++--- libretroshare/src/util/rsstring.cc | 9 ++-- libretroshare/src/util/rsthreads.cc | 27 +++++++---- libretroshare/src/util/rsthreads.h | 12 ++++- 6 files changed, 88 insertions(+), 53 deletions(-) diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp index 08bb9ea49..a9aac873c 100644 --- a/libretroshare/src/jsonapi/jsonapi.cpp +++ b/libretroshare/src/jsonapi/jsonapi.cpp @@ -146,6 +146,7 @@ bool RsJsonApi::parseToken( JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), mService(std::make_shared()), + mServiceMutex("JsonApiServer restbed ptr"), mListeningPort(RsJsonApi::DEFAULT_PORT), mBindingAddress(RsJsonApi::DEFAULT_BINDING_ADDRESS) { @@ -223,7 +224,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), rsLoginHelper->attemptLogin(account, password); if( retval == RsInit::OK ) - authorizeUser(account.toStdString(),password); + authorizeUser(account.toStdString(), password); // serialize out parameters and return value to JSON { @@ -310,6 +311,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), registerHandler("/rsEvents/registerEventsHandler", [this](const std::shared_ptr session) { + const std::weak_ptr weakService(mService); const std::multimap headers { { "Connection", "keep-alive" }, @@ -319,7 +321,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), size_t reqSize = static_cast( session->get_request()->get_header("Content-Length", 0) ); - session->fetch( reqSize, [this]( + session->fetch( reqSize, [weakService]( const std::shared_ptr session, const rb::Bytes& body ) { @@ -332,9 +334,17 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), const std::weak_ptr weakSession(session); RsEventsHandlerId_t hId = rsEvents->generateUniqueHandlerId(); std::function)> multiCallback = - [this, weakSession, hId](std::shared_ptr event) + [weakSession, weakService, hId]( + std::shared_ptr event ) { - mService->schedule( [weakSession, hId, event]() + auto lService = weakService.lock(); + if(!lService || lService->is_down()) + { + if(rsEvents) rsEvents->unregisterEventsHandler(hId); + return; + } + + lService->schedule( [weakSession, hId, event]() { auto session = weakSession.lock(); if(!session || session->is_closed()) @@ -500,10 +510,10 @@ bool JsonApiServer::authorizeUser( return false; } - if(!librs::util::is_alphanumeric(passwd)) + if(passwd.empty()) { - RsErr() << __PRETTY_FUNCTION__ << " Password is not alphanumeric" - << std::endl; + RsWarn() << __PRETTY_FUNCTION__ << " Password is empty, are you sure " + << "this what you wanted?" << std::endl; return false; } @@ -581,21 +591,21 @@ std::vector > JsonApiServer::getResources() const return tab; } -bool JsonApiServer::restart() +void JsonApiServer::restart() { - fullstop(); - RsThread::start("JSON API Server"); - - return true; + /* It is important to wrap into async(...) because fullstop() method can't + * be called from same thread of execution hence from JSON API thread! */ + RsThread::async([this]() + { + fullstop(); + RsThread::start("JSON API Server"); + }); } void JsonApiServer::onStopRequested() -{ if(mService->is_up()) mService->stop(); } - -bool JsonApiServer::fullstop() { - RsThread::fullstop(); - return true; + RS_STACK_MUTEX(mServiceMutex); + if(mService->is_up()) mService->stop(); } uint16_t JsonApiServer::listeningPort() const { return mListeningPort; } @@ -611,16 +621,12 @@ void JsonApiServer::run() settings->set_bind_address(mBindingAddress); settings->set_default_header("Connection", "close"); - if(mService->is_up()) - { - RsWarn() << __PRETTY_FUNCTION__ << " restbed is already running. " - << " stopping it before starting again!" << std::endl; - mService->stop(); - } - /* re-allocating mService is important because it deletes the existing * service and therefore leaves the listening port open */ - mService = std::make_shared(); + { + RS_STACK_MUTEX(mServiceMutex); + mService = std::make_shared(); + } for(auto& r: getResources()) mService->publish(r); @@ -628,8 +634,8 @@ void JsonApiServer::run() { RsUrl apiUrl; apiUrl.setScheme("http").setHost(mBindingAddress) .setPort(mListeningPort); - RsDbg() << __PRETTY_FUNCTION__ << " JSON API server listening on " - << apiUrl.toString() << std::endl; + RsInfo() << __PRETTY_FUNCTION__ << " JSON API server listening on " + << apiUrl.toString() << std::endl; mService->start(settings); } catch(std::exception& e) @@ -640,7 +646,7 @@ void JsonApiServer::run() return; } - RsInfo() << __PRETTY_FUNCTION__ << " finished!" << std::endl; + RsDbg() << __PRETTY_FUNCTION__ << " finished!" << std::endl; } /*static*/ void RsJsonApi::version( diff --git a/libretroshare/src/jsonapi/jsonapi.h b/libretroshare/src/jsonapi/jsonapi.h index 5067397a8..803be8459 100644 --- a/libretroshare/src/jsonapi/jsonapi.h +++ b/libretroshare/src/jsonapi/jsonapi.h @@ -63,10 +63,13 @@ public: std::vector> getResources() const; /// @see RsJsonApi - bool restart() override; + void fullstop() override { RsThread::fullstop(); } /// @see RsJsonApi - bool fullstop() override; + void restart() override; + + /// @see RsJsonApi + void askForStop() override { RsThread::askForStop(); } /// @see RsJsonApi inline bool isRunning() override { return RsThread::isRunning(); } @@ -193,6 +196,10 @@ private: std::less > mResourceProviders; std::shared_ptr mService; + /** Protect service only during very critical operation like resetting the + * pointer, still not 100% thread safe, but hopefully we can avoid + * crashes/freeze with this */ + RsMutex mServiceMutex; uint16_t mListeningPort; std::string mBindingAddress; diff --git a/libretroshare/src/retroshare/rsjsonapi.h b/libretroshare/src/retroshare/rsjsonapi.h index 2fbad4a44..251310aaa 100644 --- a/libretroshare/src/retroshare/rsjsonapi.h +++ b/libretroshare/src/retroshare/rsjsonapi.h @@ -43,18 +43,25 @@ public: static const std::string DEFAULT_BINDING_ADDRESS; // 127.0.0.1 /** - * @brief Restart RsJsonApi server + * @brief Restart RsJsonApi server asynchronously. * @jsonapi{development} */ - virtual bool restart() = 0; + virtual void restart() = 0; + + /** @brief Request RsJsonApi to stop and wait until it has stopped. + * Do not expose this method to JSON API as fullstop must not be called from + * the same thread of service execution. + */ + virtual void fullstop() = 0; /** - * @brief Request RsJsonApi to stop and wait until ti has stopped. + * @brief Request RsJsonApi to stop asynchronously. + * @jsonapi{development} * Be expecially carefull to call this from JSON API because you will loose * access to the API. - * @jsonapi{development} + * If you need to wait until stopping has completed @see isRunning(). */ - virtual bool fullstop() = 0; + virtual void askForStop() = 0; /** * @brief Get status of the json api server @@ -128,8 +135,7 @@ public: std::string& user, std::string& passwd ); /** - * Add new auth (user,passwd) token to the authorized set, creating the - * token user:passwd internally. + * Add new API auth (user,passwd) token to the authorized set. * @jsonapi{development} * @param[in] user user name to autorize, must be alphanumerinc * @param[in] password password for the user, must be alphanumerinc diff --git a/libretroshare/src/util/rsstring.cc b/libretroshare/src/util/rsstring.cc index c938ea82f..7b540156a 100644 --- a/libretroshare/src/util/rsstring.cc +++ b/libretroshare/src/util/rsstring.cc @@ -207,15 +207,14 @@ bool ConvertUtf16ToUtf8(const std::wstring& source, std::string& dest) bool is_alphanumeric(char c) { - return (c>='0' && c<'9') || (c>='a' && c<='z') || (c>='A' && c<='Z') ; + return (c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z'); } bool is_alphanumeric(const std::string& s) { - for(uint32_t i=0;i(this) << std::hex << ", callerTid: " << callerTid - << ", mTid: " << mTid << std::dec << std::endl; + << ", mTid: " << mTid << std::dec + << ", mFullName: " << mFullName << std::endl; print_stacktrace(); return; } @@ -134,9 +138,9 @@ void RsThread::fullstop() std::this_thread::sleep_for(std::chrono::milliseconds(200)); ++i; if(!(i%5)) - RsInfo() << __PRETTY_FUNCTION__ << " " << i*0.2 << " seconds passed" - << " waiting for thread: " << mTid << " " << mFullName - << " to stop" << std::endl; + RsDbg() << __PRETTY_FUNCTION__ << " " << i*0.2 << " seconds passed" + << " waiting for thread: " << std::hex << mLastTid + << std::dec << " " << mFullName << " to stop" << std::endl; } } @@ -158,6 +162,9 @@ bool RsThread::start(const std::string& threadName) return false; } + /* Store an extra copy of thread id for debugging */ + mLastTid = mTid; + /* Store thread full name as PThread is not able to keep it entirely */ mFullName = threadName; @@ -266,10 +273,10 @@ double RsStackMutex::getCurrentTS() RsThread::~RsThread() { - if(isRunning()) + if(!mHasStopped) { - RsErr() << __PRETTY_FUNCTION__ << " deleting thread: " << mTid << " " - << mFullName << " that is still " + RsErr() << __PRETTY_FUNCTION__ << " deleting thread: " << mLastTid + << " " << mFullName << " that is still " << "running! Something seems very wrong here and RetroShare is " << "likely to crash because of this." << std::endl; print_stacktrace(); diff --git a/libretroshare/src/util/rsthreads.h b/libretroshare/src/util/rsthreads.h index 55af56847..5692bb256 100644 --- a/libretroshare/src/util/rsthreads.h +++ b/libretroshare/src/util/rsthreads.h @@ -264,9 +264,19 @@ private: /// Store the id of the corresponding pthread pthread_t mTid; + void resetTid(); - /// Store thread full name + /** Store thread full name for debugging because PThread is limited to 15 + * char thread names */ std::string mFullName; + + /** Store a copy of thread id which is never reset to 0 after initialization + * due to RsThread functioning. After RsThread initialization this member is + * only re-written with a new tread id in start(...). + * This is useful for debugging because mTid is reset at the end of wrapRun + * and that might happens concurrently (or just before) a debug message + * being printed, thus causing the debug message to print a mangled value.*/ + pthread_t mLastTid; }; /** From 33c2f56a8e18245e2071fb405d456986dc0bd10f Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Wed, 8 Jan 2020 23:16:05 +0100 Subject: [PATCH 04/11] Fixup jsonapi server stopping --- libretroshare/src/jsonapi/jsonapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp index a9aac873c..b9ddb867c 100644 --- a/libretroshare/src/jsonapi/jsonapi.cpp +++ b/libretroshare/src/jsonapi/jsonapi.cpp @@ -605,7 +605,7 @@ void JsonApiServer::restart() void JsonApiServer::onStopRequested() { RS_STACK_MUTEX(mServiceMutex); - if(mService->is_up()) mService->stop(); + mService->stop(); } uint16_t JsonApiServer::listeningPort() const { return mListeningPort; } From f76b81ba490994040b8309b8a7a85c94fc3cc299 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 11 Jan 2020 16:10:28 +0100 Subject: [PATCH 05/11] fixed compilation in jsonapi to cope with new event type field in registerEventHandler() --- libretroshare/src/jsonapi/jsonapi.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp index b9ddb867c..2d1593fcf 100644 --- a/libretroshare/src/jsonapi/jsonapi.cpp +++ b/libretroshare/src/jsonapi/jsonapi.cpp @@ -331,6 +331,15 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), rsEvents, "rsEvents", cAns, session ) ) return; + uint32_t event_type; + + // deserialize input parameters from JSON + { + RsGenericSerializer::SerializeContext& ctx(cReq); + RsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON); + RS_SERIAL_PROCESS(event_type); + } + const std::weak_ptr weakSession(session); RsEventsHandlerId_t hId = rsEvents->generateUniqueHandlerId(); std::function)> multiCallback = @@ -365,7 +374,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), } ); }; - bool retval = rsEvents->registerEventsHandler(multiCallback, hId); + bool retval = rsEvents->registerEventsHandler(static_cast(event_type),multiCallback, hId); { RsGenericSerializer::SerializeContext& ctx(cAns); From 45e579c98f06e1fc8ee32465e965f4fc88277164 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 11 Jan 2020 17:00:01 +0100 Subject: [PATCH 06/11] fixed bug where notification was missing on creation of new post in forums, channels and posted --- libretroshare/src/services/p3gxschannels.cc | 2 +- libretroshare/src/services/p3gxscircles.cc | 2 +- libretroshare/src/services/p3gxsforums.cc | 2 +- libretroshare/src/services/p3postbase.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 8ee484d08..800c148f4 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -247,7 +247,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) RsGxsMsgChange *msgChange = dynamic_cast(*it); if (msgChange) { - if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) + if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW|| msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED) { /* message received */ if (rsEvents) diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index a2fac2db8..b5b7ae9ad 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -501,7 +501,7 @@ void p3GxsCircles::notifyChanges(std::vector &changes) RsGxsCircleDetails details; getCircleDetails(circle_id,details); - if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) ) + if(rsEvents && (c->getType() == RsGxsNotify::TYPE_RECEIVED_NEW|| c->getType() == RsGxsNotify::TYPE_PUBLISHED) ) for (auto msgIdIt(mit->second.begin()), end(mit->second.end()); msgIdIt != end; ++msgIdIt) { RsGxsCircleMsg msg; diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 128b5db39..6ef0dae34 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -191,7 +191,7 @@ void p3GxsForums::notifyChanges(std::vector &changes) RsGxsMsgChange *msgChange = dynamic_cast(*it); if (msgChange) { - if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) /* message received */ + if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED) /* message received */ if (rsEvents) { std::map >& msgChangeMap = msgChange->msgChangeMap; diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index 51308194c..a31115775 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -112,7 +112,7 @@ void p3PostBase::notifyChanges(std::vector &changes) // It could be taken a step further and directly request these msgs for an update. addGroupForProcessing(mit->first); - if (rsEvents && msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW) + if (rsEvents && (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW)) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { auto ev = std::make_shared(); From 6a4c98b2eda407138fd47ebc8643723c9bf1ea52 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 11 Jan 2020 19:01:43 +0100 Subject: [PATCH 07/11] allowed some clients to Event handler to register with type NONE, which means that all event types will be sent to the client --- libretroshare/src/jsonapi/jsonapi.cpp | 6 +-- libretroshare/src/services/rseventsservice.cc | 39 ++++++++----------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp index 2d1593fcf..70443bf5f 100644 --- a/libretroshare/src/jsonapi/jsonapi.cpp +++ b/libretroshare/src/jsonapi/jsonapi.cpp @@ -331,13 +331,13 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), rsEvents, "rsEvents", cAns, session ) ) return; - uint32_t event_type; + RsEventType eventType = RsEventType::NONE; // deserialize input parameters from JSON { RsGenericSerializer::SerializeContext& ctx(cReq); RsGenericSerializer::SerializeJob j(RsGenericSerializer::FROM_JSON); - RS_SERIAL_PROCESS(event_type); + RS_SERIAL_PROCESS(eventType); } const std::weak_ptr weakSession(session); @@ -374,7 +374,7 @@ JsonApiServer::JsonApiServer(): configMutex("JsonApiServer config"), } ); }; - bool retval = rsEvents->registerEventsHandler(static_cast(event_type),multiCallback, hId); + bool retval = rsEvents->registerEventsHandler(eventType,multiCallback, hId); { RsGenericSerializer::SerializeContext& ctx(cAns); diff --git a/libretroshare/src/services/rseventsservice.cc b/libretroshare/src/services/rseventsservice.cc index d8966f0bd..c1aa0958c 100644 --- a/libretroshare/src/services/rseventsservice.cc +++ b/libretroshare/src/services/rseventsservice.cc @@ -176,30 +176,25 @@ void RsEventsService::handleEvent(std::shared_ptr event) { std::function)> mCallback; - uint32_t event_type_index = (uint32_t)event->mType; + uint32_t event_type_index = static_cast(event->mType); - mHandlerMapMtx.lock(); - if(event_type_index >= mHandlerMaps.size() || event_type_index < 1) - { - RsErr() << "Cannot handle an event of type " << event_type_index << ": out of scope!" << std::endl; - return; - } - auto cbpt = mHandlerMaps[event_type_index].begin(); - mHandlerMapMtx.unlock(); - -getHandlerFromMapLock: - mHandlerMapMtx.lock(); - if(cbpt != mHandlerMaps[event_type_index].end()) { - mCallback = cbpt->second; - ++cbpt; - } - mHandlerMapMtx.unlock(); + RS_STACK_MUTEX(mHandlerMapMtx); /* LOCKED AREA */ - if(mCallback) - { - mCallback(event); // It is relevant that this happens outside mutex - mCallback = std::function)>(nullptr); - goto getHandlerFromMapLock; + if(event_type_index >= mHandlerMaps.size() || event_type_index < 1) + { + RsErr() << "Cannot handle an event of type " << event_type_index << ": out of scope!" << std::endl; + return; + } + + // Call all clients that registered a callback for this event type + + for(auto cbit: mHandlerMaps[event_type_index]) + cbit.second(event); + + // Also call all clients that registered with NONE, meaning that they expect all events + + for(auto cbit: mHandlerMaps[static_cast(RsEventType::NONE)]) + cbit.second(event); } } From f0921886db33100809fe55dce1a721ce98952572 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 11 Jan 2020 19:08:11 +0100 Subject: [PATCH 08/11] fixed glitch in previous commit --- libretroshare/src/services/p3postbase.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index a31115775..12799c4f7 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -112,7 +112,7 @@ void p3PostBase::notifyChanges(std::vector &changes) // It could be taken a step further and directly request these msgs for an update. addGroupForProcessing(mit->first); - if (rsEvents && (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW)) + if (rsEvents && (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED)) for (auto mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1) { auto ev = std::make_shared(); From c55289045943ea7253252b8e733fa10386d60de1 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 14 Jan 2020 21:43:29 +0100 Subject: [PATCH 09/11] attempt to sort out the mess in item deletion in FeedHolder widgets --- plugins/FeedReader/gui/FeedReaderFeedItem.h | 5 +-- retroshare-gui/src/gui/NewsFeed.cpp | 11 ++--- retroshare-gui/src/gui/NewsFeed.h | 2 +- retroshare-gui/src/gui/Posted/PostedItem.h | 2 +- .../src/gui/Posted/PostedListWidget.cpp | 2 +- .../src/gui/Posted/PostedListWidget.h | 2 +- .../src/gui/common/RSFeedWidget.cpp | 17 +++---- retroshare-gui/src/gui/common/RSFeedWidget.h | 3 +- retroshare-gui/src/gui/feeds/ChatMsgItem.cpp | 32 +++----------- retroshare-gui/src/gui/feeds/ChatMsgItem.h | 4 -- retroshare-gui/src/gui/feeds/FeedHolder.h | 3 +- retroshare-gui/src/gui/feeds/FeedItem.cpp | 44 ++++++++++++++----- retroshare-gui/src/gui/feeds/FeedItem.h | 17 ++++++- .../src/gui/feeds/GxsChannelGroupItem.h | 2 +- .../src/gui/feeds/GxsChannelPostItem.h | 3 +- .../src/gui/feeds/GxsCircleItem.cpp | 18 +------- retroshare-gui/src/gui/feeds/GxsCircleItem.h | 5 --- .../src/gui/feeds/GxsForumGroupItem.cpp | 1 - .../src/gui/feeds/GxsForumGroupItem.h | 4 +- .../src/gui/feeds/GxsForumMsgItem.h | 2 +- retroshare-gui/src/gui/feeds/MsgItem.cpp | 39 +++++----------- retroshare-gui/src/gui/feeds/MsgItem.h | 4 -- retroshare-gui/src/gui/feeds/PeerItem.cpp | 41 +++++------------ retroshare-gui/src/gui/feeds/PeerItem.h | 5 +-- .../src/gui/feeds/PostedGroupItem.h | 4 +- .../src/gui/feeds/SecurityIpItem.cpp | 29 +++--------- retroshare-gui/src/gui/feeds/SecurityIpItem.h | 6 +-- retroshare-gui/src/gui/feeds/SecurityItem.cpp | 31 +++---------- retroshare-gui/src/gui/feeds/SecurityItem.h | 6 +-- retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp | 2 - .../src/gui/gxs/GxsGroupFeedItem.cpp | 25 +---------- retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h | 3 -- .../gui/gxschannels/GxsChannelPostsWidget.cpp | 34 +++++++------- .../gui/gxschannels/GxsChannelPostsWidget.h | 2 +- .../gui/gxschannels/GxsChannelPostsWidget.ui | 22 +++++----- 35 files changed, 149 insertions(+), 283 deletions(-) diff --git a/plugins/FeedReader/gui/FeedReaderFeedItem.h b/plugins/FeedReader/gui/FeedReaderFeedItem.h index 10776c08b..29b8c2bba 100644 --- a/plugins/FeedReader/gui/FeedReaderFeedItem.h +++ b/plugins/FeedReader/gui/FeedReaderFeedItem.h @@ -47,8 +47,7 @@ protected: private slots: /* default stuff */ - void removeItem(); - void toggle(); + void toggle() override; void readAndClearItem(); void copyLink(); @@ -61,9 +60,7 @@ private: RsFeedReader *mFeedReader; FeedReaderNotify *mNotify; - FeedHolder *mParent; - std::string mFeedId; std::string mMsgId; QString mLink; diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 995ac13fc..1afb1bfc8 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -480,14 +480,10 @@ void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace) void NewsFeed::remUniqueFeedItem(FeedItem *item) { - FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); + //FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier()); - if (feedItem) - { + ui->feedWidget->removeFeedItem(item); delete item; - - ui->feedWidget->removeFeedItem(feedItem); - } } /* FeedHolder Functions (for FeedItem functionality) */ @@ -496,7 +492,7 @@ QScrollArea *NewsFeed::getScrollArea() return NULL; } -void NewsFeed::deleteFeedItem(QWidget *item, uint32_t /*type*/) +void NewsFeed::deleteFeedItem(FeedItem *item, uint32_t /*type*/) { #ifdef NEWS_DEBUG std::cerr << "NewsFeed::deleteFeedItem()"; @@ -504,6 +500,7 @@ void NewsFeed::deleteFeedItem(QWidget *item, uint32_t /*type*/) #endif if (item) { + ui->feedWidget->removeFeedItem(item); item->close (); } } diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index c255d56ac..2492521f5 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -74,7 +74,7 @@ public: /* FeedHolder Functions (for FeedItem functionality) */ virtual QScrollArea *getScrollArea(); - virtual void deleteFeedItem(QWidget *item, uint32_t type); + virtual void deleteFeedItem(FeedItem *item, uint32_t type); virtual void openChat(const RsPeerId& peerId); virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &versions, const RsGxsMessageId &msgId, const QString &title); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 7bb920a6c..ef5e99fc2 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -60,7 +60,7 @@ private slots: void makeDownVote(); void readToggled(bool checked); void readAndClearItem(); - void toggle(); + void toggle() override; void copyMessageLink(); void toggleNotes(); diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp index b3bf1793a..9c86a2f9a 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp @@ -143,7 +143,7 @@ QScrollArea *PostedListWidget::getScrollArea() return ui->scrollArea; } -void PostedListWidget::deleteFeedItem(QWidget */*item*/, uint32_t /*type*/) +void PostedListWidget::deleteFeedItem(FeedItem *, uint32_t /*type*/) { #ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::deleteFeedItem() Nah"; diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.h b/retroshare-gui/src/gui/Posted/PostedListWidget.h index 8184a444c..cf05e9d4c 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.h @@ -48,7 +48,7 @@ public: /* FeedHolder */ virtual QScrollArea *getScrollArea(); - virtual void deleteFeedItem(QWidget *item, uint32_t type); + virtual void deleteFeedItem(FeedItem *item, uint32_t type); virtual void openChat(const RsPeerId& peerId); virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &versions, const RsGxsMessageId &msgId, const QString &title); diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index fff41d11b..f95977d82 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -111,7 +111,6 @@ bool RSFeedWidget::eventFilter(QObject *object, QEvent *event) FeedItem *feedItem = feedItemFromTreeItem(treeItem); if (feedItem) { disconnectSignals(feedItem); - feedRemoved(feedItem); delete(feedItem); } delete(treeItem); @@ -135,23 +134,19 @@ void RSFeedWidget::feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem) { } -void RSFeedWidget::feedRemoved(FeedItem *feedItem) -{ -} - void RSFeedWidget::feedsCleared() { } void RSFeedWidget::connectSignals(FeedItem *feedItem) { - connect(feedItem, SIGNAL(feedItemDestroyed(FeedItem*)), this, SLOT(feedItemDestroyed(FeedItem*))); + connect(feedItem, SIGNAL(feedItemNeedsClosing(qulonglong)), this, SLOT(feedItemDestroyed(qulonglong))); connect(feedItem, SIGNAL(sizeChanged(FeedItem*)), this, SLOT(feedItemSizeChanged(FeedItem*))); } void RSFeedWidget::disconnectSignals(FeedItem *feedItem) { - disconnect(feedItem, SIGNAL(feedItemDestroyed(FeedItem*)), this, SLOT(feedItemDestroyed(FeedItem*))); + disconnect(feedItem, SIGNAL(feedItemNeedsClosing(qulonglong)), this, SLOT(feedItemDestroyed(qulonglong))); disconnect(feedItem, SIGNAL(sizeChanged(FeedItem*)), this, SLOT(feedItemSizeChanged(FeedItem*))); } @@ -400,7 +395,6 @@ void RSFeedWidget::removeFeedItem(FeedItem *feedItem) return ; } - feedRemoved(feedItem); disconnectSignals(feedItem); delete ui->treeWidget->takeTopLevelItem(treeItem_index); @@ -424,14 +418,13 @@ void RSFeedWidget::feedItemSizeChanged(FeedItem */*feedItem*/) ui->treeWidget->doItemsLayout(); } -void RSFeedWidget::feedItemDestroyed(FeedItem *feedItem) +void RSFeedWidget::feedItemDestroyed(qulonglong id) { /* No need to disconnect when object will be destroyed */ - QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem->uniqueIdentifier()); + QTreeWidgetItem *treeItem = findTreeWidgetItem(id); - feedRemoved(feedItem); - if (treeItem) + if(treeItem) delete(treeItem); if (!mCountChangedDisabled) diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index bc38adf84..13a975475 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -87,11 +87,10 @@ public slots: protected: bool eventFilter(QObject *object, QEvent *event); virtual void feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem); - virtual void feedRemoved(FeedItem *feedItem); virtual void feedsCleared(); private slots: - void feedItemDestroyed(FeedItem *feedItem); + void feedItemDestroyed(qulonglong id); void feedItemSizeChanged(FeedItem *feedItem); private: diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp index ee7aa5ca8..7f37aef8b 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp @@ -43,7 +43,7 @@ /** Constructor */ ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, const std::string &message) : - FeedItem(NULL), mParent(parent), mFeedId(feedId), mPeerId(peerId) + FeedItem(parent,feedId,NULL), mPeerId(peerId) { /* Invoke the Qt Designer generated object setup routine */ setupUi(this); @@ -153,26 +153,6 @@ void ChatMsgItem::insertChat(const std::string &message) chatTextlabel->setText(formatMsg); } -void ChatMsgItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "ChatMsgItem::removeItem()"; - std::cerr << std::endl; -#endif - - if (mParent) { - mParent->lockLayout(this, true); - } - - hide(); - - if (mParent) { - mParent->lockLayout(this, false); - - mParent->deleteFeedItem(this, mFeedId); - } -} - void ChatMsgItem::gotoHome() { #ifdef DEBUG_ITEM @@ -191,7 +171,7 @@ void ChatMsgItem::sendMsg() std::cerr << std::endl; #endif - if (mParent) + if (mFeedHolder) { MessageComposer *nMsgDialog = MessageComposer::newMsg(); @@ -214,15 +194,15 @@ void ChatMsgItem::openChat() std::cerr << "ChatMsgItem::openChat()"; std::cerr << std::endl; #endif - if (mParent) + if (mFeedHolder) { - mParent->openChat(mPeerId); + mFeedHolder->openChat(mPeerId); } } void ChatMsgItem::togglequickmessage() { - mParent->lockLayout(this, true); + mFeedHolder->lockLayout(this, true); if (messageFrame->isHidden()) { @@ -239,7 +219,7 @@ void ChatMsgItem::togglequickmessage() emit sizeChanged(this); - mParent->lockLayout(this, false); + mFeedHolder->lockLayout(this, false); } void ChatMsgItem::sendMessage() diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h index fe946a4b9..421cbfda8 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -45,7 +45,6 @@ protected: private slots: /* default stuff */ void gotoHome(); - void removeItem(); void sendMsg(); void openChat(); @@ -60,9 +59,6 @@ private slots: private: void insertChat(const std::string &message); - FeedHolder *mParent; - uint32_t mFeedId; - RsPeerId mPeerId; }; diff --git a/retroshare-gui/src/gui/feeds/FeedHolder.h b/retroshare-gui/src/gui/feeds/FeedHolder.h index f683bca19..6c2f256e0 100644 --- a/retroshare-gui/src/gui/feeds/FeedHolder.h +++ b/retroshare-gui/src/gui/feeds/FeedHolder.h @@ -27,6 +27,7 @@ #include // WRONG ONE - BUT IT'LL DO FOR NOW. class QScrollArea; +class FeedItem; class FeedHolder { @@ -34,7 +35,7 @@ public: FeedHolder(); virtual QScrollArea *getScrollArea() = 0; - virtual void deleteFeedItem(QWidget *item, uint32_t type) = 0; + virtual void deleteFeedItem(FeedItem *item, uint32_t type) = 0; virtual void openChat(const RsPeerId& peerId) = 0; virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &msg_versions, const RsGxsMessageId &msgId, const QString &title)=0; diff --git a/retroshare-gui/src/gui/feeds/FeedItem.cpp b/retroshare-gui/src/gui/feeds/FeedItem.cpp index 2e5353e40..5f0821790 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.cpp +++ b/retroshare-gui/src/gui/feeds/FeedItem.cpp @@ -20,17 +20,15 @@ #include #include "FeedItem.h" +#include "FeedHolder.h" /** Constructor */ -FeedItem::FeedItem(QWidget *parent) : QWidget(parent), mHash(0) +FeedItem::FeedItem(FeedHolder *fh, uint32_t feedId, QWidget *parent) : QWidget(parent), mHash(0),mFeedHolder(fh),mFeedId(feedId) { mWasExpanded = false; } -FeedItem::~FeedItem() -{ - emit feedItemDestroyed(this); -} +FeedItem::~FeedItem() { } void FeedItem::expand(bool open) { @@ -48,12 +46,36 @@ void FeedItem::expand(bool open) uint64_t FeedItem::hash_64bits(const std::string& s) const { if(mHash == 0) - { - mHash = 0x01110bbfa09; - - for(uint32_t i=0;i> 3)) + s[i]*0x217898fbba7 + 0x0294379); - } + mHash = hash64(s); return mHash; } + +uint64_t FeedItem::hash64(const std::string& s) +{ + uint64_t hash = 0x01110bbfa09; + + for(uint32_t i=0;i> 3)) + s[i]*0x217898fbba7 + 0x0294379); + + return hash; +} + +void FeedItem::removeItem() +{ +#ifdef DEBUG_ITEM + std::cerr << "MsgItem::removeItem()"; + std::cerr << std::endl; +#endif + + mFeedHolder->deleteFeedItem(this,0); + +// mFeedHolder->lockLayout(this, true); +// hide(); +// +// if (mFeedHolder) +// mFeedHolder->deleteFeedItem(this, mFeedId); +// +// mFeedHolder->lockLayout(this, false); +} + diff --git a/retroshare-gui/src/gui/feeds/FeedItem.h b/retroshare-gui/src/gui/feeds/FeedItem.h index 7cd6808a1..7739ac122 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.h +++ b/retroshare-gui/src/gui/feeds/FeedItem.h @@ -23,13 +23,15 @@ #include +class FeedHolder; + class FeedItem : public QWidget { Q_OBJECT public: /** Default Constructor */ - FeedItem(QWidget *parent = 0); + FeedItem(FeedHolder *fh,uint32_t feedId,QWidget *parent = 0); /** Default Destructor */ virtual ~FeedItem(); @@ -42,14 +44,25 @@ public: * would contain the same information. It should therefore sumarise the data represented by the item. */ virtual uint64_t uniqueIdentifier() const =0; + + static uint64_t hash64(const std::string& s); + +protected slots: + void removeItem(); + protected: virtual void doExpand(bool open) = 0; virtual void expandFill(bool /*first*/) {} + virtual void toggle() {} + uint64_t hash_64bits(const std::string& s) const; + + FeedHolder *mFeedHolder; + uint32_t mFeedId; signals: void sizeChanged(FeedItem *feedItem); - void feedItemDestroyed(FeedItem *feedItem); + void feedItemNeedsClosing(qulonglong); private: bool mWasExpanded; diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h index 1a0c56a70..266d1c019 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h @@ -53,7 +53,7 @@ protected: private slots: /* default stuff */ - void toggle(); + void toggle() override; void subscribeChannel(); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 8b9d21c57..9e37a797e 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -66,6 +66,7 @@ public: bool isUnread() const ; + static uint64_t computeIdentifier(const RsGxsMessageId& msgid) { hash64("GxsChannelPostItem " + msgid.toStdString()) ; } protected: void init(const RsGxsMessageId& messageId,const std::set& older_versions); @@ -90,7 +91,7 @@ protected: private slots: /* default stuff */ - void toggle(); + void toggle() override; void readAndClearItem(); void download(); void play(); diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp index aa161cde4..7673c6d19 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp @@ -40,7 +40,7 @@ GxsCircleItem::GxsCircleItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsCircleId &circleId, const RsGxsId &gxsId, const uint32_t type) - :FeedItem(NULL), mFeedHolder(feedHolder), mFeedId(feedId), mType(type), mCircleId(circleId), mGxsId(gxsId) + :FeedItem(feedHolder,feedId,NULL), mType(type), mCircleId(circleId), mGxsId(gxsId) { setup(); } @@ -172,22 +172,6 @@ uint64_t GxsCircleItem::uniqueIdentifier() const return hash_64bits("GxsCircle " + mCircleId.toStdString() + " " + mGxsId.toStdString() + " " + QString::number(mType).toStdString()); } -void GxsCircleItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "GxsCircleItem::removeItem()" << std::endl; -#endif - - if (mFeedHolder) - { - mFeedHolder->lockLayout(this, true); - hide(); - mFeedHolder->lockLayout(this, false); - - mFeedHolder->deleteFeedItem(this, mFeedId); - } -} - void GxsCircleItem::loadRequest(const TokenQueue * queue, const TokenRequest &req) { #ifdef ID_DEBUG diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.h b/retroshare-gui/src/gui/feeds/GxsCircleItem.h index a45114ed6..8c611c06b 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.h +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.h @@ -65,9 +65,6 @@ protected: private slots: - /* default stuff */ - void removeItem(); - void showCircleDetails(); void acceptCircleSubscription(); void grantCircleMembership() ; @@ -76,8 +73,6 @@ private slots: private: void setup(); - FeedHolder *mFeedHolder; - uint32_t mFeedId; uint32_t mType; RsGxsCircleId mCircleId; diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp index 1e430638a..8b97d73cf 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp @@ -158,7 +158,6 @@ void GxsForumGroupItem::fill() ui->clearButton->setEnabled(false); } } - void GxsForumGroupItem::toggle() { expand(ui->expandFrame->isHidden()); diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h index 87bffa022..3ac198630 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h @@ -46,6 +46,7 @@ public: protected: /* FeedItem */ virtual void doExpand(bool open); + void toggle() override; /* GxsGroupFeedItem */ virtual QString groupName(); @@ -53,9 +54,6 @@ protected: virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; } private slots: - /* default stuff */ - void toggle(); - void subscribeForum(); private: diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index be275aa07..d3d81de1d 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -67,7 +67,7 @@ protected: private slots: /* default stuff */ - void toggle(); + void toggle() override; void readAndClearItem(); void unsubscribeForum(); diff --git a/retroshare-gui/src/gui/feeds/MsgItem.cpp b/retroshare-gui/src/gui/feeds/MsgItem.cpp index c0dd8768e..181774a00 100644 --- a/retroshare-gui/src/gui/feeds/MsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/MsgItem.cpp @@ -43,7 +43,7 @@ /** Constructor */ MsgItem::MsgItem(FeedHolder *parent, uint32_t feedId, const std::string &msgId, bool isHome) : - FeedItem(NULL), mParent(parent), mFeedId(feedId), mMsgId(msgId), mIsHome(isHome) + FeedItem(parent,feedId,NULL), mMsgId(msgId), mIsHome(isHome) { /* Invoke the Qt Designer generated object setup routine */ setupUi(this); @@ -222,15 +222,10 @@ void MsgItem::updateItem() } } -void MsgItem::toggle() -{ - expand(expandFrame->isHidden()); -} - void MsgItem::doExpand(bool open) { - if (mParent) { - mParent->lockLayout(this, true); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, true); } if (open) @@ -252,8 +247,8 @@ void MsgItem::doExpand(bool open) emit sizeChanged(this); - if (mParent) { - mParent->lockLayout(this, false); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, false); } } @@ -266,23 +261,6 @@ void MsgItem::expandFill(bool first) } } -void MsgItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "MsgItem::removeItem()"; - std::cerr << std::endl; -#endif - - mParent->lockLayout(this, true); - hide(); - mParent->lockLayout(this, false); - - if (mParent) - { - mParent->deleteFeedItem(this, mFeedId); - } -} - void MsgItem::gotoHome() { @@ -315,7 +293,7 @@ void MsgItem::replyMsg() std::cerr << "MsgItem::replyMsg()"; std::cerr << std::endl; #endif - if (mParent) + if (mFeedHolder) { //mParent->openMsg(FEEDHOLDER_MSG_MESSAGE, mPeerId, mMsgId); @@ -339,6 +317,11 @@ void MsgItem::playMedia() #endif } +void MsgItem::toggle() +{ + expand(expandFrame->isHidden()); +} + void MsgItem::checkMessageReadStatus() { if (!mCloseOnRead) { diff --git a/retroshare-gui/src/gui/feeds/MsgItem.h b/retroshare-gui/src/gui/feeds/MsgItem.h index 469f8cbb7..32824ca23 100644 --- a/retroshare-gui/src/gui/feeds/MsgItem.h +++ b/retroshare-gui/src/gui/feeds/MsgItem.h @@ -50,7 +50,6 @@ private: private slots: /* default stuff */ void gotoHome(); - void removeItem(); void toggle(); void playMedia(); @@ -62,9 +61,6 @@ private slots: void updateItem(); private: - FeedHolder *mParent; - uint32_t mFeedId; - std::string mMsgId; QString mMsg; diff --git a/retroshare-gui/src/gui/feeds/PeerItem.cpp b/retroshare-gui/src/gui/feeds/PeerItem.cpp index 87d510e4b..2a6f0b19d 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.cpp +++ b/retroshare-gui/src/gui/feeds/PeerItem.cpp @@ -41,7 +41,7 @@ /** Constructor */ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, uint32_t type, bool isHome) : - FeedItem(NULL), mParent(parent), mFeedId(feedId), + FeedItem(parent,feedId,NULL), mPeerId(peerId), mType(type), mIsHome(isHome) { /* Invoke the Qt Designer generated object setup routine */ @@ -50,12 +50,12 @@ PeerItem::PeerItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, sendmsgButton->setEnabled(false); /* general ones */ - connect( expandButton, SIGNAL( clicked( void ) ), this, SLOT( toggle ( void ) ) ); - connect( clearButton, SIGNAL( clicked( void ) ), this, SLOT( removeItem ( void ) ) ); + connect( expandButton, SIGNAL( clicked() ), this, SLOT( toggle() ) ); + connect( clearButton, SIGNAL( clicked() ), this, SLOT( removeItem() ) ); /* specific ones */ - connect( chatButton, SIGNAL( clicked( void ) ), this, SLOT( openChat ( void ) ) ); - connect( sendmsgButton, SIGNAL( clicked( ) ), this, SLOT( sendMsg() ) ); + connect( chatButton, SIGNAL( clicked() ), this, SLOT( openChat() ) ); + connect( sendmsgButton, SIGNAL( clicked() ), this, SLOT( sendMsg() ) ); connect(NotifyQt::getInstance(), SIGNAL(friendsChanged()), this, SLOT(updateItem())); @@ -225,7 +225,7 @@ void PeerItem::updateItem() /* slow Tick */ int msec_rate = 10129; - QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); + QTimer::singleShot( msec_rate, this, SLOT(updateItem() )); return; } @@ -236,8 +236,8 @@ void PeerItem::toggle() void PeerItem::doExpand(bool open) { - if (mParent) { - mParent->lockLayout(this, true); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, true); } if (open) @@ -255,25 +255,8 @@ void PeerItem::doExpand(bool open) emit sizeChanged(this); - if (mParent) { - mParent->lockLayout(this, false); - } -} - -void PeerItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "PeerItem::removeItem()"; - std::cerr << std::endl; -#endif - - mParent->lockLayout(this, true); - hide(); - mParent->lockLayout(this, false); - - if (mParent) - { - mParent->deleteFeedItem(this, mFeedId); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, false); } } @@ -321,9 +304,9 @@ void PeerItem::openChat() std::cerr << "PeerItem::openChat()"; std::cerr << std::endl; #endif - if (mParent) + if (mFeedHolder) { - mParent->openChat(mPeerId); + mFeedHolder->openChat(mPeerId); } } diff --git a/retroshare-gui/src/gui/feeds/PeerItem.h b/retroshare-gui/src/gui/feeds/PeerItem.h index 6e17fbae3..22b9bbaf0 100644 --- a/retroshare-gui/src/gui/feeds/PeerItem.h +++ b/retroshare-gui/src/gui/feeds/PeerItem.h @@ -51,8 +51,7 @@ protected: private slots: /* default stuff */ - void removeItem(); - void toggle(); + void toggle() override; void addFriend(); void removeFriend(); @@ -63,8 +62,6 @@ private slots: private: - FeedHolder *mParent; - uint32_t mFeedId; RsPeerId mPeerId; uint32_t mType; diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.h b/retroshare-gui/src/gui/feeds/PostedGroupItem.h index 999abf652..88e1906dc 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.h +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.h @@ -54,9 +54,7 @@ protected: virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; } private slots: - /* default stuff */ - void toggle(); - + void toggle() override; void subscribePosted(); private: diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp index 40914fc7e..590bd0588 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp @@ -40,14 +40,14 @@ /** Constructor */ SecurityIpItem::SecurityIpItem(FeedHolder *parent, const RsPeerId &sslId, const std::string &ipAddr, uint32_t result, uint32_t type, bool isTest) : - FeedItem(NULL), mParent(parent), mType(type), mSslId(sslId), mIpAddr(ipAddr), mResult(result), mIsTest(isTest), + FeedItem(parent,0,NULL), mType(type), mSslId(sslId), mIpAddr(ipAddr), mResult(result), mIsTest(isTest), ui(new(Ui::SecurityIpItem)) { setup(); } SecurityIpItem::SecurityIpItem(FeedHolder *parent, const RsPeerId &sslId, const std::string& ipAddr, const std::string& ipAddrReported, uint32_t type, bool isTest) : - FeedItem(NULL), mParent(parent), mType(type), mSslId(sslId), mIpAddr(ipAddr), mIpAddrReported(ipAddrReported), mResult(0), mIsTest(isTest), + FeedItem(parent,0,NULL), mType(type), mSslId(sslId), mIpAddr(ipAddr), mIpAddrReported(ipAddrReported), mResult(0), mIsTest(isTest), ui(new(Ui::SecurityIpItem)) { setup(); @@ -192,8 +192,8 @@ void SecurityIpItem::toggle() void SecurityIpItem::doExpand(bool open) { - if (mParent) { - mParent->lockLayout(this, true); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, true); } if (open) @@ -211,25 +211,8 @@ void SecurityIpItem::doExpand(bool open) emit sizeChanged(this); - if (mParent) { - mParent->lockLayout(this, false); - } -} - -void SecurityIpItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "SecurityIpItem::removeItem()"; - std::cerr << std::endl; -#endif - - mParent->lockLayout(this, true); - hide(); - mParent->lockLayout(this, false); - - if (mParent) - { - mParent->deleteFeedItem(this, mFeedId); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, false); } } diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.h b/retroshare-gui/src/gui/feeds/SecurityIpItem.h index d4648ab0a..bfef10634 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.h @@ -54,16 +54,12 @@ private: private slots: /* default stuff */ - void removeItem(); - void toggle(); + void toggle() override; void peerDetails(); void updateItem(); void banIpListChanged(const QString &ipAddress); private: - FeedHolder *mParent; - uint32_t mFeedId; - uint32_t mType; RsPeerId mSslId; std::string mIpAddr; diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index b5aa9d8a4..aedfd4e6c 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -44,7 +44,7 @@ /** Constructor */ SecurityItem::SecurityItem(FeedHolder *parent, uint32_t feedId, const RsPgpId &gpgId, const RsPeerId &sslId, const std::string &sslCn, const std::string& ip_address,uint32_t type, bool isHome) : - FeedItem(NULL), mParent(parent), mFeedId(feedId), + FeedItem(parent,feedId,NULL), mGpgId(gpgId), mSslId(sslId), mSslCn(sslCn), mIP(ip_address), mType(type), mIsHome(isHome) { /* Invoke the Qt Designer generated object setup routine */ @@ -288,8 +288,8 @@ void SecurityItem::toggle() void SecurityItem::doExpand(bool open) { - if (mParent) { - mParent->lockLayout(this, true); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, true); } if (open) @@ -307,25 +307,8 @@ void SecurityItem::doExpand(bool open) emit sizeChanged(this); - if (mParent) { - mParent->lockLayout(this, false); - } -} - -void SecurityItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "SecurityItem::removeItem()"; - std::cerr << std::endl; -#endif - - mParent->lockLayout(this, true); - hide(); - mParent->lockLayout(this, false); - - if (mParent) - { - mParent->deleteFeedItem(this, mFeedId); + if (mFeedHolder) { + mFeedHolder->lockLayout(this, false); } } @@ -413,8 +396,8 @@ void SecurityItem::openChat() std::cerr << "SecurityItem::openChat()"; std::cerr << std::endl; #endif - if (mParent) + if (mFeedHolder) { - mParent->openChat(mSslId); + mFeedHolder->openChat(mSslId); } } diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index 1c9bbe054..7f99c8377 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -50,8 +50,7 @@ protected: private slots: /* default stuff */ - void removeItem(); - void toggle(); + void toggle() override; void friendRequest(); void removeFriend(); @@ -62,9 +61,6 @@ private slots: void updateItem(); private: - FeedHolder *mParent; - uint32_t mFeedId; - RsPgpId mGpgId; RsPeerId mSslId; std::string mSslCn; diff --git a/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp b/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp index 9ccaa55fa..e714b5347 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsFeedWidget.cpp @@ -46,8 +46,6 @@ void GxsFeedWidget::feedAdded(FeedItem *feedItem, QTreeWidgetItem *treeItem) void GxsFeedWidget::feedRemoved(FeedItem *feedItem) { - RSFeedWidget::feedRemoved(feedItem); - GxsFeedItem *gxsFeedItem = dynamic_cast(feedItem); if (!gxsFeedItem) { return; diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp index 59ff10056..1f5b09cb8 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp @@ -32,7 +32,7 @@ **/ GxsGroupFeedItem::GxsGroupFeedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, bool isHome, RsGxsIfaceHelper *iface, bool autoUpdate) : - FeedItem(NULL) + FeedItem(feedHolder,feedId,NULL) { #ifdef DEBUG_ITEM std::cerr << "GxsGroupFeedItem::GxsGroupFeedItem()"; @@ -40,8 +40,6 @@ GxsGroupFeedItem::GxsGroupFeedItem(FeedHolder *feedHolder, uint32_t feedId, cons #endif /* this are just generally useful for all children */ - mFeedHolder = feedHolder; - mFeedId = feedId; mIsHome = isHome; /* load data if we can */ @@ -93,27 +91,6 @@ bool GxsGroupFeedItem::initLoadQueue() return (mLoadQueue != NULL); } -void GxsGroupFeedItem::removeItem() -{ -#ifdef DEBUG_ITEM - std::cerr << "GxsGroupFeedItem::removeItem()"; - std::cerr << std::endl; -#endif - - if (mFeedHolder) - { - mFeedHolder->lockLayout(this, true); - } - - hide(); - - if (mFeedHolder) - { - mFeedHolder->lockLayout(this, false); - mFeedHolder->deleteFeedItem(this, mFeedId); - } -} - void GxsGroupFeedItem::unsubscribe() { #ifdef DEBUG_ITEM diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h index ac851a97d..9696490d9 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h @@ -64,12 +64,9 @@ protected: protected slots: void subscribe(); void unsubscribe(); - void removeItem(); void copyGroupLink(); protected: - FeedHolder *mFeedHolder; - uint32_t mFeedId; bool mIsHome; RsGxsIfaceHelper *mGxsIface; TokenQueue *mLoadQueue; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index d463170af..c40467761 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -233,8 +233,12 @@ QScrollArea *GxsChannelPostsWidget::getScrollArea() return NULL; } -void GxsChannelPostsWidget::deleteFeedItem(QWidget * /*item*/, uint32_t /*type*/) +void GxsChannelPostsWidget::deleteFeedItem(FeedItem *feedItem, uint32_t /*type*/) { + if (!feedItem) + return; + + ui->feedWidget->removeFeedItem(feedItem); } void GxsChannelPostsWidget::openChat(const RsPeerId & /*peerId*/) @@ -460,7 +464,7 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost& post, bool re if(!post.mMeta.mOrigMsgId.isNull()) { - FeedItem *feedItem = ui->feedWidget->findGxsFeedItem(post.mMeta.mGroupId, post.mMeta.mOrigMsgId); + FeedItem *feedItem = ui->feedWidget->findFeedItem(GxsChannelPostItem::computeIdentifier(post.mMeta.mOrigMsgId)) ; item = dynamic_cast(feedItem); if(item) @@ -476,7 +480,7 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost& post, bool re if (related) { - FeedItem *feedItem = ui->feedWidget->findGxsFeedItem(post.mMeta.mGroupId, post.mMeta.mMsgId); + FeedItem *feedItem = ui->feedWidget->findFeedItem(GxsChannelPostItem::computeIdentifier(post.mMeta.mMsgId)) ; item = dynamic_cast(feedItem); } if (item) { @@ -669,7 +673,7 @@ void GxsChannelPostsWidget::blank() bool GxsChannelPostsWidget::navigatePostItem(const RsGxsMessageId &msgId) { - FeedItem *feedItem = ui->feedWidget->findGxsFeedItem(groupId(), msgId); + FeedItem *feedItem = ui->feedWidget->findFeedItem(GxsChannelPostItem::computeIdentifier(msgId)); if (!feedItem) { return false; } @@ -718,17 +722,17 @@ void GxsChannelPostsWidget::toggleAutoDownload() return; } - RsQThreadUtils::postToObject( [=]() - { - /* Here it goes any code you want to be executed on the Qt Gui - * thread, for example to update the data model with new information - * after a blocking call to RetroShare API complete, note that - * Qt::QueuedConnection is important! - */ - - std::cerr << __PRETTY_FUNCTION__ << " Has been executed on GUI " - << "thread but was scheduled by async thread" << std::endl; - }, this ); +// RsQThreadUtils::postToObject( [=]() +// { +// /* Here it goes any code you want to be executed on the Qt Gui +// * thread, for example to update the data model with new information +// * after a blocking call to RetroShare API complete, note that +// * Qt::QueuedConnection is important! +// */ +// +// std::cerr << __PRETTY_FUNCTION__ << " Has been executed on GUI " +// << "thread but was scheduled by async thread" << std::endl; +// }, this ); }); } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h index a4723c18f..6f27ed677 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h @@ -58,7 +58,7 @@ public: /* FeedHolder */ virtual QScrollArea *getScrollArea(); - virtual void deleteFeedItem(QWidget *item, uint32_t type); + virtual void deleteFeedItem(FeedItem *feedItem, uint32_t type); virtual void openChat(const RsPeerId& peerId); virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const QVector &msg_versions, const RsGxsMessageId &msgId, const QString &title); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui index 59703a0d7..fb6845f26 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui @@ -6,8 +6,8 @@ 0 0 - 880 - 557 + 977 + 628 @@ -369,7 +369,7 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +</style></head><body style=" font-family:'Sans'; font-size:9pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;">Description</span></p></body></html> @@ -525,7 +525,7 @@ p, li { white-space: pre-wrap; } - + 0 @@ -572,22 +572,22 @@ p, li { white-space: pre-wrap; } QLineEdit
gui/common/LineEditClear.h
- - GxsFeedWidget - QWidget -
gui/gxs/GxsFeedWidget.h
- 1 -
GxsChannelFilesWidget QWidget
gui/gxschannels/GxsChannelFilesWidget.h
1
+ + RSFeedWidget + QWidget +
gui/common/RSFeedWidget.h
+ 1 +
- + From 5df7f7667f820a009a3d1e0dd2bd8a0a2f0c44ad Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 16 Jan 2020 20:33:34 +0100 Subject: [PATCH 10/11] fixed crash in NewFeed when attempting to find a widget using its identifier --- retroshare-gui/src/gui/Posted/PostedItem.h | 2 +- .../src/gui/common/RSFeedWidget.cpp | 57 ++++++++++++------- retroshare-gui/src/gui/common/RSFeedWidget.h | 1 + retroshare-gui/src/gui/feeds/FeedItem.cpp | 8 --- .../src/gui/feeds/GxsChannelPostItem.cpp | 5 +- .../src/gui/feeds/GxsChannelPostItem.h | 4 +- .../src/gui/feeds/GxsForumMsgItem.h | 2 +- 7 files changed, 44 insertions(+), 35 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index ef5e99fc2..aa855d72b 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -49,7 +49,7 @@ public: const RsPostedPost &getPost() const; RsPostedPost &post(); - uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + mMessageId.toStdString()); } + uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); } protected: /* FeedItem */ virtual void doExpand(bool open); diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.cpp b/retroshare-gui/src/gui/common/RSFeedWidget.cpp index f95977d82..3293e3fae 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.cpp +++ b/retroshare-gui/src/gui/common/RSFeedWidget.cpp @@ -379,11 +379,10 @@ FeedItem *RSFeedWidget::feedItem(int index) void RSFeedWidget::removeFeedItem(FeedItem *feedItem) { - if (!feedItem) { + if (!feedItem) return; - } - QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem->uniqueIdentifier()); + QTreeWidgetItem *treeItem = findTreeWidgetItem(feedItem);// WARNING: do not use the other function based on identifier here, because some items change their identifier when loading. if (treeItem) { @@ -391,7 +390,7 @@ void RSFeedWidget::removeFeedItem(FeedItem *feedItem) if(treeItem_index < 0) { - std::cerr << "(EE) Cannot remove designated item \"" << feedItem->uniqueIdentifier() << "\": not found!" << std::endl; + std::cerr << "(EE) Cannot remove designated item \"" << (void*)feedItem << "\": not found!" << std::endl; return ; } @@ -431,6 +430,26 @@ void RSFeedWidget::feedItemDestroyed(qulonglong id) emit feedCountChanged(); } +QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(const FeedItem *w) +{ + QTreeWidgetItemIterator it(ui->treeWidget); + QTreeWidgetItem *treeItem=NULL; + + // this search could probably be automatised by giving the tree items the identifier as data for some specific role, then calling QTreeWidget::findItems() + #warning TODO + while (*it) + { + FeedItem *feedItem = feedItemFromTreeItem(*it); + + if (feedItem == w) + return *it; + + ++it; + } + + return NULL; +} + QTreeWidgetItem *RSFeedWidget::findTreeWidgetItem(uint64_t identifier) { QList list = ui->treeWidget->findItems(QString("%1").arg(identifier,8,16,QChar('0')),Qt::MatchExactly,COLUMN_IDENTIFIER); @@ -483,27 +502,21 @@ void RSFeedWidget::withAll(RSFeedWidgetCallbackFunction callback, void *data) FeedItem *RSFeedWidget::findFeedItem(uint64_t identifier) { - QTreeWidgetItemIterator it(ui->treeWidget); - QTreeWidgetItem *treeItem=NULL; + QList list = ui->treeWidget->findItems(QString("%1").arg(identifier,8,16,QChar('0')),Qt::MatchExactly,COLUMN_IDENTIFIER); - // this search could probably be automatised by giving the tree items the identifier as data for some specific role, then calling QTreeWidget::findItems() -#warning TODO - while ((treeItem = *it) != NULL) { - ++it; - - FeedItem *feedItem = feedItemFromTreeItem(treeItem); - if (!feedItem) - continue; - - uint64_t id = feedItem->uniqueIdentifier(); - - if (id == identifier) - return feedItem; - } - - return NULL; + if(list.empty()) + return nullptr; + else if(list.size() == 1) + return feedItemFromTreeItem(list.front()); + else + { + std::cerr << "(EE) More than a single item with identifier \"" << identifier << "\" in the feed tree widget. This shouldn't happen!" << std::endl; + return nullptr; + } } + + void RSFeedWidget::selectedFeedItems(QList &feedItems) { foreach (QTreeWidgetItem *treeItem, ui->treeWidget->selectedItems()) { diff --git a/retroshare-gui/src/gui/common/RSFeedWidget.h b/retroshare-gui/src/gui/common/RSFeedWidget.h index 13a975475..c0278d786 100644 --- a/retroshare-gui/src/gui/common/RSFeedWidget.h +++ b/retroshare-gui/src/gui/common/RSFeedWidget.h @@ -98,6 +98,7 @@ private: void disconnectSignals(FeedItem *feedItem); FeedItem *feedItemFromTreeItem(QTreeWidgetItem *treeItem); QTreeWidgetItem *findTreeWidgetItem(uint64_t identifier); + QTreeWidgetItem *findTreeWidgetItem(const FeedItem *w); void filterItems(); void filterItem(QTreeWidgetItem *treeItem, FeedItem *feedItem); diff --git a/retroshare-gui/src/gui/feeds/FeedItem.cpp b/retroshare-gui/src/gui/feeds/FeedItem.cpp index 5f0821790..83c97eb3b 100644 --- a/retroshare-gui/src/gui/feeds/FeedItem.cpp +++ b/retroshare-gui/src/gui/feeds/FeedItem.cpp @@ -69,13 +69,5 @@ void FeedItem::removeItem() #endif mFeedHolder->deleteFeedItem(this,0); - -// mFeedHolder->lockLayout(this, true); -// hide(); -// -// if (mFeedHolder) -// mFeedHolder->deleteFeedItem(this, mFeedId); -// -// mFeedHolder->lockLayout(this, false); } diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index cdb4eeaf2..687dd2846 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -46,12 +46,14 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set& older_versions) : GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsGxsChannels, autoUpdate) { + mPost.mMeta.mMsgId = messageId; // useful for uniqueIdentifer() before the post is loaded init(messageId,older_versions) ; } GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost& post, bool isHome, bool autoUpdate,const std::set& older_versions) : GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, autoUpdate) { + mPost.mMeta.mMsgId.clear(); // security init(post.mMeta.mMsgId,older_versions) ; mPost = post ; } @@ -71,7 +73,6 @@ void GxsChannelPostItem::init(const RsGxsMessageId& messageId,const std::set& older_versions); diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index d3d81de1d..332d5877e 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -43,7 +43,7 @@ public: bool setGroup(const RsGxsForumGroup &group, bool doFill = true); bool setMessage(const RsGxsForumMsg &msg, bool doFill = true); - uint64_t uniqueIdentifier() const override { return hash_64bits("GxsForumMsgItem " + mMessage.mMeta.mMsgId.toStdString()) ; } + uint64_t uniqueIdentifier() const override { return hash_64bits("GxsForumMsgItem " + messageId().toStdString()) ; } protected: /* FeedItem */ virtual void doExpand(bool open); From 8941a19db92ca50a20c8b701e9baa9be5050e1ab Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 17 Jan 2020 21:22:39 +0100 Subject: [PATCH 11/11] fixed mistake that causes missing FeedItems for messages and posted --- libretroshare/src/services/p3msgservice.cc | 9 +++------ retroshare-gui/src/gui/NewsFeed.cpp | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 8acd44501..b1c1bf847 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -2134,8 +2134,7 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId, { RS_STACK_MUTEX(recentlyReceivedMutex); - if( mRecentlyReceivedMessageHashes.find(hash) != - mRecentlyReceivedMessageHashes.end() ) + if( mRecentlyReceivedMessageHashes.find(hash) != mRecentlyReceivedMessageHashes.end() ) { RsInfo() << __PRETTY_FUNCTION__ << " (II) receiving " << "message of hash " << hash << " more than once. " @@ -2143,14 +2142,12 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId, << std::endl; return true; } - mRecentlyReceivedMessageHashes[hash] = - static_cast(time(nullptr)); + mRecentlyReceivedMessageHashes[hash] = static_cast(time(nullptr)); } IndicateConfigChanged(); - RsItem *item = _serialiser->deserialise( - const_cast(data), &dataSize ); + RsItem *item = _serialiser->deserialise( const_cast(data), &dataSize ); RsMsgItem *msg_item = dynamic_cast(item); if(msg_item) diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 1afb1bfc8..872a819ce 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -188,10 +188,10 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) handleForumEvent(event); if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) - handleMailEvent(event); + handlePostedEvent(event); if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MSG)) - handlePostedEvent(event); + handleMailEvent(event); } void NewsFeed::handleMailEvent(std::shared_ptr event)