mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
Move createOriginalPulse / createReplyPulse to libretroshare
message creation logic moved to libretroshare GUI classes cleaned up.
This commit is contained in:
parent
11ce959b2f
commit
8df5a886db
@ -144,7 +144,7 @@ class RsWirePulse
|
||||
std::string mPulseText;
|
||||
|
||||
uint32_t mPulseType;
|
||||
uint32_t mReplySentiment; // only relevant if a reply.
|
||||
uint32_t mSentiment; // sentiment can be asserted at any point.
|
||||
|
||||
// These Ref to the related (parent or reply) if reply (RESPONSE set)
|
||||
// Mode RESPONSE REFERENCE
|
||||
@ -222,13 +222,15 @@ virtual bool getGroups(const std::list<RsGxsGroupId> grpIds,
|
||||
// New Blocking Interfaces.
|
||||
// Plan to migrate all GUI calls to these, and remove old interfaces above.
|
||||
// These are not single requests, but return data graphs for display.
|
||||
virtual bool createOriginalPulse(RsGxsGroupId grpId, std::string msg) = 0;
|
||||
virtual bool createOriginalPulse(const RsGxsGroupId &grpId, RsWirePulseSPtr pPulse) = 0;
|
||||
virtual bool createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId,
|
||||
RsGxsGroupId replyWith, uint32_t reply_type,
|
||||
uint32_t sentiment, std::string msg) = 0;
|
||||
RsWirePulseSPtr pPulse) = 0;
|
||||
|
||||
// Provide Group Details for display.
|
||||
|
||||
// Provide Individual Group Details for display.
|
||||
virtual bool getWireGroup(const RsGxsGroupId &groupId, RsWireGroupSPtr &grp) = 0;
|
||||
virtual bool getWirePulse(const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, RsWirePulseSPtr &pPulse) = 0;
|
||||
|
||||
// Provide list of pulses associated with groups.
|
||||
virtual bool getPulsesForGroups(const std::list<RsGxsGroupId> &groupIds,
|
||||
|
@ -61,7 +61,7 @@ void RsGxsWirePulseItem::clear()
|
||||
{
|
||||
pulse.mPulseText.clear();
|
||||
pulse.mPulseType = 0;
|
||||
pulse.mReplySentiment = 0;
|
||||
pulse.mSentiment = 0;
|
||||
pulse.mRefGroupId.clear();
|
||||
pulse.mRefGroupName.clear();
|
||||
pulse.mRefOrigMsgId.clear();
|
||||
@ -81,7 +81,7 @@ void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_PARAM,pulse.mPulseType,"pulse.mPulseType") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_PARAM,pulse.mReplySentiment,"pulse.mReplySentiment") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_PARAM,pulse.mSentiment,"pulse.mSentiment") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pulse.mRefGroupId,"pulse.mRefGroupId") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,pulse.mRefGroupName,"pulse.mRefGroupName") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,pulse.mRefOrigMsgId,"pulse.mRefOrigMsgId") ;
|
||||
|
@ -447,6 +447,10 @@ bool p3Wire::fetchPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsWirePulseSPt
|
||||
pPulse = std::make_shared<RsWirePulse>(pulses[0]);
|
||||
std::cerr << "p3Wire::fetchPulse() retrieved token: " << *pPulse;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3Wire::fetchPulse() ANS GrpId: " << pPulse->mMeta.mGroupId;
|
||||
std::cerr << " MsgId: " << pPulse->mMeta.mMsgId;
|
||||
std::cerr << " OrigMsgId: " << pPulse->mMeta.mOrigMsgId;
|
||||
std::cerr << std::endl;
|
||||
} else {
|
||||
std::cerr << "p3Wire::fetchPulse() ERROR multiple pulses";
|
||||
std::cerr << std::endl;
|
||||
@ -469,8 +473,7 @@ bool p3Wire::fetchPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsWirePulseSPt
|
||||
}
|
||||
|
||||
// New Interfaces.
|
||||
// TODO: createOriginalPulse has not been tested.
|
||||
bool p3Wire::createOriginalPulse(RsGxsGroupId grpId, std::string msg)
|
||||
bool p3Wire::createOriginalPulse(const RsGxsGroupId &grpId, RsWirePulseSPtr pPulse)
|
||||
{
|
||||
// request Group.
|
||||
std::list<RsGxsGroupId> groupIds = { grpId };
|
||||
@ -499,6 +502,7 @@ bool p3Wire::createOriginalPulse(RsGxsGroupId grpId, std::string msg)
|
||||
}
|
||||
|
||||
// Create Msg.
|
||||
// Start fresh, just to be sure nothing dodgy happens in UX world.
|
||||
RsWirePulse pulse;
|
||||
|
||||
pulse.mMeta.mGroupId = group.mMeta.mGroupId;
|
||||
@ -507,9 +511,14 @@ bool p3Wire::createOriginalPulse(RsGxsGroupId grpId, std::string msg)
|
||||
pulse.mMeta.mParentId.clear();
|
||||
pulse.mMeta.mOrigMsgId.clear();
|
||||
|
||||
// copy info over
|
||||
pulse.mPulseType = WIRE_PULSE_TYPE_ORIGINAL;
|
||||
pulse.mReplySentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
|
||||
pulse.mPulseText = msg;
|
||||
pulse.mSentiment = pPulse->mSentiment;
|
||||
pulse.mPulseText = pPulse->mPulseText;
|
||||
pulse.mImage1 = pPulse->mImage1;
|
||||
pulse.mImage2 = pPulse->mImage2;
|
||||
pulse.mImage3 = pPulse->mImage3;
|
||||
pulse.mImage4 = pPulse->mImage4;
|
||||
|
||||
// all mRefs should empty.
|
||||
|
||||
@ -527,8 +536,7 @@ bool p3Wire::createOriginalPulse(RsGxsGroupId grpId, std::string msg)
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: createReplyPulse has not been tested.
|
||||
bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGroupId replyWith, uint32_t reply_type, uint32_t /*sentiment*/, std::string msg)
|
||||
bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGroupId replyWith, uint32_t reply_type, RsWirePulseSPtr pPulse)
|
||||
{
|
||||
// check reply_type. can only be ONE.
|
||||
if (!((reply_type == WIRE_PULSE_TYPE_REPLY) ||
|
||||
@ -550,16 +558,29 @@ bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGro
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract group info.
|
||||
RsWireGroup replyToGroup;
|
||||
RsWireGroup replyWithGroup;
|
||||
|
||||
if (grpId == replyWith)
|
||||
{
|
||||
if (groups.size() != 1) {
|
||||
std::cerr << "p3Wire::createReplyPulse() getGroups != 1";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
replyToGroup = groups[0];
|
||||
replyWithGroup = groups[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (groups.size() != 2) {
|
||||
std::cerr << "p3Wire::createReplyPulse() getGroups != 2";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// extract group info.
|
||||
RsWireGroup replyToGroup;
|
||||
RsWireGroup replyWithGroup;
|
||||
|
||||
if (groups[0].mMeta.mGroupId == grpId) {
|
||||
replyToGroup = groups[0];
|
||||
replyWithGroup = groups[1];
|
||||
@ -567,9 +588,11 @@ bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGro
|
||||
replyToGroup = groups[1];
|
||||
replyWithGroup = groups[0];
|
||||
}
|
||||
}
|
||||
|
||||
// check groupIds match
|
||||
if ((replyToGroup.mMeta.mGroupId != grpId) ||
|
||||
(replyToGroup.mMeta.mGroupId != replyWith))
|
||||
(replyWithGroup.mMeta.mGroupId != replyWith))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() groupid mismatch";
|
||||
std::cerr << std::endl;
|
||||
@ -604,8 +627,8 @@ bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGro
|
||||
responsePulse.mMeta.mOrigMsgId.clear();
|
||||
|
||||
responsePulse.mPulseType = WIRE_PULSE_TYPE_RESPONSE | reply_type;
|
||||
responsePulse.mReplySentiment = 0; // toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
||||
responsePulse.mPulseText = msg; // ui.textEdit_Pulse->toPlainText().toStdString();
|
||||
responsePulse.mSentiment = pPulse->mSentiment;
|
||||
responsePulse.mPulseText = pPulse->mPulseText;
|
||||
|
||||
// mRefs refer to parent post.
|
||||
responsePulse.mRefGroupId = replyToPulse->mMeta.mGroupId;
|
||||
@ -615,13 +638,59 @@ bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGro
|
||||
responsePulse.mRefPublishTs = replyToPulse->mMeta.mPublishTs;
|
||||
responsePulse.mRefPulseText = replyToPulse->mPulseText;
|
||||
|
||||
std::cerr << "p3Wire::createReplyPulse() create Response Pulse";
|
||||
std::cerr << std::endl;
|
||||
|
||||
uint32_t token;
|
||||
createPulse(token, responsePulse);
|
||||
if (!createPulse(token, responsePulse))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() FAILED to create Response Pulse";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = waitToken(token);
|
||||
if (result != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() FAILED(2) to create Response Pulse";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// get MsgId.
|
||||
std::pair<RsGxsGroupId, RsGxsMessageId> responsePair;
|
||||
if (!acknowledgeMsg(token, responsePair))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() FAILED acknowledgeMsg for Response Pulse";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// update responsePulse.
|
||||
// TODO.
|
||||
std::cerr << "p3Wire::createReplyPulse() Response Pulse ID: (";
|
||||
std::cerr << responsePair.first.toStdString() << ", ";
|
||||
std::cerr << responsePair.second.toStdString() << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// retrieve newly generated message.
|
||||
// **********************************************************
|
||||
RsWirePulseSPtr createdResponsePulse;
|
||||
if (!fetchPulse(responsePair.first, responsePair.second, createdResponsePulse))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() fetch createdReponsePulse FAILED";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check that pulses is created properly */
|
||||
if ((createdResponsePulse->mMeta.mGroupId != responsePulse.mMeta.mGroupId) ||
|
||||
(createdResponsePulse->mPulseText != responsePulse.mPulseText) ||
|
||||
(createdResponsePulse->mRefGroupId != responsePulse.mRefGroupId) ||
|
||||
(createdResponsePulse->mRefOrigMsgId != responsePulse.mRefOrigMsgId))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() fetch createdReponsePulse FAILED";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// create ReplyTo Ref Msg.
|
||||
std::cerr << "PulseAddDialog::postRefPulse() create Reference!";
|
||||
@ -637,7 +706,7 @@ bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGro
|
||||
refPulse.mMeta.mOrigMsgId.clear();
|
||||
|
||||
refPulse.mPulseType = WIRE_PULSE_TYPE_REFERENCE | reply_type;
|
||||
refPulse.mReplySentiment = 0; //toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
||||
refPulse.mSentiment = 0; // should this be =? createdResponsePulse->mSentiment;
|
||||
|
||||
// Dont put parent PulseText into refPulse - it is available on Thread Msg.
|
||||
// otherwise gives impression it is correctly setup Parent / Reply...
|
||||
@ -647,15 +716,41 @@ bool p3Wire::createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId, RsGxsGro
|
||||
// refs refer back to own Post.
|
||||
refPulse.mRefGroupId = replyWithGroup.mMeta.mGroupId;
|
||||
refPulse.mRefGroupName = replyWithGroup.mMeta.mGroupName;
|
||||
refPulse.mRefOrigMsgId = responsePulse.mMeta.mOrigMsgId;
|
||||
refPulse.mRefOrigMsgId = createdResponsePulse->mMeta.mOrigMsgId;
|
||||
refPulse.mRefAuthorId = replyWithGroup.mMeta.mAuthorId;
|
||||
refPulse.mRefPublishTs = responsePulse.mMeta.mPublishTs;
|
||||
refPulse.mRefPulseText = responsePulse.mPulseText;
|
||||
|
||||
// uint32_t token;
|
||||
rsWire->createPulse(token, refPulse);
|
||||
refPulse.mRefPublishTs = createdResponsePulse->mMeta.mPublishTs;
|
||||
refPulse.mRefPulseText = createdResponsePulse->mPulseText;
|
||||
|
||||
// publish Ref Msg.
|
||||
if (!createPulse(token, refPulse))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() FAILED to create Ref Pulse";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = waitToken(token);
|
||||
if (result != RsTokenService::COMPLETE)
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() FAILED(2) to create Ref Pulse";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// get MsgId.
|
||||
std::pair<RsGxsGroupId, RsGxsMessageId> refPair;
|
||||
if (!acknowledgeMsg(token, refPair))
|
||||
{
|
||||
std::cerr << "p3Wire::createReplyPulse() FAILED acknowledgeMsg for Ref Pulse";
|
||||
std::cerr << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cerr << "p3Wire::createReplyPulse() Success: Ref Pulse ID: (";
|
||||
std::cerr << refPair.first.toStdString() << ", ";
|
||||
std::cerr << refPair.second.toStdString() << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -706,6 +801,15 @@ bool p3Wire::getWireGroup(const RsGxsGroupId &groupId, RsWireGroupSPtr &grp)
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO Remove duplicate ...
|
||||
bool p3Wire::getWirePulse(const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, RsWirePulseSPtr &pPulse)
|
||||
{
|
||||
return fetchPulse(groupId, msgId, pPulse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool compare_time(const RsWirePulseSPtr& first, const RsWirePulseSPtr &second)
|
||||
{
|
||||
return first->mMeta.mPublishTs > second->mMeta.mPublishTs;
|
||||
|
@ -63,10 +63,10 @@ public:
|
||||
|
||||
// New Interfaces.
|
||||
// Blocking, request structures for display.
|
||||
virtual bool createOriginalPulse(RsGxsGroupId grpId, std::string msg) override;
|
||||
virtual bool createOriginalPulse(const RsGxsGroupId &grpId, RsWirePulseSPtr pPulse) override;
|
||||
virtual bool createReplyPulse(RsGxsGroupId grpId, RsGxsMessageId msgId,
|
||||
RsGxsGroupId replyWith, uint32_t reply_type,
|
||||
uint32_t sentiment, std::string msg) override;
|
||||
RsWirePulseSPtr pPulse) override;
|
||||
|
||||
#if 0
|
||||
virtual bool createReplyPulse(uint32_t &token, RsWirePulse &pulse) override;
|
||||
@ -75,6 +75,7 @@ public:
|
||||
#endif
|
||||
|
||||
virtual bool getWireGroup(const RsGxsGroupId &groupId, RsWireGroupSPtr &grp) override;
|
||||
virtual bool getWirePulse(const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, RsWirePulseSPtr &pPulse) override;
|
||||
|
||||
virtual bool getPulsesForGroups(const std::list<RsGxsGroupId> &groupIds, std::list<RsWirePulseSPtr> &pulsePtrs) override;
|
||||
|
||||
|
@ -28,12 +28,10 @@ const uint32_t PULSE_MAX_SIZE = 1000; // 1k char.
|
||||
|
||||
/** Constructor */
|
||||
PulseAddDialog::PulseAddDialog(QWidget *parent)
|
||||
: QWidget(parent), mIsReply(false), mWaitingRefMsg(false)
|
||||
: QWidget(parent), mIsReply(false)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
mWireQueue = new TokenQueue(rsWire->getTokenService(), this);
|
||||
|
||||
connect(ui.pushButton_Post, SIGNAL( clicked( void ) ), this, SLOT( postPulse( void ) ) );
|
||||
connect(ui.pushButton_AddURL, SIGNAL( clicked( void ) ), this, SLOT( addURL( void ) ) );
|
||||
connect(ui.pushButton_ClearDisplayAs, SIGNAL( clicked( void ) ), this, SLOT( clearDisplayAs( void ) ) );
|
||||
@ -48,12 +46,21 @@ void PulseAddDialog::setGroup(RsWireGroup &group)
|
||||
mGroup = group;
|
||||
}
|
||||
|
||||
// set ReplyWith Group.
|
||||
void PulseAddDialog::setGroup(const RsGxsGroupId &grpId)
|
||||
{
|
||||
/* fetch in the background */
|
||||
RsWireGroupSPtr pGroup;
|
||||
rsWire->getWireGroup(grpId, pGroup);
|
||||
|
||||
setGroup(*pGroup);
|
||||
}
|
||||
|
||||
void PulseAddDialog::cleanup()
|
||||
{
|
||||
if (mIsReply)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::setReplyTo() cleaning up old replyto";
|
||||
std::cerr << "PulseAddDialog::cleanup() cleaning up old replyto";
|
||||
std::cerr << std::endl;
|
||||
QLayout *layout = ui.widget_replyto->layout();
|
||||
// completely delete layout and sublayouts
|
||||
@ -63,14 +70,14 @@ void PulseAddDialog::cleanup()
|
||||
{
|
||||
if ((widget = item->widget()) != 0)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::setReplyTo() removing widget";
|
||||
std::cerr << "PulseAddDialog::cleanup() removing widget";
|
||||
std::cerr << std::endl;
|
||||
widget->hide();
|
||||
delete widget;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "PulseAddDialog::setReplyTo() removing item";
|
||||
std::cerr << "PulseAddDialog::cleanup() removing item";
|
||||
std::cerr << std::endl;
|
||||
delete item;
|
||||
}
|
||||
@ -96,11 +103,11 @@ void PulseAddDialog::pulseTextChanged()
|
||||
ui.pushButton_Post->setEnabled(enable);
|
||||
}
|
||||
|
||||
// Old Interface, deprecate / make internal.
|
||||
void PulseAddDialog::setReplyTo(RsWirePulse &pulse, std::string &groupName)
|
||||
{
|
||||
mIsReply = true;
|
||||
mReplyToPulse = pulse;
|
||||
mReplyGroupName = groupName;
|
||||
ui.frame_reply->setVisible(true);
|
||||
|
||||
{
|
||||
@ -116,6 +123,27 @@ void PulseAddDialog::setReplyTo(RsWirePulse &pulse, std::string &groupName)
|
||||
}
|
||||
}
|
||||
|
||||
void PulseAddDialog::setReplyTo(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId)
|
||||
{
|
||||
/* 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;
|
||||
if (!rsWire->getWirePulse(grpId, msgId, pPulse))
|
||||
{
|
||||
std::cerr << "PulseAddDialog::setRplyTo() failed to fetch pulse";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
setReplyTo(*pPulse, pGroup->mMeta.mGroupName);
|
||||
}
|
||||
|
||||
void PulseAddDialog::addURL()
|
||||
{
|
||||
@ -164,21 +192,19 @@ void PulseAddDialog::postOriginalPulse()
|
||||
std::cerr << "PulseAddDialog::postOriginalPulse()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsWirePulse pulse;
|
||||
RsWirePulseSPtr pPulse(new RsWirePulse());
|
||||
|
||||
pulse.mMeta.mGroupId = mGroup.mMeta.mGroupId;
|
||||
pulse.mMeta.mAuthorId = mGroup.mMeta.mAuthorId;
|
||||
pulse.mMeta.mThreadId.clear();
|
||||
pulse.mMeta.mParentId.clear();
|
||||
pulse.mMeta.mOrigMsgId.clear();
|
||||
pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
|
||||
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
||||
// set images here too.
|
||||
|
||||
pulse.mPulseType = WIRE_PULSE_TYPE_ORIGINAL;
|
||||
pulse.mReplySentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
|
||||
pulse.mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
||||
// all mRefs should empty.
|
||||
|
||||
uint32_t token;
|
||||
rsWire->createPulse(token, pulse);
|
||||
// this should be in async thread, so doesn't block UI thread.
|
||||
if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse))
|
||||
{
|
||||
std::cerr << "PulseAddDialog::postOriginalPulse() FAILED";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
clearDialog();
|
||||
hide();
|
||||
@ -211,67 +237,23 @@ void PulseAddDialog::postReplyPulse()
|
||||
std::cerr << "PulseAddDialog::postReplyPulse()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsWirePulse pulse;
|
||||
RsWirePulseSPtr pPulse(new RsWirePulse());
|
||||
|
||||
pulse.mMeta.mGroupId = mGroup.mMeta.mGroupId;
|
||||
pulse.mMeta.mAuthorId = mGroup.mMeta.mAuthorId;
|
||||
pulse.mMeta.mThreadId.clear();
|
||||
pulse.mMeta.mParentId.clear();
|
||||
pulse.mMeta.mOrigMsgId.clear();
|
||||
pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
||||
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
||||
// set images too.
|
||||
|
||||
pulse.mPulseType = WIRE_PULSE_TYPE_RESPONSE | WIRE_PULSE_TYPE_REPLY;
|
||||
pulse.mReplySentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
||||
pulse.mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
||||
|
||||
// mRefs refer to parent post.
|
||||
pulse.mRefGroupId = mReplyToPulse.mMeta.mGroupId;
|
||||
pulse.mRefGroupName = mReplyGroupName;
|
||||
pulse.mRefOrigMsgId = mReplyToPulse.mMeta.mOrigMsgId;
|
||||
pulse.mRefAuthorId = mReplyToPulse.mMeta.mAuthorId;
|
||||
pulse.mRefPublishTs = mReplyToPulse.mMeta.mPublishTs;
|
||||
pulse.mRefPulseText = mReplyToPulse.mPulseText;
|
||||
|
||||
// Need Pulse MsgID before we can create associated Reference.
|
||||
mWaitingRefMsg = true;
|
||||
|
||||
uint32_t token;
|
||||
rsWire->createPulse(token, pulse);
|
||||
mWireQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, 0);
|
||||
}
|
||||
|
||||
|
||||
void PulseAddDialog::postRefPulse(RsWirePulse &pulse)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::postRefPulse() create Reference!";
|
||||
// this should be in async thread, so doesn't block UI thread.
|
||||
if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId,
|
||||
mReplyToPulse.mMeta.mOrigMsgId,
|
||||
mGroup.mMeta.mGroupId,
|
||||
WIRE_PULSE_TYPE_REPLY,
|
||||
pPulse))
|
||||
{
|
||||
std::cerr << "PulseAddDialog::postReplyPulse() FAILED";
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Reference Pulse. posted on Parent's Group.
|
||||
RsWirePulse refPulse;
|
||||
|
||||
refPulse.mMeta.mGroupId = mReplyToPulse.mMeta.mGroupId;
|
||||
refPulse.mMeta.mAuthorId = mGroup.mMeta.mAuthorId; // own author Id.
|
||||
refPulse.mMeta.mThreadId = mReplyToPulse.mMeta.mOrigMsgId;
|
||||
refPulse.mMeta.mParentId = mReplyToPulse.mMeta.mOrigMsgId;
|
||||
refPulse.mMeta.mOrigMsgId.clear();
|
||||
|
||||
refPulse.mPulseType = WIRE_PULSE_TYPE_REFERENCE | WIRE_PULSE_TYPE_REPLY;
|
||||
refPulse.mReplySentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
||||
|
||||
// Dont put parent PulseText into refPulse - it is available on Thread Msg.
|
||||
// otherwise gives impression it is correctly setup Parent / Reply...
|
||||
// when in fact the parent PublishTS, and AuthorId are wrong.
|
||||
refPulse.mPulseText = "";
|
||||
|
||||
// refs refer back to own Post.
|
||||
refPulse.mRefGroupId = mGroup.mMeta.mGroupId;
|
||||
refPulse.mRefGroupName = mGroup.mMeta.mGroupName;
|
||||
refPulse.mRefOrigMsgId = pulse.mMeta.mOrigMsgId;
|
||||
refPulse.mRefAuthorId = mGroup.mMeta.mAuthorId;
|
||||
refPulse.mRefPublishTs = pulse.mMeta.mPublishTs;
|
||||
refPulse.mRefPulseText = pulse.mPulseText;
|
||||
|
||||
uint32_t token;
|
||||
rsWire->createPulse(token, refPulse);
|
||||
return;
|
||||
}
|
||||
|
||||
clearDialog();
|
||||
hide();
|
||||
@ -283,89 +265,4 @@ void PulseAddDialog::clearDialog()
|
||||
}
|
||||
|
||||
|
||||
void PulseAddDialog::acknowledgeMessage(const uint32_t &token)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::acknowledgeMessage()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::pair<RsGxsGroupId, RsGxsMessageId> p;
|
||||
rsWire->acknowledgeMsg(token, p);
|
||||
|
||||
if (mWaitingRefMsg)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::acknowledgeMessage() Waiting Ref Msg";
|
||||
std::cerr << std::endl;
|
||||
mWaitingRefMsg = false;
|
||||
|
||||
// request photo data.
|
||||
GxsMsgReq req;
|
||||
std::set<RsGxsMessageId> msgIds;
|
||||
msgIds.insert(p.second);
|
||||
req[p.first] = msgIds;
|
||||
|
||||
RsTokReqOptions opts;
|
||||
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
||||
uint32_t token;
|
||||
mWireQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, req, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "PulseAddDialog::acknowledgeMessage() Not Waiting Ref Msg";
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void PulseAddDialog::loadPulseData(const uint32_t &token)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::loadPulseData()";
|
||||
std::cerr << std::endl;
|
||||
std::vector<RsWirePulse> pulses;
|
||||
rsWire->getPulseData(token, pulses);
|
||||
|
||||
if (pulses.size() != 1)
|
||||
{
|
||||
std::cerr << "PulseAddDialog::loadPulseData() Error Too many pulses";
|
||||
std::cerr << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cerr << "PulseAddDialog::loadPulseData() calling postRefMsg";
|
||||
std::cerr << std::endl;
|
||||
|
||||
RsWirePulse& pulse = pulses[0];
|
||||
postRefPulse(pulse);
|
||||
}
|
||||
|
||||
|
||||
/**************************** Request / Response Filling of Data ************************/
|
||||
|
||||
void PulseAddDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
|
||||
{
|
||||
if (queue == mWireQueue)
|
||||
{
|
||||
/* now switch on req */
|
||||
switch(req.mType)
|
||||
{
|
||||
case TOKENREQ_MSGINFO:
|
||||
switch(req.mAnsType)
|
||||
{
|
||||
case RS_TOKREQ_ANSTYPE_ACK:
|
||||
acknowledgeMessage(req.mToken);
|
||||
break;
|
||||
case RS_TOKREQ_ANSTYPE_DATA:
|
||||
loadPulseData(req.mToken);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "PulseAddDialog::loadRequest() ERROR: MSG: INVALID ANS TYPE";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
std::cerr << "PulseAddDialog::loadRequest() ERROR: INVALID TYPE";
|
||||
std::cerr << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,8 @@
|
||||
#include "ui_PulseAddDialog.h"
|
||||
|
||||
#include <retroshare/rswire.h>
|
||||
#include "util/TokenQueue.h"
|
||||
|
||||
class PulseAddDialog : public QWidget, public TokenResponse
|
||||
class PulseAddDialog : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -34,8 +33,9 @@ public:
|
||||
PulseAddDialog(QWidget *parent = 0);
|
||||
|
||||
void cleanup();
|
||||
void setGroup(RsWireGroup &group);
|
||||
void setReplyTo(RsWirePulse &pulse, std::string &groupName);
|
||||
|
||||
void setReplyTo(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId);
|
||||
void setGroup(const RsGxsGroupId &grpId);
|
||||
|
||||
private slots:
|
||||
void addURL();
|
||||
@ -46,26 +46,23 @@ private slots:
|
||||
void pulseTextChanged();
|
||||
|
||||
private:
|
||||
// OLD VERSIONs, private now.
|
||||
void setGroup(RsWireGroup &group);
|
||||
void setReplyTo(RsWirePulse &pulse, std::string &groupName);
|
||||
|
||||
void postOriginalPulse();
|
||||
void postReplyPulse();
|
||||
void postRefPulse(RsWirePulse &pulse);
|
||||
|
||||
void acknowledgeMessage(const uint32_t &token);
|
||||
void loadPulseData(const uint32_t &token);
|
||||
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
|
||||
uint32_t toPulseSentiment(int index);
|
||||
|
||||
protected:
|
||||
|
||||
RsWireGroup mGroup; // where we want to post from.
|
||||
RsWireGroup mGroup; // replyWith.
|
||||
|
||||
// if this is a reply
|
||||
bool mIsReply;
|
||||
std::string mReplyGroupName;
|
||||
RsWirePulse mReplyToPulse;
|
||||
bool mWaitingRefMsg;
|
||||
|
||||
TokenQueue* mWireQueue;
|
||||
Ui::PulseAddDialog ui;
|
||||
|
||||
};
|
||||
|
@ -56,6 +56,7 @@ PulseDetails::PulseDetails(PulseHolder *actions,
|
||||
// reuse Meta data structure.
|
||||
mPulse.mMeta.mGroupId = parentGroupId;
|
||||
mPulse.mMeta.mOrigMsgId = parentOrigMsgId;
|
||||
mPulse.mMeta.mMsgId = parentOrigMsgId; // add in, for completeness.
|
||||
mPulse.mMeta.mAuthorId = parentAuthorId;
|
||||
mPulse.mMeta.mPublishTs = parentPublishTs;
|
||||
mPulse.mPulseText = parentPulseText;
|
||||
|
@ -136,7 +136,9 @@ void WireDialog::reply(RsWirePulse &pulse, std::string &groupName)
|
||||
{
|
||||
std::cerr << "WireDialog::reply(";
|
||||
std::cerr << pulse.mMeta.mGroupId.toStdString();
|
||||
std::cerr << ",";
|
||||
std::cerr << ", MsgId:";
|
||||
std::cerr << pulse.mMeta.mMsgId.toStdString();
|
||||
std::cerr << ", OrigMsgId:";
|
||||
std::cerr << pulse.mMeta.mOrigMsgId.toStdString();
|
||||
std::cerr << ")";
|
||||
std::cerr << std::endl;
|
||||
@ -159,10 +161,11 @@ void WireDialog::reply(RsWirePulse &pulse, std::string &groupName)
|
||||
// publishing group.
|
||||
RsWireGroup group = mOwnGroups[idx];
|
||||
mAddDialog->cleanup();
|
||||
mAddDialog->setGroup(group);
|
||||
mAddDialog->setGroup(group.mMeta.mGroupId);
|
||||
|
||||
// establish replyTo.
|
||||
mAddDialog->setReplyTo(pulse, groupName);
|
||||
//mAddDialog->setReplyTo(pulse, groupName);
|
||||
mAddDialog->setReplyTo(pulse.mMeta.mGroupId, pulse.mMeta.mMsgId);
|
||||
|
||||
mAddDialog->show();
|
||||
}
|
||||
@ -269,7 +272,7 @@ void WireDialog::createPulse()
|
||||
RsWireGroup group = mOwnGroups[idx];
|
||||
|
||||
mAddDialog->cleanup();
|
||||
mAddDialog->setGroup(group);
|
||||
mAddDialog->setGroup(group.mMeta.mGroupId);
|
||||
mAddDialog->show();
|
||||
}
|
||||
|
||||
@ -440,6 +443,9 @@ void WireDialog::showSelectedGroups()
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
grpIds.push_back(mGroupSelected->groupId());
|
||||
requestPulseData(grpIds);
|
||||
|
||||
// show GroupFocus.
|
||||
showGroupFocus(mGroupSelected->groupId());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -454,6 +460,7 @@ void WireDialog::showGroups()
|
||||
deletePulses();
|
||||
|
||||
|
||||
std::list<RsGxsGroupId> allGroupIds;
|
||||
|
||||
/* depends on the comboBox */
|
||||
std::map<RsGxsGroupId, RsWireGroup>::const_iterator it;
|
||||
@ -481,9 +488,12 @@ void WireDialog::showGroups()
|
||||
// request data.
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
grpIds.push_back(it->second.mMeta.mGroupId);
|
||||
allGroupIds.push_back(it->second.mMeta.mGroupId);
|
||||
requestPulseData(grpIds);
|
||||
}
|
||||
}
|
||||
|
||||
showGroupsPulses(allGroupIds);
|
||||
}
|
||||
|
||||
|
||||
@ -1015,6 +1025,8 @@ void WireDialog::postPulseFocus(RsWirePulseSPtr pPulse)
|
||||
return;
|
||||
}
|
||||
|
||||
ui.label_viewMode->setText("Pulse Focus");
|
||||
|
||||
addTwitterView(new PulseTopLevel(this, pPulse));
|
||||
|
||||
std::list<RsWirePulseSPtr>::iterator it;
|
||||
@ -1089,6 +1101,8 @@ void WireDialog::postGroupFocus(RsWireGroupSPtr group, std::list<RsWirePulseSPtr
|
||||
return;
|
||||
}
|
||||
|
||||
ui.label_viewMode->setText("Group Focus");
|
||||
|
||||
addTwitterView(new PulseViewGroup(this, group));
|
||||
|
||||
std::list<RsWirePulseSPtr>::iterator it;
|
||||
@ -1104,5 +1118,49 @@ void WireDialog::postGroupFocus(RsWireGroupSPtr group, std::list<RsWirePulseSPtr
|
||||
}
|
||||
}
|
||||
|
||||
void WireDialog::showGroupsPulses(const std::list<RsGxsGroupId> groupIds)
|
||||
{
|
||||
clearTwitterView();
|
||||
|
||||
// background thread for loading.
|
||||
RsThread::async([this, groupIds]()
|
||||
{
|
||||
// fetch data from backend.
|
||||
std::list<RsWirePulseSPtr> pulses;
|
||||
bool success = rsWire->getPulsesForGroups(groupIds, pulses);
|
||||
|
||||
sleep(2);
|
||||
|
||||
/* now insert the pulse + children into the layput */
|
||||
RsQThreadUtils::postToObject([pulses,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 */
|
||||
|
||||
postGroupsPulses(pulses);
|
||||
|
||||
}, this);
|
||||
});
|
||||
}
|
||||
|
||||
void WireDialog::postGroupsPulses(std::list<RsWirePulseSPtr> pulses)
|
||||
{
|
||||
std::cerr << "WireDialog::postGroupsPulses()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
ui.label_viewMode->setText("Groups Pulses");
|
||||
|
||||
std::list<RsWirePulseSPtr>::iterator it;
|
||||
for(it = pulses.begin(); it != pulses.end(); it++)
|
||||
{
|
||||
RsWirePulseSPtr reply = *it;
|
||||
PulseReply *firstReply = new PulseReply(this, reply);
|
||||
addTwitterView(firstReply);
|
||||
firstReply->showReplyLine(false);
|
||||
|
||||
addTwitterView(new PulseReplySeperator());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,12 +83,16 @@ public:
|
||||
void postTestTwitterView();
|
||||
void clearTwitterView();
|
||||
void addTwitterView(PulseViewItem *item);
|
||||
|
||||
void showPulseFocus(const RsGxsGroupId groupId, const RsGxsMessageId msgId);
|
||||
void postPulseFocus(RsWirePulseSPtr pulse);
|
||||
|
||||
void showGroupFocus(const RsGxsGroupId groupId);
|
||||
void postGroupFocus(RsWireGroupSPtr group, std::list<RsWirePulseSPtr> pulses);
|
||||
|
||||
void showGroupsPulses(const std::list<RsGxsGroupId> groupIds);
|
||||
void postGroupsPulses(std::list<RsWirePulseSPtr> pulses);
|
||||
|
||||
private slots:
|
||||
|
||||
void createGroup();
|
||||
|
@ -192,7 +192,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>228</width>
|
||||
<height>421</height>
|
||||
<height>442</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
@ -223,9 +223,9 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabWidget_Page1" native="true">
|
||||
<widget class="QWidget" name="tabWidget_Page1">
|
||||
<attribute name="title">
|
||||
<string>Orig View</string>
|
||||
</attribute>
|
||||
@ -367,6 +367,13 @@
|
||||
<string>Fancy View</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_viewMode">
|
||||
<property name="text">
|
||||
<string>Most Recent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea_3">
|
||||
<property name="widgetResizable">
|
||||
@ -381,7 +388,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>508</width>
|
||||
<height>466</height>
|
||||
<height>443</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
|
Loading…
Reference in New Issue
Block a user