This is the gui part of the commit where the wire feed is refreshed if there is any event published.

This commit is contained in:
PYRET1C 2023-05-02 23:50:37 +05:30
parent b543281bb3
commit dbddf7166f
2 changed files with 43 additions and 2 deletions

View File

@ -59,7 +59,7 @@
WireDialog::WireDialog(QWidget *parent) WireDialog::WireDialog(QWidget *parent)
: MainPage(parent), mGroupSet(GROUP_SET_ALL) : MainPage(parent), mGroupSet(GROUP_SET_ALL)
, mAddDialog(nullptr), mGroupSelected(nullptr), mWireQueue(nullptr) , mAddDialog(nullptr), mGroupSelected(nullptr), mWireQueue(nullptr)
, mHistoryIndex(-1) , mHistoryIndex(-1), mEventHandlerId(0)
{ {
ui.setupUi(this); ui.setupUi(this);
@ -89,6 +89,42 @@ WireDialog::WireDialog(QWidget *parent)
// load settings // load settings
processSettings(true); processSettings(true);
// Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler(
[this](std::shared_ptr<const RsEvent> event)
{ RsQThreadUtils::postToObject([=]() { handleEvent_main_thread(event); }, this ); },
mEventHandlerId, RsEventType::WIRE );
}
void WireDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
const RsWireEvent *e = dynamic_cast<const RsWireEvent*>(event.get());
if(e)
switch(e->mWireEventCode)
{
case RsWireEventCode::NEW_POST: // [[fallthrough]];
refreshGroups();
break;
case RsWireEventCode::NEW_REPLY: // [[fallthrough]];
refreshGroups();
break;
case RsWireEventCode::NEW_LIKE: // [[fallthrough]];
refreshGroups();
break;
case RsWireEventCode::NEW_REPUBLISH: // [[fallthrough]];
refreshGroups();
break;
case RsWireEventCode::NEW_WIRE: // [[fallthrough]];
refreshGroups();
break;
case RsWireEventCode::FOLLOW_STATUS_CHANGED: // [[fallthrough]];
refreshGroups();
break;
default:
break;
}
} }
WireDialog::~WireDialog() WireDialog::~WireDialog()
@ -97,7 +133,9 @@ WireDialog::~WireDialog()
processSettings(false); processSettings(false);
clearTwitterView(); clearTwitterView();
delete(mWireQueue); delete(mWireQueue);
rsEvents->unregisterEventsHandler(mEventHandlerId);
} }
void WireDialog::processSettings(bool load) void WireDialog::processSettings(bool load)

View File

@ -164,6 +164,9 @@ private:
std::map<RsGxsGroupId, RsWireGroup> mAllGroups; std::map<RsGxsGroupId, RsWireGroup> mAllGroups;
std::vector<RsWireGroup> mOwnGroups; std::vector<RsWireGroup> mOwnGroups;
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
RsEventsHandlerId_t mEventHandlerId;
int32_t mHistoryIndex; int32_t mHistoryIndex;
std::vector<WireViewHistory> mHistory; std::vector<WireViewHistory> mHistory;