diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp index 07d2f696d..fdbd678d8 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.cpp @@ -36,6 +36,9 @@ #include "gui/msgs/MessageInterface.h" +#include "util/qtthreadsutils.h" +#include "retroshare/rsevents.h" + /***** * #define DEBUG_ITEM 1 ****/ @@ -67,6 +70,27 @@ ChatMsgItem::ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &pe updateItemStatic(); updateItem(); insertChat(message); + + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + auto fe = dynamic_cast(e.get()); + + if(!fe || fe->mSslId != mPeerId) + return; + + updateItem(); + } + , this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); +} + +ChatMsgItem::~ChatMsgItem() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); } void ChatMsgItem::updateItemStatic() @@ -122,11 +146,6 @@ void ChatMsgItem::updateItem() msgButton->setEnabled(false); } } - - /* slow Tick */ - int msec_rate = 10129; - - QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); return; } diff --git a/retroshare-gui/src/gui/feeds/ChatMsgItem.h b/retroshare-gui/src/gui/feeds/ChatMsgItem.h index 421cbfda8..0515b925e 100644 --- a/retroshare-gui/src/gui/feeds/ChatMsgItem.h +++ b/retroshare-gui/src/gui/feeds/ChatMsgItem.h @@ -35,6 +35,8 @@ public: /** Default Constructor */ ChatMsgItem(FeedHolder *parent, uint32_t feedId, const RsPeerId &peerId, const std::string &message); + virtual ~ChatMsgItem(); + void updateItemStatic(); virtual uint64_t uniqueIdentifier() const override { return hash_64bits("ChatMsgItem " + mPeerId.toStdString()); } @@ -60,6 +62,7 @@ private: void insertChat(const std::string &message); RsPeerId mPeerId; + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp index 6d03cbf56..6d1a3e809 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.cpp @@ -34,6 +34,8 @@ #include #include +#include "util/qtthreadsutils.h" + /***** * #define DEBUG_ITEM 1 ****/ @@ -53,6 +55,11 @@ SecurityIpItem::SecurityIpItem(FeedHolder *parent, const RsPeerId &sslId, const setup(); } +SecurityIpItem::~SecurityIpItem() +{ + rsEvents->unregisterEventsHandler(mEventHandlerId); +} + void SecurityIpItem::setup() { /* Invoke the Qt Designer generated object setup routine */ @@ -76,6 +83,21 @@ void SecurityIpItem::setup() updateItemStatic(); updateItem(); + + mEventHandlerId = 0; + + rsEvents->registerEventsHandler( [this](std::shared_ptr e) + { + RsQThreadUtils::postToObject([=]() + { + // Filter events to only update relevant items. + auto fe = dynamic_cast(e.get()); + if(!fe || fe->mSslId != mSslId) + return; + updateItem(); + } + , this ); + }, mEventHandlerId, RsEventType::FRIEND_LIST ); } uint64_t SecurityIpItem::uniqueIdentifier() const @@ -178,11 +200,6 @@ void SecurityIpItem::updateItem() ui->peerDetailsButton->setEnabled(true); } } - - /* slow Tick */ - int msec_rate = 10129; - - QTimer::singleShot( msec_rate, this, SLOT(updateItem(void))); } void SecurityIpItem::toggle() diff --git a/retroshare-gui/src/gui/feeds/SecurityIpItem.h b/retroshare-gui/src/gui/feeds/SecurityIpItem.h index 506bb3de9..ffaac8915 100644 --- a/retroshare-gui/src/gui/feeds/SecurityIpItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityIpItem.h @@ -21,11 +21,12 @@ #ifndef _SECURITYIPITEM_H #define _SECURITYIPITEM_H -#include "retroshare/rstypes.h" - -#include "FeedItem.h" #include +#include "retroshare/rstypes.h" +#include "retroshare/rsevents.h" +#include "FeedItem.h" + namespace Ui { class SecurityIpItem; } @@ -44,6 +45,7 @@ public: void updateItemStatic(); uint64_t uniqueIdentifier() const override; + virtual ~SecurityIpItem(); protected: /* FeedItem */ @@ -60,12 +62,13 @@ private slots: void banIpListChanged(const QString &ipAddress); private: - RsFeedTypeFlags mType; + RsFeedTypeFlags mType; RsPeerId mSslId; std::string mIpAddr; std::string mIpAddrReported; uint32_t mResult; bool mIsTest; + RsEventsHandlerId_t mEventHandlerId; /** Qt Designer generated object */ Ui::SecurityIpItem *ui; diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.cpp b/retroshare-gui/src/gui/feeds/SecurityItem.cpp index bf9e0dce6..4d21440a4 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.cpp +++ b/retroshare-gui/src/gui/feeds/SecurityItem.cpp @@ -99,6 +99,7 @@ SecurityItem::~SecurityItem() { rsEvents->unregisterEventsHandler(mEventHandlerId); } + uint64_t SecurityItem::uniqueIdentifier() const { return hash_64bits("SecurityItem " + QString::number((uint)mType).toStdString() + " " + mSslId.toStdString()); @@ -303,10 +304,6 @@ void SecurityItem::updateItem() //quickmsgButton->show(); } - /* slow Tick */ - int msec_rate = 10129; - - QTimer::singleShot( msec_rate, this, SLOT(updateItem( void ) )); return; } diff --git a/retroshare-gui/src/gui/feeds/SecurityItem.h b/retroshare-gui/src/gui/feeds/SecurityItem.h index 03887c121..e2ba2b394 100644 --- a/retroshare-gui/src/gui/feeds/SecurityItem.h +++ b/retroshare-gui/src/gui/feeds/SecurityItem.h @@ -66,7 +66,7 @@ private: RsPeerId mSslId; std::string mSslCn; std::string mIP; - RsFeedTypeFlags mType; + RsFeedTypeFlags mType; bool mIsHome; RsEventsHandlerId_t mEventHandlerId;