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

View File

@ -36,7 +36,7 @@ class CreateGxsForumMsg : public QDialog, public TokenResponse
Q_OBJECT
public:
CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId);
CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId, const RsGxsMessageId &moId);
~CreateGxsForumMsg();
void newMsg(); /* cleanup */
@ -64,15 +64,17 @@ private:
void loadForumCircleInfo(const uint32_t &token);
RsGxsGroupId mForumId;
RsGxsCircleId mCircleId ;
RsGxsMessageId mParentId;
RsGxsCircleId mCircleId ;
RsGxsMessageId mParentId;
RsGxsMessageId mOrigMsgId;
bool mParentMsgLoaded;
bool mForumMetaLoaded;
bool mForumCircleLoaded ;
bool mForumCircleLoaded ;
RsGxsForumMsg mParentMsg;
RsGroupMetaData mForumMeta;
RsGxsCircleGroup mForumCircleData ;
RsGxsCircleGroup mForumCircleData ;
TokenQueue *mForumQueue;
TokenQueue *mCirclesQueue;

View File

@ -160,6 +160,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mTokenTypeNegativeAuthor = nextTokenType();
mTokenTypeNeutralAuthor = nextTokenType();
mTokenTypePositiveAuthor = nextTokenType();
mTokenTypeEditForumMessage = nextTokenType();
setUpdateWhenInvisible(true);
@ -478,11 +479,14 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
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);
connect(replyAct, SIGNAL(triggered()), this, SLOT(replytoforummessage()));
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);
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);
}
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(newthreadAct);
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(collapseAll);
QList<QTreeWidgetItem*> selectedItems = ui->threadTreeWidget->selectedItems();
if(selectedItems.size() == 1)
{
QTreeWidgetItem *item = *selectedItems.begin();
@ -1952,7 +1966,7 @@ void GxsForumThreadWidget::createmessage()
return;
}
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId);
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId,RsGxsMessageId());
cfm->show();
/* window will destroy itself! */
@ -1965,7 +1979,7 @@ void GxsForumThreadWidget::createthread()
return;
}
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), RsGxsMessageId());
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), RsGxsMessageId(),RsGxsMessageId());
cfm->show();
/* window will destroy itself! */
@ -2019,7 +2033,7 @@ void GxsForumThreadWidget::flagperson()
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()) {
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().
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()
{
if (groupId().isNull() || mThreadId.isNull()) {
@ -2083,6 +2107,29 @@ void GxsForumThreadWidget::showAuthorInPeople(const RsGxsForumMsg& msg)
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)
{
if ((msg.mMeta.mGroupId != groupId()) || (msg.mMeta.mMsgId != mThreadId))
@ -2094,10 +2141,12 @@ void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg)
if (!msg.mMeta.mAuthorId.isNull())
{
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId);
QTextDocument doc ;
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId,RsGxsMessageId());
// 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)) ;
@ -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;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
@ -2353,7 +2403,23 @@ void GxsForumThreadWidget::requestMsgData_ShowAuthorInPeople(const RsGxsGrpMsgId
uint32_t token;
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)
{
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)
{
#ifdef DEBUG_FORUMS
@ -2524,6 +2615,10 @@ void GxsForumThreadWidget::loadRequest(const TokenQueue *queue, const TokenReque
return;
}
if (req.mUserType == mTokenTypeEditForumMessage) {
loadMsgData_EditForumMessage(req.mToken);
return;
}
if (req.mUserType == mTokenTypeShowAuthorInPeople) {
loadMsgData_ShowAuthorInPeople(req.mToken);
return;

View File

@ -75,10 +75,12 @@ private slots:
void changedThread();
void clickedThread (QTreeWidgetItem *item, int column);
void replytomessage();
void reply_with_private_message();
void replytoforummessage();
void editforummessage();
void replyMessageData(const RsGxsForumMsg &msg);
void editForumMessageData(const RsGxsForumMsg &msg);
void replyForumMessageData(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*/);
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_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_EditForumMessage(const RsGxsGrpMsgIdPair &msgId);
void loadMessageData(const uint32_t &token);
void loadMsgData_ReplyMessage(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_SetAuthorOpinion(const uint32_t &token, RsReputations::Opinion opinion);
@ -177,6 +181,7 @@ private:
uint32_t mTokenTypeMessageData;
uint32_t mTokenTypeReplyMessage;
uint32_t mTokenTypeReplyForumMessage;
uint32_t mTokenTypeEditForumMessage;
uint32_t mTokenTypeShowAuthorInPeople;
uint32_t mTokenTypeNegativeAuthor;
uint32_t mTokenTypePositiveAuthor;