Make forum moderator selectable by the user

This commit is contained in:
David Bears 2025-03-14 12:31:29 -04:00
parent 8fcc52b304
commit 41b3ec4de5
No known key found for this signature in database
GPG Key ID: FB975E12C69F7177
3 changed files with 31 additions and 42 deletions

View File

@ -53,9 +53,9 @@
//#define ENABLE_GENERATE
/** Constructor */
CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId, const RsGxsMessageId& mOId, const RsGxsId& posterId, bool isModerating)
CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId, const RsGxsMessageId& mOId, const RsGxsId& posterId, const std::set<RsGxsId>& moderatorSet)
: QDialog(NULL, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint),
mForumId(fId), mParentId(pId), mOrigMsgId(mOId),mPosterId(posterId),mIsModerating(isModerating),
mForumId(fId), mParentId(pId), mOrigMsgId(mOId), mPosterId(posterId), mModeratorSet(moderatorSet),
ui(new Ui::CreateGxsForumMsg)
{
/* Invoke the Qt Designer generated object setup routine */
@ -86,7 +86,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
QString text = mOId.isNull()?(pId.isNull() ? tr("Start New Thread") : tr("Post Forum Message")):tr("Edit Message");
setWindowTitle(text);
if (!mOId.isNull())
ui->postButton->setText(tr ("Update"));
@ -119,7 +119,7 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
mForumCircleLoaded = false;
newMsg();
ui->hashGroupBox->hide();
#ifndef ENABLE_GENERATE
@ -168,19 +168,22 @@ void CreateGxsForumMsg::newMsg()
mForumMetaLoaded = false;
/* fill in the available OwnIds for signing */
//std::cerr << "Initing ID chooser. Sign flags = " << std::hex << mForumMeta.mSignFlags << std::dec << std::endl;
if(!mPosterId.isNull())
{
std::set<RsGxsId> id_set ;
id_set.insert(mPosterId) ;
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED | IDCHOOSER_NO_CREATE, mPosterId);
ui->idChooser->setIdConstraintSet(id_set);
//std::cerr << "Initing ID chooser. Sign flags = " << std::hex << mForumMeta.mSignFlags << std::dec << std::endl;
uint32_t idChooserFlags = IDCHOOSER_ID_REQUIRED;
if(!mOrigMsgId.isNull()) {
// we are editing an existing message
std::set<RsGxsId> id_set = mModeratorSet;
if(!mPosterId.isNull())
id_set.insert(mPosterId);
// TODO: Report error if idChooser has no IDs to choose from.
// NOTE: mPosterId may not be our own; then GxsIdChooser will not include it.
idChooserFlags |= IDCHOOSER_NO_CREATE;
ui->idChooser->setIdConstraintSet(id_set);
}
else
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, mPosterId);
ui->idChooser->loadIds(idChooserFlags, mPosterId);
if (mForumId.isNull()) {
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
@ -404,7 +407,7 @@ void CreateGxsForumMsg::createMsg()
msg.mMeta.mGroupId = mForumId;
msg.mMeta.mParentId = mParentId;
msg.mMeta.mOrigMsgId = mOrigMsgId;
msg.mMeta.mMsgFlags = mIsModerating?RS_GXS_FORUM_MSG_FLAGS_MODERATED : 0;
msg.mMeta.mMsgFlags = 0;
msg.mMeta.mMsgId.clear() ;
if (mParentMsgLoaded) {
@ -426,6 +429,8 @@ void CreateGxsForumMsg::createMsg()
case GxsIdChooser::KnowId:
case GxsIdChooser::UnKnowId:
msg.mMeta.mAuthorId = authorId;
if(!mOrigMsgId.isNull() && authorId != mPosterId)
msg.mMeta.mMsgFlags |= RS_GXS_FORUM_MSG_FLAGS_MODERATED;
//std::cerr << "CreateGxsForumMsg::createMsg() AuthorId: " << authorId;
//std::cerr << std::endl;
@ -578,7 +583,7 @@ void CreateGxsForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
void CreateGxsForumMsg::loadCircleInfo(const RsGxsGroupId& circle_id)
{
//std::cerr << "Loading forum circle info" << std::endl;
RsThread::async( [circle_id,this]()
{
std::vector<RsGxsCircleGroup> circle_grp_v ;

View File

@ -38,7 +38,7 @@ class CreateGxsForumMsg : public QDialog
Q_OBJECT
public:
CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId, const RsGxsMessageId &moId, const RsGxsId &posterId = RsGxsId(),bool isModerating=false);
CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessageId &pId, const RsGxsMessageId &moId, const RsGxsId &posterId = RsGxsId(), const std::set<RsGxsId>& moderatorSet = std::set<RsGxsId>());
~CreateGxsForumMsg();
void newMsg(); /* cleanup */
@ -59,7 +59,7 @@ private slots:
protected:
void closeEvent (QCloseEvent * event);
void loadCircleInfo(const RsGxsGroupId& circle_id);
private:
void processSettings(bool load);
@ -75,7 +75,7 @@ private:
bool mOrigMsgLoaded;
bool mForumMetaLoaded;
bool mForumCircleLoaded ;
bool mIsModerating; // means that the msg has a orig author Id that is not the Id of the author
std::set<RsGxsId> mModeratorSet; // these IDs are allowed to edit the post in addition to mPosterId
RsGxsForumMsg mParentMsg;
RsGxsForumMsg mOrigMsg;

View File

@ -1747,33 +1747,17 @@ void GxsForumThreadWidget::editForumMessageData(const RsGxsForumMsg& msg)
std::list<RsGxsId> own_ids ;
rsIdentity->getOwnIds(own_ids) ;
std::set<RsGxsId> modIds;
for(auto it(own_ids.begin());it!=own_ids.end();++it)
if(mForumGroup.mAdminList.ids.find(*it) != mForumGroup.mAdminList.ids.end())
{
moderator_id = *it;
break;
}
modIds.insert(*it);
// Check that author is in own ids, if not use the moderator id that was collected among own ids.
bool is_own = false ;
for(auto it(own_ids.begin());it!=own_ids.end() && !is_own;++it)
if(*it == msg.mMeta.mAuthorId)
is_own = true ;
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), msg.mMeta.mParentId, msg.mMeta.mMsgId, msg.mMeta.mAuthorId, modIds);
if (!msg.mMeta.mAuthorId.isNull())
{
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), msg.mMeta.mParentId, msg.mMeta.mMsgId, is_own?(msg.mMeta.mAuthorId):moderator_id,!is_own);
cfm->insertPastedText(QString::fromUtf8(msg.mMsg.c_str())) ;
cfm->show();
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"));
}
/* cfm window will destroy itself! */
}
void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg)
{