Merge pull request #2765 from PYRET1C/new_token_service

[WIP] Added the new token service in this file
This commit is contained in:
csoler 2023-12-30 15:23:25 +01:00 committed by GitHub
commit 267ffc99af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 139 additions and 70 deletions

View File

@ -25,6 +25,7 @@
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/common/FilesDefs.h" #include "gui/common/FilesDefs.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "PulseAddDialog.h" #include "PulseAddDialog.h"
@ -98,11 +99,31 @@ void PulseAddDialog::setGroup(RsWireGroup &group)
// set ReplyWith Group. // set ReplyWith Group.
void PulseAddDialog::setGroup(const RsGxsGroupId &grpId) void PulseAddDialog::setGroup(const RsGxsGroupId &grpId)
{ {
/* fetch in the background */ if(grpId.isNull()){
RsWireGroupSPtr pGroup; return;
rsWire->getWireGroup(grpId, pGroup); }
setGroup(*pGroup); RsThread::async([this,grpId](){
RsWireGroupSPtr pGroup;
if(!rsWire->getWireGroup(grpId,pGroup))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve wire group info for wire id: " << grpId << std::endl;
return;
}
RsQThreadUtils::postToObject( [pGroup,this]()
{
/* 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!
*/
setGroup(*pGroup);
}, this );
});
} }
void PulseAddDialog::cleanup() void PulseAddDialog::cleanup()
@ -236,30 +257,46 @@ void PulseAddDialog::setReplyTo(const RsWirePulse &pulse, RsWirePulseSPtr pPulse
void PulseAddDialog::setReplyTo(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId, uint32_t replyType) void PulseAddDialog::setReplyTo(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId, uint32_t replyType)
{ {
if(grpId.isNull()){
return;
}
/* fetch in the background */ /* fetch in the background */
RsWireGroupSPtr pGroup;
if (!rsWire->getWireGroup(grpId, pGroup))
{
std::cerr << "PulseAddDialog::setRplyTo() failed to fetch group";
std::cerr << std::endl;
return;
}
RsWirePulseSPtr pPulse; RsThread::async([this,grpId,msgId,replyType](){
if (!rsWire->getWirePulse(grpId, msgId, pPulse))
{
std::cerr << "PulseAddDialog::setRplyTo() failed to fetch pulse";
std::cerr << std::endl;
return;
}
// update GroupPtr RsWireGroupSPtr pGroup;
// TODO - this should be handled in libretroshare if possible. RsWirePulseSPtr pPulse;
if (pPulse->mGroupPtr == NULL) { if(!rsWire->getWireGroup(grpId,pGroup))
pPulse->mGroupPtr = pGroup; {
} std::cerr << __PRETTY_FUNCTION__ << "PulseAddDialog::setRplyTo() failed to fetch group id: " << grpId << std::endl;
return;
}
if (!rsWire->getWirePulse(grpId, msgId, pPulse))
{
std::cerr << "PulseAddDialog::setRplyTo() failed to fetch pulse of group id: " << grpId << std::endl;
return;
}
// update GroupPtr
// TODO - this should be handled in libretroshare if possible.
if (pPulse->mGroupPtr == NULL) {
pPulse->mGroupPtr = pGroup;
}
RsQThreadUtils::postToObject( [pGroup,this,pPulse,replyType]()
{
/* 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!
*/
setReplyTo(*pPulse, pPulse, pGroup->mMeta.mGroupName, replyType);
}, this );
});
setReplyTo(*pPulse, pPulse, pGroup->mMeta.mGroupName, replyType);
} }
void PulseAddDialog::addURL() void PulseAddDialog::addURL()
@ -309,26 +346,39 @@ void PulseAddDialog::postOriginalPulse()
std::cerr << "PulseAddDialog::postOriginalPulse()"; std::cerr << "PulseAddDialog::postOriginalPulse()";
std::cerr << std::endl; std::cerr << std::endl;
RsWirePulseSPtr pPulse(new RsWirePulse()); RsWirePulseSPtr pPulse(new RsWirePulse());
pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT; pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString(); pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
// set images here too. // set images here too.
pPulse->mImage1 = mImage1; pPulse->mImage1 = mImage1;
pPulse->mImage2 = mImage2; pPulse->mImage2 = mImage2;
pPulse->mImage3 = mImage3; pPulse->mImage3 = mImage3;
pPulse->mImage4 = mImage4; pPulse->mImage4 = mImage4;
// this should be in async thread, so doesn't block UI thread. RsThread::async([this,pPulse](){
if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse))
{ if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse))
std::cerr << "PulseAddDialog::postOriginalPulse() FAILED"; {
std::cerr << std::endl; std::cerr << "PulseAddDialog::postOriginalPulse() FAILED";
return; std::cerr << std::endl;
} return;
}
RsQThreadUtils::postToObject( [this]()
{
/* 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!
*/
clearDialog();
hide();
}, this );
});
clearDialog();
hide();
} }
uint32_t PulseAddDialog::toPulseSentiment(int index) uint32_t PulseAddDialog::toPulseSentiment(int index)
@ -358,15 +408,15 @@ void PulseAddDialog::postReplyPulse()
std::cerr << "PulseAddDialog::postReplyPulse()"; std::cerr << "PulseAddDialog::postReplyPulse()";
std::cerr << std::endl; std::cerr << std::endl;
RsWirePulseSPtr pPulse(new RsWirePulse()); RsWirePulseSPtr pPulse(new RsWirePulse());
pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex()); pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString(); pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
// set images here too. // set images here too.
pPulse->mImage1 = mImage1; pPulse->mImage1 = mImage1;
pPulse->mImage2 = mImage2; pPulse->mImage2 = mImage2;
pPulse->mImage3 = mImage3; pPulse->mImage3 = mImage3;
pPulse->mImage4 = mImage4; pPulse->mImage4 = mImage4;
if (mReplyType & WIRE_PULSE_TYPE_REPUBLISH) { if (mReplyType & WIRE_PULSE_TYPE_REPUBLISH) {
// Copy details from parent, and override // Copy details from parent, and override
@ -380,20 +430,33 @@ void PulseAddDialog::postReplyPulse()
pPulse->mImage4 = mReplyToPulse.mImage4; pPulse->mImage4 = mReplyToPulse.mImage4;
} }
// this should be in async thread, so doesn't block UI thread. RsThread::async([this, pPulse](){
if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId,
mReplyToPulse.mMeta.mOrigMsgId, if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId,
mGroup.mMeta.mGroupId, mReplyToPulse.mMeta.mOrigMsgId,
mReplyType, mGroup.mMeta.mGroupId,
pPulse)) mReplyType,
{ pPulse))
std::cerr << "PulseAddDialog::postReplyPulse() FAILED"; {
std::cerr << std::endl; std::cerr << "PulseAddDialog::postReplyPulse() FAILED";
return; std::cerr << std::endl;
} return;
}
RsQThreadUtils::postToObject( [this]()
{
/* 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!
*/
clearDialog();
hide();
}, this );
});
clearDialog();
hide();
} }
void PulseAddDialog::clearDialog() void PulseAddDialog::clearDialog()

View File

@ -140,6 +140,7 @@ WireDialog::~WireDialog()
processSettings(false); processSettings(false);
clearTwitterView(); clearTwitterView();
std::cerr << "WireDialog::~WireDialog()" << std::endl;
delete(mWireQueue); delete(mWireQueue);
rsEvents->unregisterEventsHandler(mEventHandlerId); rsEvents->unregisterEventsHandler(mEventHandlerId);
@ -474,13 +475,13 @@ bool WireDialog::loadGroupData(const uint32_t &token)
std::cerr << "WireDialog::loadGroupData()"; std::cerr << "WireDialog::loadGroupData()";
std::cerr << std::endl; std::cerr << std::endl;
std::vector<RsWireGroup> groups; std::vector<RsWireGroup> groups;
rsWire->getGroupData(token, groups); rsWire->getGroupData(token, groups);
// save list of groups. // save list of groups.
updateGroups(groups); updateGroups(groups);
showGroups(); showGroups();
return true; return true;
} }
rstime_t WireDialog::getFilterTimestamp() rstime_t WireDialog::getFilterTimestamp()
@ -688,6 +689,7 @@ void WireDialog::PVHrate(const RsGxsId &authorId)
void WireDialog::postTestTwitterView() void WireDialog::postTestTwitterView()
{ {
clearTwitterView(); clearTwitterView();
std::cerr << "WireDialog::postTestTwitterView()" << std::endl;
addTwitterView(new PulseTopLevel(NULL,RsWirePulseSPtr())); addTwitterView(new PulseTopLevel(NULL,RsWirePulseSPtr()));
addTwitterView(new PulseReply(NULL,RsWirePulseSPtr())); addTwitterView(new PulseReply(NULL,RsWirePulseSPtr()));
@ -844,6 +846,7 @@ void WireDialog::requestPulseFocus(const RsGxsGroupId groupId, const RsGxsMessag
void WireDialog::showPulseFocus(const RsGxsGroupId groupId, const RsGxsMessageId msgId) void WireDialog::showPulseFocus(const RsGxsGroupId groupId, const RsGxsMessageId msgId)
{ {
clearTwitterView(); clearTwitterView();
std::cerr << "WireDialog::showPulseFocus()" << std::endl;
// background thread for loading. // background thread for loading.
RsThread::async([this, groupId, msgId]() RsThread::async([this, groupId, msgId]()
@ -873,6 +876,8 @@ void WireDialog::showPulseFocus(const RsGxsGroupId groupId, const RsGxsMessageId
void WireDialog::postPulseFocus(RsWirePulseSPtr pPulse) void WireDialog::postPulseFocus(RsWirePulseSPtr pPulse)
{ {
clearTwitterView(); clearTwitterView();
std::cerr << "WireDialog::postPulseFocus()" << std::endl;
if (!pPulse) if (!pPulse)
{ {
std::cerr << "WireDialog::postPulseFocus() Invalid pulse"; std::cerr << "WireDialog::postPulseFocus() Invalid pulse";
@ -945,7 +950,7 @@ void WireDialog::requestGroupFocus(const RsGxsGroupId groupId)
void WireDialog::showGroupFocus(const RsGxsGroupId groupId) void WireDialog::showGroupFocus(const RsGxsGroupId groupId)
{ {
clearTwitterView(); clearTwitterView();
std::cerr << "WireDialog::showGroupFocus()" << std::endl;
// background thread for loading. // background thread for loading.
RsThread::async([this, groupId]() RsThread::async([this, groupId]()
{ {
@ -1022,6 +1027,7 @@ void WireDialog::requestGroupsPulses(const std::list<RsGxsGroupId>& groupIds)
void WireDialog::showGroupsPulses(const std::list<RsGxsGroupId>& groupIds) void WireDialog::showGroupsPulses(const std::list<RsGxsGroupId>& groupIds)
{ {
clearTwitterView(); clearTwitterView();
std::cerr << "WireDialog::showGroupPulses()" << std::endl;
// background thread for loading. // background thread for loading.
RsThread::async([this, groupIds]() RsThread::async([this, groupIds]()

View File

@ -150,7 +150,7 @@ private:
// Loading Data. // Loading Data.
void requestGroupData(); void requestGroupData();
bool loadGroupData(const uint32_t &token); bool loadGroupData(const uint32_t &token);
void acknowledgeGroup(const uint32_t &token, const uint32_t &userType); void acknowledgeGroup(const uint32_t &token, const uint32_t &userType);
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) override; virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req) override;