Merge pull request #3072 from jolavillette/RemoveRecursiveSingleShotCalls
Some checks are pending
macOS Build / build (push) Waiting to run
MINGW64 Qt6 Build / build (push) Waiting to run
MINGW64 Qt5 Build / build (push) Waiting to run
UCRT64 Qt5 Build / build (push) Waiting to run
Ubuntu Qt 5 C/C++ CI / build (push) Waiting to run
Ubuntu Qt 6 C/C++ CI / build (push) Waiting to run

Remove recursive singleShot calls on feed items
This commit is contained in:
csoler 2025-12-22 13:12:18 +01:00 committed by GitHub
commit aa99fa9441
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 19 deletions

View file

@ -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<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
auto fe = dynamic_cast<const RsFriendListEvent*>(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;
}

View file

@ -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

View file

@ -34,6 +34,8 @@
#include <retroshare/rspeers.h>
#include <retroshare/rsbanlist.h>
#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<const RsEvent> e)
{
RsQThreadUtils::postToObject([=]()
{
// Filter events to only update relevant items.
auto fe = dynamic_cast<const RsFriendListEvent*>(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()

View file

@ -21,11 +21,12 @@
#ifndef _SECURITYIPITEM_H
#define _SECURITYIPITEM_H
#include "retroshare/rstypes.h"
#include "FeedItem.h"
#include <stdint.h>
#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;

View file

@ -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;
}

View file

@ -66,7 +66,7 @@ private:
RsPeerId mSslId;
std::string mSslCn;
std::string mIP;
RsFeedTypeFlags mType;
RsFeedTypeFlags mType;
bool mIsHome;
RsEventsHandlerId_t mEventHandlerId;