added GUI for editing forum messages

This commit is contained in:
csoler 2017-02-03 12:48:51 +01:00
parent 72493ad09f
commit 777a73e528
4 changed files with 127 additions and 24 deletions

View File

@ -49,8 +49,8 @@
//#define ENABLE_GENERATE //#define ENABLE_GENERATE
/** Constructor */ /** Constructor */
CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId) CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId,const RsGxsMessageId& mOId)
: QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), mForumId(fId), mParentId(pId) : QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint), mForumId(fId), mParentId(pId), mOrigMsgId(mOId)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this); ui.setupUi(this);
@ -75,7 +75,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
mStateHelper->addLoadPlaceholder(CREATEGXSFORUMMSG_PARENTMSG, ui.forumSubject); mStateHelper->addLoadPlaceholder(CREATEGXSFORUMMSG_PARENTMSG, ui.forumSubject);
mStateHelper->addClear(CREATEGXSFORUMMSG_PARENTMSG, ui.forumName); mStateHelper->addClear(CREATEGXSFORUMMSG_PARENTMSG, ui.forumName);
QString text = pId.isNull() ? tr("Start New Thread") : tr("Post Forum Message"); QString text = mOId.isNull()?(pId.isNull() ? tr("Start New Thread") : tr("Post Forum Message")):tr("Edit Message");
setWindowTitle(text); setWindowTitle(text);
ui.headerFrame->setHeaderImage(QPixmap(":/images/konversation64.png")); ui.headerFrame->setHeaderImage(QPixmap(":/images/konversation64.png"));
@ -285,6 +285,7 @@ void CreateGxsForumMsg::createMsg()
RsGxsForumMsg msg; RsGxsForumMsg msg;
msg.mMeta.mGroupId = mForumId; msg.mMeta.mGroupId = mForumId;
msg.mMeta.mParentId = mParentId; msg.mMeta.mParentId = mParentId;
msg.mMeta.mOrigMsgId = mOrigMsgId;
msg.mMeta.mMsgId.clear() ; msg.mMeta.mMsgId.clear() ;
if (mParentMsgLoaded) { if (mParentMsgLoaded) {
msg.mMeta.mThreadId = mParentMsg.mMeta.mThreadId; msg.mMeta.mThreadId = mParentMsg.mMeta.mThreadId;
@ -376,9 +377,9 @@ void CreateGxsForumMsg::reject()
{ {
if (ui.forumMessage->document()->isModified()) { if (ui.forumMessage->document()->isModified()) {
QMessageBox::StandardButton ret; QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Forum Message"), ret = QMessageBox::warning(this, tr("Cancel Forum Message"),
tr("Forum Message has not been Sent.\n" tr("Forum Message has not been sent yet!\n"
"Do you want to reject this message?"), "Please confirm that you want to discard this message?"),
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
switch (ret) { switch (ret) {
case QMessageBox::Yes: case QMessageBox::Yes:

View File

@ -36,7 +36,7 @@ class CreateGxsForumMsg : public QDialog, public TokenResponse
Q_OBJECT Q_OBJECT
public: public:
CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId); CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId, const RsGxsMessageId &moId);
~CreateGxsForumMsg(); ~CreateGxsForumMsg();
void newMsg(); /* cleanup */ void newMsg(); /* cleanup */
@ -66,10 +66,12 @@ private:
RsGxsGroupId mForumId; RsGxsGroupId mForumId;
RsGxsCircleId mCircleId ; RsGxsCircleId mCircleId ;
RsGxsMessageId mParentId; RsGxsMessageId mParentId;
RsGxsMessageId mOrigMsgId;
bool mParentMsgLoaded; bool mParentMsgLoaded;
bool mForumMetaLoaded; bool mForumMetaLoaded;
bool mForumCircleLoaded ; bool mForumCircleLoaded ;
RsGxsForumMsg mParentMsg; RsGxsForumMsg mParentMsg;
RsGroupMetaData mForumMeta; RsGroupMetaData mForumMeta;
RsGxsCircleGroup mForumCircleData ; RsGxsCircleGroup mForumCircleData ;

View File

@ -160,6 +160,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mTokenTypeNegativeAuthor = nextTokenType(); mTokenTypeNegativeAuthor = nextTokenType();
mTokenTypeNeutralAuthor = nextTokenType(); mTokenTypeNeutralAuthor = nextTokenType();
mTokenTypePositiveAuthor = nextTokenType(); mTokenTypePositiveAuthor = nextTokenType();
mTokenTypeEditForumMessage = nextTokenType();
setUpdateWhenInvisible(true); setUpdateWhenInvisible(true);
@ -478,11 +479,14 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
QMenu contextMnu(this); QMenu contextMnu(this);
QAction *editAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Edit"), &contextMnu);
connect(editAct, SIGNAL(triggered()), this, SLOT(editforummessage()));
QAction *replyAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply"), &contextMnu); QAction *replyAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply"), &contextMnu);
connect(replyAct, SIGNAL(triggered()), this, SLOT(replytoforummessage())); connect(replyAct, SIGNAL(triggered()), this, SLOT(replytoforummessage()));
QAction *replyauthorAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply to author with private message"), &contextMnu); QAction *replyauthorAct = new QAction(QIcon(IMAGE_MESSAGEREPLY), tr("Reply to author with private message"), &contextMnu);
connect(replyauthorAct, SIGNAL(triggered()), this, SLOT(replytomessage())); connect(replyauthorAct, SIGNAL(triggered()), this, SLOT(reply_with_private_message()));
QAction *flagaspositiveAct = new QAction(QIcon(IMAGE_POSITIVE_OPINION), tr("Give positive opinion"), &contextMnu); QAction *flagaspositiveAct = new QAction(QIcon(IMAGE_POSITIVE_OPINION), tr("Give positive opinion"), &contextMnu);
flagaspositiveAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ; flagaspositiveAct->setToolTip(tr("This will block/hide messages from this person, and notify friend nodes.")) ;
@ -567,6 +571,18 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
replyauthorAct->setDisabled (true); replyauthorAct->setDisabled (true);
} }
QList<QTreeWidgetItem*> selectedItems = ui->threadTreeWidget->selectedItems();
if(selectedItems.size() == 1)
{
QTreeWidgetItem *item = *selectedItems.begin();
GxsIdRSTreeWidgetItem *gxsIdItem = dynamic_cast<GxsIdRSTreeWidgetItem*>(item);
RsGxsId author_id;
if(gxsIdItem && gxsIdItem->getId(author_id) && rsIdentity->isOwnId(author_id))
contextMnu.addAction(editAct);
}
contextMnu.addAction(replyAct); contextMnu.addAction(replyAct);
contextMnu.addAction(newthreadAct); contextMnu.addAction(newthreadAct);
QAction* action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink())); QAction* action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink()));
@ -580,8 +596,6 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
contextMnu.addAction(expandAll); contextMnu.addAction(expandAll);
contextMnu.addAction(collapseAll); contextMnu.addAction(collapseAll);
QList<QTreeWidgetItem*> selectedItems = ui->threadTreeWidget->selectedItems();
if(selectedItems.size() == 1) if(selectedItems.size() == 1)
{ {
QTreeWidgetItem *item = *selectedItems.begin(); QTreeWidgetItem *item = *selectedItems.begin();
@ -1952,7 +1966,7 @@ void GxsForumThreadWidget::createmessage()
return; return;
} }
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId); CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId,RsGxsMessageId());
cfm->show(); cfm->show();
/* window will destroy itself! */ /* window will destroy itself! */
@ -1965,7 +1979,7 @@ void GxsForumThreadWidget::createthread()
return; return;
} }
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), RsGxsMessageId()); CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), RsGxsMessageId(),RsGxsMessageId());
cfm->show(); cfm->show();
/* window will destroy itself! */ /* window will destroy itself! */
@ -2019,7 +2033,7 @@ void GxsForumThreadWidget::flagperson()
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, token_type); mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, token_type);
} }
void GxsForumThreadWidget::replytomessage() void GxsForumThreadWidget::reply_with_private_message()
{ {
if (groupId().isNull() || mThreadId.isNull()) { if (groupId().isNull() || mThreadId.isNull()) {
QMessageBox::information(this, tr("RetroShare"),tr("You cant reply to a non-existant Message")); QMessageBox::information(this, tr("RetroShare"),tr("You cant reply to a non-existant Message"));
@ -2028,9 +2042,19 @@ void GxsForumThreadWidget::replytomessage()
// Get Message ... then complete replyMessageData(). // Get Message ... then complete replyMessageData().
RsGxsGrpMsgIdPair postId = std::make_pair(groupId(), mThreadId); RsGxsGrpMsgIdPair postId = std::make_pair(groupId(), mThreadId);
requestMsgData_ReplyMessage(postId); requestMsgData_ReplyWithPrivateMessage(postId);
} }
void GxsForumThreadWidget::editforummessage()
{
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_EditForumMessage(postId);
}
void GxsForumThreadWidget::replytoforummessage() void GxsForumThreadWidget::replytoforummessage()
{ {
if (groupId().isNull() || mThreadId.isNull()) { if (groupId().isNull() || mThreadId.isNull()) {
@ -2083,6 +2107,29 @@ void GxsForumThreadWidget::showAuthorInPeople(const RsGxsForumMsg& msg)
requestMsgData_ShowAuthorInPeople(postId); requestMsgData_ShowAuthorInPeople(postId);
} }
void GxsForumThreadWidget::editForumMessageData(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, msg.mMeta.mMsgId);
cfm->insertPastedText(QString::fromUtf8(msg.mMsg.c_str())) ;
cfm->show();
/* window will destroy itself! */
}
else
{
QMessageBox::information(this, tr("RetroShare"),tr("You cant reply to an Anonymous Author"));
}
}
void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg) void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg)
{ {
if ((msg.mMeta.mGroupId != groupId()) || (msg.mMeta.mMsgId != mThreadId)) if ((msg.mMeta.mGroupId != groupId()) || (msg.mMeta.mMsgId != mThreadId))
@ -2094,10 +2141,12 @@ void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg)
if (!msg.mMeta.mAuthorId.isNull()) if (!msg.mMeta.mAuthorId.isNull())
{ {
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId); CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId,RsGxsMessageId());
QTextDocument doc ;
// QTextDocument doc ;
// doc.setHtml(QString::fromUtf8(msg.mMsg.c_str()) ); // doc.setHtml(QString::fromUtf8(msg.mMsg.c_str()) );
// std::string cited_text(doc.toPlainText().toStdString()) ; // std::string cited_text(doc.toPlainText().toStdString()) ;
RsHtml::makeQuotedText(ui->postText); RsHtml::makeQuotedText(ui->postText);
cfm->insertPastedText(RsHtml::makeQuotedText(ui->postText)) ; cfm->insertPastedText(RsHtml::makeQuotedText(ui->postText)) ;
@ -2318,7 +2367,8 @@ void GxsForumThreadWidget::loadMessageData(const uint32_t &token)
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
void GxsForumThreadWidget::requestMsgData_ReplyMessage(const RsGxsGrpMsgIdPair &msgId)
void GxsForumThreadWidget::requestMsgData_ReplyWithPrivateMessage(const RsGxsGrpMsgIdPair &msgId)
{ {
RsTokReqOptions opts; RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
@ -2353,7 +2403,23 @@ void GxsForumThreadWidget::requestMsgData_ShowAuthorInPeople(const RsGxsGrpMsgId
uint32_t token; uint32_t token;
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeShowAuthorInPeople); mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeShowAuthorInPeople);
} }
void GxsForumThreadWidget::requestMsgData_EditForumMessage(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, mTokenTypeEditForumMessage);
}
void GxsForumThreadWidget::requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId) void GxsForumThreadWidget::requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId)
{ {
RsTokReqOptions opts; RsTokReqOptions opts;
@ -2397,6 +2463,31 @@ void GxsForumThreadWidget::loadMsgData_ReplyMessage(const uint32_t &token)
} }
} }
void GxsForumThreadWidget::loadMsgData_EditForumMessage(const uint32_t &token)
{
#ifdef DEBUG_FORUMS
std::cerr << "GxsForumThreadWidget::loadMsgData_EditMessage()";
std::cerr << std::endl;
#endif
std::vector<RsGxsForumMsg> msgs;
if (rsGxsForums->getMsgData(token, msgs))
{
if (msgs.size() != 1)
{
std::cerr << "GxsForumThreadWidget::loadMsgData_EditMessage() ERROR Wrong number of answers";
std::cerr << std::endl;
return;
}
editForumMessageData(msgs[0]);
}
else
{
std::cerr << "GxsForumThreadWidget::loadMsgData_ReplyMessage() ERROR Missing Message Data...";
std::cerr << std::endl;
}
}
void GxsForumThreadWidget::loadMsgData_ReplyForumMessage(const uint32_t &token) void GxsForumThreadWidget::loadMsgData_ReplyForumMessage(const uint32_t &token)
{ {
#ifdef DEBUG_FORUMS #ifdef DEBUG_FORUMS
@ -2524,6 +2615,10 @@ void GxsForumThreadWidget::loadRequest(const TokenQueue *queue, const TokenReque
return; return;
} }
if (req.mUserType == mTokenTypeEditForumMessage) {
loadMsgData_EditForumMessage(req.mToken);
return;
}
if (req.mUserType == mTokenTypeShowAuthorInPeople) { if (req.mUserType == mTokenTypeShowAuthorInPeople) {
loadMsgData_ShowAuthorInPeople(req.mToken); loadMsgData_ShowAuthorInPeople(req.mToken);
return; return;

View File

@ -75,10 +75,12 @@ private slots:
void changedThread(); void changedThread();
void clickedThread (QTreeWidgetItem *item, int column); void clickedThread (QTreeWidgetItem *item, int column);
void replytomessage(); void reply_with_private_message();
void replytoforummessage(); void replytoforummessage();
void editforummessage();
void replyMessageData(const RsGxsForumMsg &msg); void replyMessageData(const RsGxsForumMsg &msg);
void editForumMessageData(const RsGxsForumMsg &msg);
void replyForumMessageData(const RsGxsForumMsg &msg); void replyForumMessageData(const RsGxsForumMsg &msg);
void showAuthorInPeople(const RsGxsForumMsg& msg); void showAuthorInPeople(const RsGxsForumMsg& msg);
@ -147,13 +149,15 @@ private:
static void loadAuthorIdCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/); static void loadAuthorIdCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/);
void requestMessageData(const RsGxsGrpMsgIdPair &msgId); void requestMessageData(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_ReplyMessage(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_ReplyWithPrivateMessage(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_ShowAuthorInPeople(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_ShowAuthorInPeople(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_EditForumMessage(const RsGxsGrpMsgIdPair &msgId);
void loadMessageData(const uint32_t &token); void loadMessageData(const uint32_t &token);
void loadMsgData_ReplyMessage(const uint32_t &token); void loadMsgData_ReplyMessage(const uint32_t &token);
void loadMsgData_ReplyForumMessage(const uint32_t &token); void loadMsgData_ReplyForumMessage(const uint32_t &token);
void loadMsgData_EditForumMessage(const uint32_t &token);
void loadMsgData_ShowAuthorInPeople(const uint32_t &token); void loadMsgData_ShowAuthorInPeople(const uint32_t &token);
void loadMsgData_SetAuthorOpinion(const uint32_t &token, RsReputations::Opinion opinion); void loadMsgData_SetAuthorOpinion(const uint32_t &token, RsReputations::Opinion opinion);
@ -177,6 +181,7 @@ private:
uint32_t mTokenTypeMessageData; uint32_t mTokenTypeMessageData;
uint32_t mTokenTypeReplyMessage; uint32_t mTokenTypeReplyMessage;
uint32_t mTokenTypeReplyForumMessage; uint32_t mTokenTypeReplyForumMessage;
uint32_t mTokenTypeEditForumMessage;
uint32_t mTokenTypeShowAuthorInPeople; uint32_t mTokenTypeShowAuthorInPeople;
uint32_t mTokenTypeNegativeAuthor; uint32_t mTokenTypeNegativeAuthor;
uint32_t mTokenTypePositiveAuthor; uint32_t mTokenTypePositiveAuthor;