Enabled creating forum messages in FeedReader plugin

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7706 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-11-24 22:40:29 +00:00
parent 30d9671ca6
commit 069e8e490a
8 changed files with 422 additions and 246 deletions

View File

@ -87,8 +87,7 @@ void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
{ {
mInterfaces = interfaces; mInterfaces = interfaces;
//Todo: Replace with gxs forums mFeedReader = new p3FeedReader(mPlugInHandler, mInterfaces.mGxsForums);
mFeedReader = new p3FeedReader(mPlugInHandler, NULL /*mInterfaces.mForums*/);
rsFeedReader = mFeedReader; rsFeedReader = mFeedReader;
mNotify = new FeedReaderNotify(); mNotify = new FeedReaderNotify();

View File

@ -28,20 +28,28 @@
#include "PreviewFeedDialog.h" #include "PreviewFeedDialog.h"
#include "FeedReaderStringDefs.h" #include "FeedReaderStringDefs.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/common/UIStateHelper.h"
//Todo: Replace with gxs forums #include <retroshare/rsgxsforums.h>
//#include "retroshare/rsforums.h" #include <iostream>
//bool sortForumInfo(const ForumInfo& info1, const ForumInfo& info2) #define TOKEN_TYPE_FORUM_GROUPS 1
//{
// return QString::fromStdWString(info1.forumName).compare(QString::fromStdWString(info2.forumName), Qt::CaseInsensitive);
//}
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent) AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
: QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog) : QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
mStateHelper->addWidget(TOKEN_TYPE_FORUM_GROUPS, ui->forumComboBox, UISTATE_LOADING_DISABLED);
mStateHelper->addWidget(TOKEN_TYPE_FORUM_GROUPS, ui->buttonBox->button(QDialogButtonBox::Ok), UISTATE_LOADING_DISABLED);
/* Setup TokenQueue */
mTokenQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
/* Connect signals */
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(createFeed())); connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(createFeed()));
connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
@ -52,7 +60,7 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(typeForumToggled())); connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(typeForumToggled()));
connect(ui->previewButton, SIGNAL(clicked()), this, SLOT(preview())); connect(ui->previewButton, SIGNAL(clicked()), this, SLOT(preview()));
/* currently only for loacl feeds */ /* currently only for local feeds */
connect(ui->saveCompletePageCheckBox, SIGNAL(toggled(bool)), this, SLOT(denyForumToggled())); connect(ui->saveCompletePageCheckBox, SIGNAL(toggled(bool)), this, SLOT(denyForumToggled()));
connect(ui->urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(validate())); connect(ui->urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(validate()));
@ -60,16 +68,18 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
connect(ui->useInfoFromFeedCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate())); connect(ui->useInfoFromFeedCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate()));
connect(ui->typeLocalRadio, SIGNAL(toggled(bool)), this, SLOT(validate())); connect(ui->typeLocalRadio, SIGNAL(toggled(bool)), this, SLOT(validate()));
connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(validate())); connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(validate()));
connect(ui->forumComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(validate()));
connect(ui->clearCachePushButton, SIGNAL(clicked()), this, SLOT(clearMessageCache()));
ui->headerFrame->setHeaderText(tr("Feed Details")); ui->headerFrame->setHeaderText(tr("Feed Details"));
ui->headerFrame->setHeaderImage(QPixmap(":/images/FeedReader.png")); ui->headerFrame->setHeaderImage(QPixmap(":/images/FeedReader.png"));
ui->activatedCheckBox->setChecked(true); ui->activatedCheckBox->setChecked(true);
ui->forumComboBox->setEnabled(false); mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
ui->useInfoFromFeedCheckBox->setChecked(true); ui->useInfoFromFeedCheckBox->setChecked(true);
ui->updateForumInfoCheckBox->setEnabled(false); ui->updateForumInfoCheckBox->setEnabled(false);
ui->updateForumInfoCheckBox->setChecked(true); ui->updateForumInfoCheckBox->setChecked(true);
ui->forumNameLabel->hide();
ui->useAuthenticationCheckBox->setChecked(false); ui->useAuthenticationCheckBox->setChecked(false);
ui->useStandardStorageTimeCheckBox->setChecked(true); ui->useStandardStorageTimeCheckBox->setChecked(true);
ui->useStandardUpdateInterval->setChecked(true); ui->useStandardUpdateInterval->setChecked(true);
@ -81,22 +91,10 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
mTransformationType = RS_FEED_TRANSFORMATION_TYPE_NONE; mTransformationType = RS_FEED_TRANSFORMATION_TYPE_NONE;
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType)); ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
ui->clearCachePushButton->show();
/* fill own forums */ /* fill own forums */
//Todo: Replace with gxs forums requestForumGroups();
// std::list<ForumInfo> forumList;
// if (rsForums->getForumList(forumList)) {
// forumList.sort(sortForumInfo);
// for (std::list<ForumInfo>::iterator it = forumList.begin(); it != forumList.end(); ++it) {
// ForumInfo &forumInfo = *it;
// /* show only own anonymous forums */
// if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) && (forumInfo.forumFlags & RS_DISTRIB_AUTHEN_ANON)) {
// ui->forumComboBox->addItem(QString::fromStdWString(forumInfo.forumName), QString::fromStdString(forumInfo.forumId));
// }
// }
// }
/* insert item to create a new forum */
ui->forumComboBox->insertItem(0, tr("Create a new anonymous public forum"), "");
ui->forumComboBox->setCurrentIndex(0);
validate(); validate();
@ -104,9 +102,6 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
/* load settings */ /* load settings */
processSettings(true); processSettings(true);
//Todo: Replace with gxs forums
ui->typeForumRadio->setEnabled(false);
} }
AddFeedDialog::~AddFeedDialog() AddFeedDialog::~AddFeedDialog()
@ -114,7 +109,8 @@ AddFeedDialog::~AddFeedDialog()
/* save settings */ /* save settings */
processSettings(false); processSettings(false);
delete ui; delete(ui);
delete(mTokenQueue);
} }
void AddFeedDialog::processSettings(bool load) void AddFeedDialog::processSettings(bool load)
@ -164,7 +160,7 @@ void AddFeedDialog::useStandardProxyToggled()
void AddFeedDialog::typeForumToggled() void AddFeedDialog::typeForumToggled()
{ {
bool checked = ui->typeForumRadio->isChecked(); bool checked = ui->typeForumRadio->isChecked();
ui->forumComboBox->setEnabled(checked); mStateHelper->setWidgetEnabled(ui->forumComboBox, checked);
ui->updateForumInfoCheckBox->setEnabled(checked); ui->updateForumInfoCheckBox->setEnabled(checked);
} }
@ -195,7 +191,11 @@ void AddFeedDialog::validate()
ok = false; ok = false;
} }
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok); if (ui->typeForumRadio->isChecked() && ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().isEmpty()) {
ok = false;
}
mStateHelper->setWidgetEnabled(ui->buttonBox->button(QDialogButtonBox::Ok), ok);
} }
void AddFeedDialog::setParent(const std::string &parentId) void AddFeedDialog::setParent(const std::string &parentId)
@ -215,7 +215,6 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
} }
setWindowTitle(tr("Edit feed")); setWindowTitle(tr("Edit feed"));
ui->typeGroupBox->setEnabled(false);
mParentId = feedInfo.parentId; mParentId = feedInfo.parentId;
@ -229,28 +228,15 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
ui->descriptionPlainTextEdit->setPlainText(QString::fromUtf8(feedInfo.description.c_str())); ui->descriptionPlainTextEdit->setPlainText(QString::fromUtf8(feedInfo.description.c_str()));
ui->typeGroupBox->setEnabled(false);
ui->forumComboBox->hide();
ui->forumNameLabel->clear();
ui->forumNameLabel->show();
if (feedInfo.flag.forum) { if (feedInfo.flag.forum) {
mStateHelper->setWidgetEnabled(ui->forumComboBox, true);
ui->typeForumRadio->setChecked(true); ui->typeForumRadio->setChecked(true);
ui->saveCompletePageCheckBox->setEnabled(false); ui->saveCompletePageCheckBox->setEnabled(false);
if (feedInfo.forumId.empty()) { setActiveForumId(feedInfo.forumId);
ui->forumNameLabel->setText(tr("Not yet created"));
} else {
//Todo: Replace with gxs forums
// ForumInfo forumInfo;
// if (rsForums->getForumInfo(feedInfo.forumId, forumInfo)) {
// ui->forumNameLabel->setText(QString::fromStdWString(forumInfo.forumName));
// } else {
// ui->forumNameLabel->setText(tr("Unknown forum"));
// }
}
} else { } else {
ui->typeLocalRadio->setChecked(true); ui->typeLocalRadio->setChecked(true);
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
} }
ui->useAuthenticationCheckBox->setChecked(feedInfo.flag.authentication); ui->useAuthenticationCheckBox->setChecked(feedInfo.flag.authentication);
@ -276,11 +262,28 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
mXslt = feedInfo.xslt; mXslt = feedInfo.xslt;
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType)); ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
ui->clearCachePushButton->show();
} }
return true; return true;
} }
void AddFeedDialog::setActiveForumId(const std::string &forumId)
{
if (mStateHelper->isLoading(TOKEN_TYPE_FORUM_GROUPS)) {
mFillForumId = forumId;
return;
}
int index = ui->forumComboBox->findData(QString::fromStdString(forumId));
if (index >= 0) {
ui->forumComboBox->setCurrentIndex(index);
} else {
ui->forumComboBox->setCurrentIndex(0);
}
}
void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo) void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
{ {
feedInfo.parentId = mParentId; feedInfo.parentId = mParentId;
@ -296,12 +299,10 @@ void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
feedInfo.description = ui->descriptionPlainTextEdit->toPlainText().toUtf8().constData(); feedInfo.description = ui->descriptionPlainTextEdit->toPlainText().toUtf8().constData();
feedInfo.flag.forum = ui->typeForumRadio->isChecked(); feedInfo.flag.forum = ui->typeForumRadio->isChecked();
if (mFeedId.empty()) {
if (feedInfo.flag.forum) { if (feedInfo.flag.forum) {
/* set forum (only when create a new feed) */
feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString(); feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString();
} }
}
feedInfo.flag.authentication = ui->useAuthenticationCheckBox->isChecked(); feedInfo.flag.authentication = ui->useAuthenticationCheckBox->isChecked();
feedInfo.user = ui->userLineEdit->text().toUtf8().constData(); feedInfo.user = ui->userLineEdit->text().toUtf8().constData();
@ -362,3 +363,72 @@ void AddFeedDialog::preview()
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType)); ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
} }
} }
void AddFeedDialog::clearMessageCache()
{
if (mFeedId.empty()) {
return;
}
mFeedReader->clearMessageCache(mFeedId);
}
void AddFeedDialog::requestForumGroups()
{
mStateHelper->setLoading(TOKEN_TYPE_FORUM_GROUPS, true);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_FORUM_GROUPS);
uint32_t token;
mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, TOKEN_TYPE_FORUM_GROUPS);
}
void AddFeedDialog::loadForumGroups(const uint32_t &token)
{
std::vector<RsGxsForumGroup> groups;
rsGxsForums->getGroupData(token, groups);
ui->forumComboBox->clear();
for (std::vector<RsGxsForumGroup>::iterator it = groups.begin(); it != groups.end(); ++it) {
const RsGxsForumGroup &group = *it;
/* show only own forums */
if (IS_GROUP_PUBLISHER(group.mMeta.mSubscribeFlags) && IS_GROUP_ADMIN(group.mMeta.mSubscribeFlags)) {
ui->forumComboBox->addItem(QString::fromUtf8(group.mMeta.mGroupName.c_str()), QString::fromStdString(group.mMeta.mGroupId.toStdString()));
}
}
/* insert empty item */
ui->forumComboBox->insertItem(0, "", "");
ui->forumComboBox->setCurrentIndex(0);
mStateHelper->setLoading(TOKEN_TYPE_FORUM_GROUPS, false);
if (!mFillForumId.empty()) {
setActiveForumId(mFillForumId);
mFillForumId.clear();
}
}
void AddFeedDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
if (queue == mTokenQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case TOKEN_TYPE_FORUM_GROUPS:
loadForumGroups(req.mToken);
break;
default:
std::cerr << "AddFeedDialog::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
}
}
}

View File

@ -24,6 +24,7 @@
#include <QDialog> #include <QDialog>
#include "interface/rsFeedReader.h" #include "interface/rsFeedReader.h"
#include "util/TokenQueue.h"
namespace Ui { namespace Ui {
class AddFeedDialog; class AddFeedDialog;
@ -31,8 +32,9 @@ class AddFeedDialog;
class RsFeedReader; class RsFeedReader;
class FeedReaderNotify; class FeedReaderNotify;
class UIStateHelper;
class AddFeedDialog : public QDialog class AddFeedDialog : public QDialog, public TokenResponse
{ {
Q_OBJECT Q_OBJECT
@ -43,6 +45,9 @@ public:
void setParent(const std::string &parentId); void setParent(const std::string &parentId);
bool fillFeed(const std::string &feedId); bool fillFeed(const std::string &feedId);
/* TokenResponse */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
private slots: private slots:
void authenticationToggled(); void authenticationToggled();
void useStandardStorageTimeToggled(); void useStandardStorageTimeToggled();
@ -53,21 +58,31 @@ private slots:
void validate(); void validate();
void createFeed(); void createFeed();
void preview(); void preview();
void clearMessageCache();
private: private:
void processSettings(bool load); void processSettings(bool load);
void getFeedInfo(FeedInfo &feedInfo); void getFeedInfo(FeedInfo &feedInfo);
void setActiveForumId(const std::string &forumId);
void requestForumGroups();
void loadForumGroups(const uint32_t &token);
private:
RsFeedReader *mFeedReader; RsFeedReader *mFeedReader;
FeedReaderNotify *mNotify; FeedReaderNotify *mNotify;
std::string mFeedId; std::string mFeedId;
std::string mParentId; std::string mParentId;
std::string mFillForumId;
RsFeedTransformationType mTransformationType; RsFeedTransformationType mTransformationType;
std::list<std::string> mXPathsToUse; std::list<std::string> mXPathsToUse;
std::list<std::string> mXPathsToRemove; std::list<std::string> mXPathsToRemove;
std::string mXslt; std::string mXslt;
TokenQueue *mTokenQueue;
UIStateHelper *mStateHelper;
Ui::AddFeedDialog *ui; Ui::AddFeedDialog *ui;
}; };

View File

@ -14,7 +14,7 @@
<string>Create new feed</string> <string>Create new feed</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../../retroshare-gui/src/gui/images.qrc"> <iconset>
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset> <normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -75,19 +75,6 @@
<item> <item>
<widget class="QComboBox" name="forumComboBox"/> <widget class="QComboBox" name="forumComboBox"/>
</item> </item>
<item>
<widget class="QLabel" name="forumNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Forum name</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -146,13 +133,6 @@
<string>Storage time</string> <string>Storage time</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="useStandardStorageTimeCheckBox">
<property name="text">
<string>Use standard storage time</string>
</property>
</widget>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="storageTimeLabel"> <widget class="QLabel" name="storageTimeLabel">
<property name="text"> <property name="text">
@ -173,6 +153,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QCheckBox" name="useStandardStorageTimeCheckBox">
<property name="text">
<string>Use standard storage time</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="clearCachePushButton">
<property name="text">
<string>Clear cache</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -433,8 +427,6 @@
<tabstop>proxyPortSpinBox</tabstop> <tabstop>proxyPortSpinBox</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
</tabstops> </tabstops>
<resources> <resources/>
<include location="../../../retroshare-gui/src/gui/images.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -119,9 +119,6 @@ QString FeedReaderStringDefs::errorString(RsFeedReaderErrorState errorState, con
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN: case RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN:
errorText = QApplication::translate("FeedReaderStringDefs", "You are not admin of the forum"); errorText = QApplication::translate("FeedReaderStringDefs", "You are not admin of the forum");
break; break;
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS:
errorText = QApplication::translate("FeedReaderStringDefs", "The forum is no anonymous forum");
break;
case RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR: case RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR:
errorText = QApplication::translate("FeedReaderStringDefs", "Can't read html"); errorText = QApplication::translate("FeedReaderStringDefs", "Can't read html");

View File

@ -45,7 +45,6 @@ enum RsFeedReaderErrorState {
RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE = 100, RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE = 100,
RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND = 101, RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND = 101,
RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN = 102, RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN = 102,
RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS = 103,
RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR = 150, RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR = 150,
RS_FEED_ERRORSTATE_PROCESS_XPATH_INTERNAL_ERROR = 151, RS_FEED_ERRORSTATE_PROCESS_XPATH_INTERNAL_ERROR = 151,
@ -218,6 +217,7 @@ public:
virtual bool processFeed(const std::string &feedId) = 0; virtual bool processFeed(const std::string &feedId) = 0;
virtual bool setMessageRead(const std::string &feedId, const std::string &msgId, bool read) = 0; virtual bool setMessageRead(const std::string &feedId, const std::string &msgId, bool read) = 0;
virtual bool retransformMsg(const std::string &feedId, const std::string &msgId) = 0; virtual bool retransformMsg(const std::string &feedId, const std::string &msgId) = 0;
virtual bool clearMessageCache(const std::string &feedId) = 0;
virtual RsFeedReaderErrorState processXPath(const std::list<std::string> &xpathsToUse, const std::list<std::string> &xpathsToRemove, std::string &description, std::string &errorString) = 0; virtual RsFeedReaderErrorState processXPath(const std::list<std::string> &xpathsToUse, const std::list<std::string> &xpathsToRemove, std::string &description, std::string &errorString) = 0;
virtual RsFeedReaderErrorState processXslt(const std::string &xslt, std::string &description, std::string &errorString) = 0; virtual RsFeedReaderErrorState processXslt(const std::string &xslt, std::string &description, std::string &errorString) = 0;

View File

@ -24,20 +24,24 @@
#include "p3FeedReaderThread.h" #include "p3FeedReaderThread.h"
#include "serialiser/rsconfigitems.h" #include "serialiser/rsconfigitems.h"
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
//Todo: Replace with gxs forums #include "retroshare/rsgxsforums.h"
//#include "retroshare/rsforums.h"
#include "util/rsstring.h" #include "util/rsstring.h"
#include "gxs/rsgenexchange.h"
#include <unistd.h>
RsFeedReader *rsFeedReader = NULL; RsFeedReader *rsFeedReader = NULL;
#define FEEDREADER_CLEAN_INTERVAL 1 * 60 * 60 // check every hour #define FEEDREADER_CLEAN_INTERVAL 1 * 60 * 60 // check every hour
#define FEEDREADER_FORUM_PREFIX L"RSS: " #define FEEDREADER_FORUM_PREFIX "RSS: "
#define MAX_REQUEST_AGE 30 // 30 seconds
/********* /*********
* #define FEEDREADER_DEBUG * #define FEEDREADER_DEBUG
*********/ *********/
p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums) p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsGxsForums *forums)
: RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, 5, pgHandler), : RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, 5, pgHandler),
mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview") mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview")
{ {
@ -53,6 +57,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums)
mForums = forums; mForums = forums;
mNotify = NULL; mNotify = NULL;
mSaveInBackground = false; mSaveInBackground = false;
mStopped = false;
mPreviewDownloadThread = NULL; mPreviewDownloadThread = NULL;
mPreviewProcessThread = NULL; mPreviewProcessThread = NULL;
@ -129,7 +134,7 @@ static void feedToInfo(const RsFeedReaderFeed *feed, FeedInfo &info)
} }
} }
static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add) static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed)
{ {
// feed->feedId = info.feedId; // feed->feedId = info.feedId;
feed->parentId = info.parentId; feed->parentId = info.parentId;
@ -144,10 +149,8 @@ static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add)
feed->updateInterval = info.updateInterval; feed->updateInterval = info.updateInterval;
// feed->lastUpdate = info.lastUpdate; // feed->lastUpdate = info.lastUpdate;
feed->storageTime = info.storageTime; feed->storageTime = info.storageTime;
if (add) {
/* set forum id only when adding a feed */
feed->forumId = info.forumId; feed->forumId = info.forumId;
}
feed->transformationType = info.transformationType; feed->transformationType = info.transformationType;
feed->xpathsToUse.ids = info.xpathsToUse; feed->xpathsToUse.ids = info.xpathsToUse;
@ -156,7 +159,6 @@ static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add)
// feed->preview = info.flag.preview; // feed->preview = info.flag.preview;
uint32_t oldFlag = feed->flag;
feed->flag = 0; feed->flag = 0;
if (info.flag.infoFromFeed) { if (info.flag.infoFromFeed) {
feed->flag |= RS_FEED_FLAG_INFO_FROM_FEED; feed->flag |= RS_FEED_FLAG_INFO_FROM_FEED;
@ -182,18 +184,12 @@ static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add)
if (info.flag.saveCompletePage) { if (info.flag.saveCompletePage) {
feed->flag |= RS_FEED_FLAG_SAVE_COMPLETE_PAGE; feed->flag |= RS_FEED_FLAG_SAVE_COMPLETE_PAGE;
} }
if (add) {
/* only set when adding a new feed */
if (info.flag.folder) { if (info.flag.folder) {
feed->flag |= RS_FEED_FLAG_FOLDER; feed->flag |= RS_FEED_FLAG_FOLDER;
} }
if (info.flag.forum) { if (info.flag.forum) {
feed->flag |= RS_FEED_FLAG_FORUM; feed->flag |= RS_FEED_FLAG_FORUM;
} }
} else {
/* use old bits */
feed->flag |= (oldFlag & (RS_FEED_FLAG_FOLDER | RS_FEED_FLAG_FORUM));
}
if (info.flag.updateForumInfo) { if (info.flag.updateForumInfo) {
feed->flag |= RS_FEED_FLAG_UPDATE_FORUM_INFO; feed->flag |= RS_FEED_FLAG_UPDATE_FORUM_INFO;
} }
@ -311,6 +307,8 @@ void p3FeedReader::setSaveInBackground(bool saveInBackground)
void p3FeedReader::stop() void p3FeedReader::stop()
{ {
mStopped = true;
{ {
RsStackMutex stack(mPreviewMutex); /******* LOCK STACK MUTEX *********/ RsStackMutex stack(mPreviewMutex); /******* LOCK STACK MUTEX *********/
@ -458,7 +456,7 @@ RsFeedAddResult p3FeedReader::addFeed(const FeedInfo &feedInfo, std::string &fee
} }
RsFeedReaderFeed *fi = new RsFeedReaderFeed; RsFeedReaderFeed *fi = new RsFeedReaderFeed;
infoToFeed(feedInfo, fi, true); infoToFeed(feedInfo, fi);
rs_sprintf(fi->feedId, "%lu", mNextFeedId++); rs_sprintf(fi->feedId, "%lu", mNextFeedId++);
mFeeds[fi->feedId] = fi; mFeeds[fi->feedId] = fi;
@ -478,8 +476,8 @@ RsFeedAddResult p3FeedReader::addFeed(const FeedInfo &feedInfo, std::string &fee
RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo &feedInfo) RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo &feedInfo)
{ {
std::string forumId; std::string forumId;
//Todo: Replace with gxs forums std::string forumName;
// ForumInfo forumInfo; std::string forumDescription;
{ {
RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/ RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/
@ -522,20 +520,20 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo
} }
RsFeedReaderFeed *fi = feedIt->second; RsFeedReaderFeed *fi = feedIt->second;
std::string oldForumId = fi->forumId;
std::string oldName = fi->name; std::string oldName = fi->name;
std::string oldDescription = fi->description; std::string oldDescription = fi->description;
infoToFeed(feedInfo, fi, false); infoToFeed(feedInfo, fi);
//Todo: Replace with gxs forums if ((fi->flag & RS_FEED_FLAG_FORUM) && (fi->flag & RS_FEED_FLAG_UPDATE_FORUM_INFO) && !fi->forumId.empty() &&
// if ((fi->flag & RS_FEED_FLAG_FORUM) && (fi->flag & RS_FEED_FLAG_UPDATE_FORUM_INFO) && !fi->forumId.empty() && (fi->forumId != oldForumId || fi->name != oldName || fi->description != oldDescription)) {
// (fi->name != oldName || fi->description != oldDescription)) { /* name or description changed, update forum */
// /* name or description changed, update forum */ forumId = fi->forumId;
// forumId = fi->forumId; forumName = fi->name;
// librs::util::ConvertUtf8ToUtf16(fi->name, forumInfo.forumName); forumDescription = fi->description;
// librs::util::ConvertUtf8ToUtf16(fi->description, forumInfo.forumDesc); forumName.insert(0, FEEDREADER_FORUM_PREFIX);
// forumInfo.forumName.insert(0, FEEDREADER_FORUM_PREFIX); }
// }
} }
IndicateConfigChanged(); IndicateConfigChanged();
@ -544,19 +542,13 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo
mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD); mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD);
} }
//Todo: Replace with gxs forums if (!forumId.empty()) {
// if (!forumId.empty()) { RsGxsForumGroup forumGroup;
// if (mForums) { if (getForumGroup(RsGxsGroupId(forumId), forumGroup)) {
// /* name or description changed, update forum */ updateForumGroup(forumGroup, forumName, forumDescription);
// if (!mForums->setForumInfo(forumId, forumInfo)) { }
//#ifdef FEEDREADER_DEBUG //TODO: error
// std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; }
//#endif
// }
// } else {
// std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << ", member mForums is not set" << std::endl;
// }
// }
return RS_FEED_ADD_RESULT_SUCCESS; return RS_FEED_ADD_RESULT_SUCCESS;
} }
@ -677,7 +669,7 @@ bool p3FeedReader::addPreviewFeed(const FeedInfo &feedInfo, std::string &feedId)
#endif #endif
RsFeedReaderFeed *fi = new RsFeedReaderFeed; RsFeedReaderFeed *fi = new RsFeedReaderFeed;
infoToFeed(feedInfo, fi, true); infoToFeed(feedInfo, fi);
rs_sprintf(fi->feedId, "preview%d", mNextPreviewFeedId--); rs_sprintf(fi->feedId, "preview%d", mNextPreviewFeedId--);
fi->preview = true; fi->preview = true;
@ -1234,6 +1226,51 @@ bool p3FeedReader::retransformMsg(const std::string &feedId, const std::string &
return true; return true;
} }
bool p3FeedReader::clearMessageCache(const std::string &feedId)
{
{
RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::clearMessageCache - feed id " << feedId << std::endl;
#endif
std::map<std::string, RsFeedReaderFeed*>::iterator feedIt = mFeeds.find(feedId);
if (feedIt == mFeeds.end()) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::clearMessageCache - feed id " << feedId << " not found" << std::endl;
#endif
return false;
}
if (feedIt->second->flag & RS_FEED_FLAG_FOLDER) {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::clearMessageCache - feed " << feedIt->second->name << " is a folder" << std::endl;
#endif
return false;
}
RsFeedReaderFeed *fi = feedIt->second;
std::map<std::string, RsFeedReaderMsg*>::iterator msgIt;
for (msgIt = fi->msgs.begin(); msgIt != fi->msgs.end(); ) {
RsFeedReaderMsg *mi = msgIt->second;
if (mi->flag & RS_FEEDMSG_FLAG_DELETED) {
delete(mi);
std::map<std::string, RsFeedReaderMsg*>::iterator deleteIt = msgIt++;
fi->msgs.erase(deleteIt);
continue;
}
++msgIt;
}
}
IndicateConfigChanged();
return true;
}
RsFeedReaderErrorState p3FeedReader::processXPath(const std::list<std::string> &xpathsToUse, const std::list<std::string> &xpathsToRemove, std::string &description, std::string &errorString) RsFeedReaderErrorState p3FeedReader::processXPath(const std::list<std::string> &xpathsToUse, const std::list<std::string> &xpathsToRemove, std::string &description, std::string &errorString)
{ {
return p3FeedReaderThread::processXPath(xpathsToUse, xpathsToRemove, description, errorString); return p3FeedReaderThread::processXPath(xpathsToUse, xpathsToRemove, description, errorString);
@ -1854,6 +1891,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
std::list<std::string> addedMsgs; std::list<std::string> addedMsgs;
std::string forumId; std::string forumId;
RsGxsId authorId;
std::list<RsFeedReaderMsg> forumMsgs; std::list<RsFeedReaderMsg> forumMsgs;
{ {
@ -1873,65 +1911,29 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
bool forum = (fi->flag & RS_FEED_FLAG_FORUM) && !fi->preview; bool forum = (fi->flag & RS_FEED_FLAG_FORUM) && !fi->preview;
RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK; RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK;
//Todo: Replace with gxs forums
#if 0
if (forum && !msgs.empty()) { if (forum && !msgs.empty()) {
if (mForums) { if (mForums) {
if (fi->forumId.empty()) { if (!fi->forumId.empty()) {
/* create new forum */
std::wstring forumName;
librs::util::ConvertUtf8ToUtf16(fi->name, forumName);
forumName.insert(0, FEEDREADER_FORUM_PREFIX);
long todo; // search for existing forum?
/* search for existing own forum */
// std::list<ForumInfo> forumList;
// if (mForums->getForumList(forumList)) {
// std::wstring wName = StringToWString(name);
// for (std::list<ForumInfo>::iterator it = forumList.begin(); it != forumList.end(); ++it) {
// if (it->forumName == wName) {
// std::cout << "DEBUG_RSS2FORUM: Found existing forum " << it->forumId << " for " << name << std::endl;
// return it->forumId;
// }
// }
// }
std::wstring forumDescription;
librs::util::ConvertUtf8ToUtf16(fi->description, forumDescription);
/* create anonymous public forum */
fi->forumId = mForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON);
forumId = fi->forumId;
if (fi->forumId.empty()) {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE;
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't create forum for feed " << feedId << " (" << fi->name << ") - ignore all messages" << std::endl;
} else {
std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - forum " << fi->forumId << " (" << fi->name << ") created" << std::endl;
#endif
}
} else {
/* check forum */ /* check forum */
ForumInfo forumInfo; RsGxsForumGroup forumGroup;
if (mForums->getForumInfo(fi->forumId, forumInfo)) { if (getForumGroup(RsGxsGroupId(fi->forumId), forumGroup)) {
if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) == 0) { if (IS_GROUP_PUBLISHER(forumGroup.mMeta.mSubscribeFlags) && IS_GROUP_ADMIN(forumGroup.mMeta.mSubscribeFlags)) {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN;
} else if ((forumInfo.forumFlags & RS_DISTRIB_AUTHEN_REQ) || (forumInfo.forumFlags & RS_DISTRIB_AUTHEN_ANON) == 0) {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS;
} else {
forumId = fi->forumId; forumId = fi->forumId;
authorId = forumGroup.mMeta.mAuthorId;
} else {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN;
} }
} else { } else {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND; errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND;
} }
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - forum id is empty (" << fi->name << ")" << std::endl;
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND;
} }
} else { } else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl; std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
} }
} }
#endif
/* process msgs */ /* process msgs */
if (errorState == RS_FEED_ERRORSTATE_OK) { if (errorState == RS_FEED_ERRORSTATE_OK) {
@ -1982,39 +1984,49 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
} }
} }
//Todo: Replace with gxs forums if (!forumId.empty() && !forumMsgs.empty()) {
// if (!forumId.empty() && !forumMsgs.empty()) { if (mForums) {
// if (mForums) { /* a bit tricky */
// /* add messages as forum messages */ RsGenExchange *genExchange = dynamic_cast<RsGenExchange*>(mForums);
// std::list<RsFeedReaderMsg>::iterator msgIt; if (genExchange) {
// for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) { /* add messages as forum messages */
// RsFeedReaderMsg &mi = *msgIt; std::list<RsFeedReaderMsg>::iterator msgIt;
for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) {
RsFeedReaderMsg &mi = *msgIt;
// /* convert to forum messages */ /* convert to forum messages */
// ForumMsgInfo forumMsgInfo; RsGxsForumMsg forumMsg;
// forumMsgInfo.forumId = forumId; forumMsg.mMeta.mGroupId = RsGxsGroupId(forumId);
// librs::util::ConvertUtf8ToUtf16(mi.title, forumMsgInfo.title); forumMsg.mMeta.mMsgName = mi.title;
forumMsg.mMeta.mAuthorId = authorId;
// std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed;
// /* add link */ /* add link */
// if (!mi.link.empty()) { if (!mi.link.empty()) {
// description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>"; description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>";
// } }
// librs::util::ConvertUtf8ToUtf16(description, forumMsgInfo.msg); forumMsg.mMsg = description;
// if (mForums->ForumMessageSend(forumMsgInfo)) { uint32_t token;
// /* set to new */ if (mForums->createMsg(token, forumMsg) && waitForToken(token)) {
// mForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK); RsGxsGrpMsgIdPair msgPair;
// } else { if (mForums->acknowledgeMsg(token, msgPair)) {
//#ifdef FEEDREADER_DEBUG /* set to new */
// std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl; genExchange->setMsgStatusFlags(token, msgPair, GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD, GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD);
//#endif }
// } } else {
// } #ifdef FEEDREADER_DEBUG
// } else { std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't add forum message " << mi.title << " for feed " << forumId << std::endl;
// std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl; #endif
// } }
// } }
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not derived from RsGenExchange" << std::endl;
}
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
}
}
if (mNotify) { if (mNotify) {
mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD); mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD);
@ -2068,8 +2080,8 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
bool changed = false; bool changed = false;
bool preview; bool preview;
std::string forumId; std::string forumId;
//Todo: Replace with gxs forums std::string forumName;
// ForumInfo forumInfoNew; std::string forumDescription;
{ {
RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/ RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/
@ -2101,14 +2113,13 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
changed = true; changed = true;
} }
//Todo: Replace with gxs forums if ((fi->flag & RS_FEED_FLAG_FORUM) && (fi->flag & RS_FEED_FLAG_UPDATE_FORUM_INFO) && !fi->forumId.empty() && !preview) {
// if ((fi->flag & RS_FEED_FLAG_FORUM) && (fi->flag & RS_FEED_FLAG_UPDATE_FORUM_INFO) && !fi->forumId.empty() && !preview) { /* change forum too */
// /* change forum too */ forumId = fi->forumId;
// forumId = fi->forumId; forumName = fi->name;
// librs::util::ConvertUtf8ToUtf16(fi->name, forumInfoNew.forumName); forumDescription = fi->description;
// librs::util::ConvertUtf8ToUtf16(fi->description, forumInfoNew.forumDesc); forumName.insert(0, FEEDREADER_FORUM_PREFIX);
// forumInfoNew.forumName.insert(0, FEEDREADER_FORUM_PREFIX); }
// }
} }
if (changed) { if (changed) {
@ -2121,29 +2132,112 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
} }
} }
//Todo: Replace with gxs forums if (!forumId.empty()) {
// if (!forumId.empty()) { RsGxsForumGroup forumGroup;
// if (mForums) { if (getForumGroup(RsGxsGroupId(forumId), forumGroup)) {
// ForumInfo forumInfo; updateForumGroup(forumGroup, forumName, forumDescription);
// if (mForums->getForumInfo(forumId, forumInfo)) { }
// if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) { //TODO: error
// /* name or description changed, update forum */ }
//#ifdef FEEDREADER_DEBUG }
// std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl;
//#endif bool p3FeedReader::getForumGroup(const RsGxsGroupId &groupId, RsGxsForumGroup &forumGroup)
// if (!mForums->setForumInfo(forumId, forumInfoNew)) { {
//#ifdef FEEDREADER_DEBUG if (!mForums) {
// std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; std::cerr << "p3FeedReader::getForumGroup - can't get forum group " << groupId.toStdString() << ", member mForums is not set" << std::endl;
//#endif return false;
// } }
// }
// } else { if (groupId.isNull()) {
//#ifdef FEEDREADER_DEBUG std::cerr << "p3FeedReader::getForumGroup - group id is not valid" << std::endl;
// std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl; return false;
//#endif }
// }
// } else { std::list<RsGxsGroupId> grpIds;
// std::cerr << "p3FeedReader::setFeedInfo - can't process forum, member mForums is not set" << std::endl; grpIds.push_back(groupId);
// }
// } RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mForums->getTokenService()->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds);
if (!waitForToken(token)) {
std::cerr << "p3FeedReader::getForumGroup - waitForToken for request failed" << std::endl;
return false;
}
std::vector<RsGxsForumGroup> groups;
if (!mForums->getGroupData(token, groups)) {
std::cerr << "p3FeedReader::getForumGroup - Error getting data" << std::endl;
return false;
}
if (groups.size() != 1) {
std::cerr << "p3FeedReader::getForumGroup - Wrong number of items" << std::endl;
return false;
}
forumGroup = groups[0];
return true;
}
bool p3FeedReader::updateForumGroup(const RsGxsForumGroup &forumGroup, const std::string &groupName, const std::string &groupDescription)
{
if (!mForums) {
std::cerr << "p3FeedReader::updateForumGroup - can't change forum " << forumGroup.mMeta.mGroupId.toStdString() << ", member mForums is not set" << std::endl;
return false;
}
if (forumGroup.mMeta.mGroupName == groupName && forumGroup.mDescription == groupDescription) {
/* No change */
return true;
}
RsGxsForumGroup newForumGroup = forumGroup;
newForumGroup.mMeta.mGroupName = groupName;
newForumGroup.mDescription = groupDescription;
uint32_t token;
if (!mForums->updateGroup(token, newForumGroup)) {
std::cerr << "p3FeedReader::updateForumGroup - can't change forum " << newForumGroup.mMeta.mGroupId.toStdString() << std::endl;
return false;
}
if (!waitForToken(token)) {
std::cerr << "p3FeedReader::updateForumGroup - waitForToken for update failed" << std::endl;
return false;
}
/* Forum updated */
return true;
}
bool p3FeedReader::waitForToken(uint32_t token)
{
if (!mForums) {
return false;
}
RsTokenService *service = mForums->getTokenService();
int count = MAX_REQUEST_AGE * 2;
while (!mStopped) {
uint32_t status = service->requestStatus(token);
if (status == RsTokenService::GXS_REQUEST_V2_STATUS_FAILED) {
break;
}
if (status == RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE) {
return true;
}
if (count-- <= 0) {
break;
}
usleep(500 * 1000); // sleep for 500 msec
}
return false;
} }

View File

@ -26,17 +26,19 @@
#include "plugins/rspqiservice.h" #include "plugins/rspqiservice.h"
#include "interface/rsFeedReader.h" #include "interface/rsFeedReader.h"
#include "retroshare/rsgxsifacetypes.h"
class RsFeedReaderFeed; class RsFeedReaderFeed;
class RsFeedReaderMsg; class RsFeedReaderMsg;
class p3FeedReaderThread; class p3FeedReaderThread;
//Todo: Replace with gxs forums class RsGxsForums;
class RsForums; class RsGxsForumGroup;
class p3FeedReader : public RsPQIService, public RsFeedReader class p3FeedReader : public RsPQIService, public RsFeedReader
{ {
public: public:
p3FeedReader(RsPluginHandler *pgHandler, RsForums *forums); p3FeedReader(RsPluginHandler *pgHandler, RsGxsForums *forums);
/****************** FeedReader Interface *************/ /****************** FeedReader Interface *************/
virtual void stop(); virtual void stop();
@ -68,6 +70,7 @@ public:
virtual bool processFeed(const std::string &feedId); virtual bool processFeed(const std::string &feedId);
virtual bool setMessageRead(const std::string &feedId, const std::string &msgId, bool read); virtual bool setMessageRead(const std::string &feedId, const std::string &msgId, bool read);
virtual bool retransformMsg(const std::string &feedId, const std::string &msgId); virtual bool retransformMsg(const std::string &feedId, const std::string &msgId);
virtual bool clearMessageCache(const std::string &feedId);
virtual RsFeedReaderErrorState processXPath(const std::list<std::string> &xpathsToUse, const std::list<std::string> &xpathsToRemove, std::string &description, std::string &errorString); virtual RsFeedReaderErrorState processXPath(const std::list<std::string> &xpathsToUse, const std::list<std::string> &xpathsToRemove, std::string &description, std::string &errorString);
virtual RsFeedReaderErrorState processXslt(const std::string &xslt, std::string &description, std::string &errorString); virtual RsFeedReaderErrorState processXslt(const std::string &xslt, std::string &description, std::string &errorString);
@ -88,6 +91,10 @@ public:
void setFeedInfo(const std::string &feedId, const std::string &name, const std::string &description); void setFeedInfo(const std::string &feedId, const std::string &name, const std::string &description);
bool getForumGroup(const RsGxsGroupId &groupId, RsGxsForumGroup &forumGroup);
bool updateForumGroup(const RsGxsForumGroup &forumGroup, const std::string &groupName, const std::string &groupDescription);
bool waitForToken(uint32_t token);
protected: protected:
/****************** p3Config STUFF *******************/ /****************** p3Config STUFF *******************/
virtual RsSerialiser *setupSerialiser(); virtual RsSerialiser *setupSerialiser();
@ -100,9 +107,11 @@ private:
void deleteAllMsgs_locked(RsFeedReaderFeed *fi); void deleteAllMsgs_locked(RsFeedReaderFeed *fi);
void stopPreviewThreads_locked(); void stopPreviewThreads_locked();
private:
time_t mLastClean; time_t mLastClean;
RsForums *mForums; RsGxsForums *mForums;
RsFeedReaderNotify *mNotify; RsFeedReaderNotify *mNotify;
volatile bool mStopped;
RsMutex mFeedReaderMtx; RsMutex mFeedReaderMtx;
std::list<RsItem*> cleanSaveData; std::list<RsItem*> cleanSaveData;