Added Forum reply with plaintext quote (by anmo)

This commit is contained in:
defnax 2015-11-19 12:05:52 +01:00
parent e3d12b8194
commit 5404cda302
6 changed files with 127 additions and 5 deletions

View File

@ -260,7 +260,7 @@ void CreateGxsForumMsg::loadFormInformation()
ui.signBox->setEnabled(true);
}
ui.forumMessage->setText("");
//ui.forumMessage->setText("");
}
void CreateGxsForumMsg::createMsg()
@ -506,3 +506,8 @@ void CreateGxsForumMsg::loadRequest(const TokenQueue *queue, const TokenRequest
}
}
}
void CreateGxsForumMsg::insertPastedText(QString msg)
{
ui.forumMessage->append(msg);
}

View File

@ -40,6 +40,7 @@ public:
void newMsg(); /* cleanup */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void insertPastedText(QString msg) ;
private slots:
void fileHashingFinished(QList<HashedFile> hashedFiles);

View File

@ -97,6 +97,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mTokenTypeInsertThreads = nextTokenType();
mTokenTypeMessageData = nextTokenType();
mTokenTypeReplyMessage = nextTokenType();
mTokenTypeReplyForumMessage = nextTokenType();
setUpdateWhenInvisible(true);
@ -137,7 +138,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
ui->subscribeToolButton->hide() ;
connect(ui->subscribeToolButton, SIGNAL(subscribe(bool)), this, SLOT(subscribeGroup(bool)));
connect(ui->newmessageButton, SIGNAL(clicked()), this, SLOT(createmessage()));
connect(ui->newmessageButton, SIGNAL(clicked()), this, SLOT(replytoforummessage()));
connect(ui->newthreadButton, SIGNAL(clicked()), this, SLOT(createthread()));
connect(ui->threadTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(changedThread()));
@ -404,7 +405,7 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
QMenu contextMnu(this);
QAction *replyAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply"), &contextMnu);
connect(replyAct, SIGNAL(triggered()), this, SLOT(createmessage()));
connect(replyAct, SIGNAL(triggered()), this, SLOT(replytoforummessage()));
QAction *replyauthorAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply with private message"), &contextMnu);
connect(replyauthorAct, SIGNAL(triggered()), this, SLOT(replytomessage()));
@ -1787,6 +1788,18 @@ void GxsForumThreadWidget::replytomessage()
requestMsgData_ReplyMessage(postId);
}
void GxsForumThreadWidget::replytoforummessage()
{
if (groupId().isNull() || mThreadId.isNull()) {
QMessageBox::information(this, tr("RetroShare"),tr("You cant reply to a non-existant Message"));
return;
}
// Get Message ... then complete replyMessageData().
RsGxsGrpMsgIdPair postId = std::make_pair(groupId(), mThreadId);
requestMsgData_ReplyForumMessage(postId);
}
void GxsForumThreadWidget::replyMessageData(const RsGxsForumMsg &msg)
{
if ((msg.mMeta.mGroupId != groupId()) || (msg.mMeta.mMsgId != mThreadId))
@ -1815,6 +1828,34 @@ void GxsForumThreadWidget::replyMessageData(const RsGxsForumMsg &msg)
}
}
void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg)
{
if ((msg.mMeta.mGroupId != groupId()) || (msg.mMeta.mMsgId != mThreadId))
{
std::cerr << "GxsForumThreadWidget::replyMessageData() ERROR Message Ids have changed!";
std::cerr << std::endl;
return;
}
if (!msg.mMeta.mAuthorId.isNull())
{
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId);
QTextDocument doc ;
// doc.setHtml(QString::fromUtf8(msg.mMsg.c_str()) );
// std::string cited_text(doc.toPlainText().toStdString()) ;
RsHtml::makeQuotedText(ui->postText);
cfm->insertPastedText(RsHtml::makeQuotedText(ui->postText)) ;
cfm->show();
/* window will destroy itself! */
}
else
{
QMessageBox::information(this, tr("RetroShare"),tr("You cant reply to an Anonymous Author"));
}
}
void GxsForumThreadWidget::changedViewBox()
{
if (mInProcessSettings) {
@ -2031,6 +2072,24 @@ void GxsForumThreadWidget::requestMsgData_ReplyMessage(const RsGxsGrpMsgIdPair &
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeReplyMessage);
}
void GxsForumThreadWidget::requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId)
{
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumThreadWidget::requestMsgData_ReplyMessage(" << msgId.first << "," << msgId.second << ")";
std::cerr << std::endl;
#endif
GxsMsgReq msgIds;
std::vector<RsGxsMessageId> &vect = msgIds[msgId.first];
vect.push_back(msgId.second);
uint32_t token;
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeReplyForumMessage);
}
void GxsForumThreadWidget::loadMsgData_ReplyMessage(const uint32_t &token)
{
#ifdef DEBUG_FORUMS
@ -2047,7 +2106,6 @@ void GxsForumThreadWidget::loadMsgData_ReplyMessage(const uint32_t &token)
std::cerr << std::endl;
return;
}
replyMessageData(msgs[0]);
}
else
@ -2057,6 +2115,32 @@ void GxsForumThreadWidget::loadMsgData_ReplyMessage(const uint32_t &token)
}
}
void GxsForumThreadWidget::loadMsgData_ReplyForumMessage(const uint32_t &token)
{
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumThreadWidget::loadMsgData_ReplyMessage()";
std::cerr << std::endl;
#endif
std::vector<RsGxsForumMsg> msgs;
if (rsGxsForums->getMsgData(token, msgs))
{
if (msgs.size() != 1)
{
std::cerr << "GxsForumThreadWidget::loadMsgData_ReplyMessage() ERROR Wrong number of answers";
std::cerr << std::endl;
return;
}
replyForumMessageData(msgs[0]);
}
else
{
std::cerr << "GxsForumThreadWidget::loadMsgData_ReplyMessage() ERROR Missing Message Data...";
std::cerr << std::endl;
}
}
void GxsForumThreadWidget::loadMsgData_BanAuthor(const uint32_t &token)
{
#ifdef DEBUG_FORUMS
@ -2115,6 +2199,11 @@ void GxsForumThreadWidget::loadRequest(const TokenQueue *queue, const TokenReque
loadMsgData_ReplyMessage(req.mToken);
return;
}
if (req.mUserType == mTokenTypeReplyForumMessage) {
loadMsgData_ReplyForumMessage(req.mToken);
return;
}
if (req.mUserType == mTokenTypeBanAuthor) {
loadMsgData_BanAuthor(req.mToken);

View File

@ -75,7 +75,13 @@ private slots:
void clickedThread (QTreeWidgetItem *item, int column);
void replytomessage();
void replytoforummessage();
void replyMessageData(const RsGxsForumMsg &msg);
void replyForumMessageData(const RsGxsForumMsg &msg);
//void print();
//void printpreview();
@ -141,7 +147,10 @@ private:
void loadMessageData(const uint32_t &token);
void requestMsgData_ReplyMessage(const RsGxsGrpMsgIdPair &msgId);
void loadMsgData_ReplyMessage(const uint32_t &token);
void loadMsgData_BanAuthor(const uint32_t &token);
void requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId);
void loadMsgData_ReplyForumMessage(const uint32_t &token);
void loadMsgData_BanAuthor(const uint32_t &token);
private:
RsGxsGroupId mLastForumID;
@ -162,6 +171,7 @@ private:
uint32_t mTokenTypeInsertThreads;
uint32_t mTokenTypeMessageData;
uint32_t mTokenTypeReplyMessage;
uint32_t mTokenTypeReplyForumMessage;
uint32_t mTokenTypeBanAuthor;
/* Color definitions (for standard see qss.default) */

View File

@ -24,6 +24,7 @@
#include <QtXml>
#include <QBuffer>
#include <QMessageBox>
#include <QTextDocumentFragment>
#include <qmath.h>
#include "HandleRichText.h"
@ -997,3 +998,15 @@ QString RsHtml::plainText(const std::string &text)
return Qt::escape(QString::fromUtf8(text.c_str()));
#endif
}
QString RsHtml::makeQuotedText(RSTextBrowser *browser)
{
QString text = browser->textCursor().selection().toPlainText();
if(text.length() == 0)
{
text = browser->toPlainText();
}
QStringList sl = text.split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
text = sl.join("\n>");
return QString(">") + text;
}

View File

@ -19,6 +19,8 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <gui/common/RSTextBrowser.h>
/**
* This file provides helper functions and functors for translating data from/to
* rich text format and HTML. Its main goal is to facilitate decoding of chat
@ -72,6 +74,8 @@ public:
static QString plainText(const QString &text);
static QString plainText(const std::string &text);
static QString makeQuotedText(RSTextBrowser* browser);
protected:
void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement &currentElement, EmbedInHtml& embedInfos, ulong flag);
void replaceAnchorWithImg(QDomDocument& doc, QDomElement &element, QTextDocument *textDocument, const RetroShareLink &link);