2018-12-25 21:10:15 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/TheWire/PulseAddDialog.cpp *
|
|
|
|
* *
|
2020-02-29 11:47:00 +11:00
|
|
|
* Copyright (c) 2012-2020 Robert Fernie <retroshare.project@gmail.com> *
|
2018-12-25 21:10:15 +01:00
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
#include <iostream>
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
#include "PulseDetails.h"
|
|
|
|
|
|
|
|
#include "PulseAddDialog.h"
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
PulseAddDialog::PulseAddDialog(QWidget *parent)
|
2020-02-29 11:47:00 +11:00
|
|
|
: QWidget(parent), mIsReply(false), mWaitingRefMsg(false)
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
mWireQueue = new TokenQueue(rsWire->getTokenService(), this);
|
|
|
|
|
2012-02-13 18:43:15 +00:00
|
|
|
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_AddTo, SIGNAL( clicked( void ) ), this, SLOT( addTo( void ) ) );
|
|
|
|
connect(ui.pushButton_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelPulse( void ) ) );
|
2020-02-29 11:47:00 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void PulseAddDialog::setGroup(RsWireGroup &group)
|
|
|
|
{
|
|
|
|
ui.label_groupName->setText(QString::fromStdString(group.mMeta.mGroupName));
|
|
|
|
ui.label_idName->setText(QString::fromStdString(group.mMeta.mAuthorId.toStdString()));
|
|
|
|
mGroup = group;
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::setReplyTo(RsWirePulse &pulse, std::string &groupName)
|
|
|
|
{
|
|
|
|
mIsReply = true;
|
|
|
|
mReplyToPulse = pulse;
|
|
|
|
mReplyGroupName = groupName;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
{
|
2020-03-13 16:44:15 +11:00
|
|
|
std::map<rstime_t, RsWirePulse *> replies;
|
|
|
|
PulseDetails *details = new PulseDetails(NULL, &pulse, groupName, replies);
|
2020-02-29 11:47:00 +11:00
|
|
|
// add extra widget into layout.
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout();
|
|
|
|
vbox->addWidget(details);
|
|
|
|
vbox->setSpacing(1);
|
|
|
|
vbox->setContentsMargins(0,0,0,0);
|
|
|
|
ui.widget_replyto->setLayout(vbox);
|
|
|
|
ui.widget_replyto->setVisible(true);
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PulseAddDialog::addURL()
|
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::addURL()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PulseAddDialog::addTo()
|
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::addTo()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PulseAddDialog::cancelPulse()
|
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::cancelPulse()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
clearDialog();
|
|
|
|
hide();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postPulse()
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::postPulse()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
if (mIsReply)
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
postReplyPulse();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
postOriginalPulse();
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postOriginalPulse()
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::postOriginalPulse()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
RsWirePulse pulse;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
pulse.mMeta.mGroupId = mGroup.mMeta.mGroupId;
|
|
|
|
pulse.mMeta.mAuthorId = mGroup.mMeta.mAuthorId;
|
|
|
|
pulse.mMeta.mThreadId.clear();
|
|
|
|
pulse.mMeta.mParentId.clear();
|
|
|
|
pulse.mMeta.mOrigMsgId.clear();
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
pulse.mPulseType = WIRE_PULSE_TYPE_ORIGINAL_MSG;
|
|
|
|
pulse.mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
|
|
|
// all mRefs should empty.
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
uint32_t token;
|
|
|
|
rsWire->createPulse(token, pulse);
|
|
|
|
|
|
|
|
clearDialog();
|
|
|
|
hide();
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postReplyPulse()
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::postReplyPulse()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
RsWirePulse pulse;
|
|
|
|
|
|
|
|
pulse.mMeta.mGroupId = mGroup.mMeta.mGroupId;
|
|
|
|
pulse.mMeta.mAuthorId = mGroup.mMeta.mAuthorId;
|
|
|
|
pulse.mMeta.mThreadId.clear();
|
|
|
|
pulse.mMeta.mParentId.clear();
|
|
|
|
pulse.mMeta.mOrigMsgId.clear();
|
|
|
|
|
|
|
|
pulse.mPulseType = WIRE_PULSE_TYPE_REPLY_MSG;
|
|
|
|
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);
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::postRefPulse(RsWirePulse &pulse)
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::postRefPulse() create Reference!";
|
|
|
|
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_REPLY_REFERENCE;
|
|
|
|
// 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);
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
clearDialog();
|
|
|
|
hide();
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::clearDialog()
|
|
|
|
{
|
|
|
|
ui.textEdit_Pulse->setPlainText("");
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::acknowledgeMessage(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::acknowledgeMessage()";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
std::pair<RsGxsGroupId, RsGxsMessageId> p;
|
|
|
|
rsWire->acknowledgeMsg(token, p);
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
if (mWaitingRefMsg)
|
2012-02-13 18:43:15 +00:00
|
|
|
{
|
2020-02-29 11:47:00 +11:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
void PulseAddDialog::loadPulseData(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::loadPulseData()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::vector<RsWirePulse> pulses;
|
|
|
|
rsWire->getPulseData(token, pulses);
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
if (pulses.size() != 1)
|
|
|
|
{
|
|
|
|
std::cerr << "PulseAddDialog::loadPulseData() Error Too many pulses";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
std::cerr << "PulseAddDialog::loadPulseData() calling postRefMsg";
|
|
|
|
std::cerr << std::endl;
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
RsWirePulse& pulse = pulses[0];
|
|
|
|
postRefPulse(pulse);
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
/**************************** Request / Response Filling of Data ************************/
|
2012-02-13 18:43:15 +00:00
|
|
|
|
2020-02-29 11:47:00 +11:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-02-13 18:43:15 +00:00
|
|
|
}
|
|
|
|
|