mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
30d9671ca6
commit
069e8e490a
@ -87,8 +87,7 @@ void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
|
||||
{
|
||||
mInterfaces = interfaces;
|
||||
|
||||
//Todo: Replace with gxs forums
|
||||
mFeedReader = new p3FeedReader(mPlugInHandler, NULL /*mInterfaces.mForums*/);
|
||||
mFeedReader = new p3FeedReader(mPlugInHandler, mInterfaces.mGxsForums);
|
||||
rsFeedReader = mFeedReader;
|
||||
|
||||
mNotify = new FeedReaderNotify();
|
||||
|
@ -28,20 +28,28 @@
|
||||
#include "PreviewFeedDialog.h"
|
||||
#include "FeedReaderStringDefs.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "gui/common/UIStateHelper.h"
|
||||
|
||||
//Todo: Replace with gxs forums
|
||||
//#include "retroshare/rsforums.h"
|
||||
#include <retroshare/rsgxsforums.h>
|
||||
#include <iostream>
|
||||
|
||||
//bool sortForumInfo(const ForumInfo& info1, const ForumInfo& info2)
|
||||
//{
|
||||
// return QString::fromStdWString(info1.forumName).compare(QString::fromStdWString(info2.forumName), Qt::CaseInsensitive);
|
||||
//}
|
||||
#define TOKEN_TYPE_FORUM_GROUPS 1
|
||||
|
||||
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
|
||||
: QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
|
||||
{
|
||||
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::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->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->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->typeLocalRadio, 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->setHeaderImage(QPixmap(":/images/FeedReader.png"));
|
||||
|
||||
ui->activatedCheckBox->setChecked(true);
|
||||
ui->forumComboBox->setEnabled(false);
|
||||
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
|
||||
ui->useInfoFromFeedCheckBox->setChecked(true);
|
||||
ui->updateForumInfoCheckBox->setEnabled(false);
|
||||
ui->updateForumInfoCheckBox->setChecked(true);
|
||||
ui->forumNameLabel->hide();
|
||||
ui->useAuthenticationCheckBox->setChecked(false);
|
||||
ui->useStandardStorageTimeCheckBox->setChecked(true);
|
||||
ui->useStandardUpdateInterval->setChecked(true);
|
||||
@ -81,22 +91,10 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
|
||||
mTransformationType = RS_FEED_TRANSFORMATION_TYPE_NONE;
|
||||
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
|
||||
|
||||
ui->clearCachePushButton->show();
|
||||
|
||||
/* fill own forums */
|
||||
//Todo: Replace with gxs forums
|
||||
// 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);
|
||||
requestForumGroups();
|
||||
|
||||
validate();
|
||||
|
||||
@ -104,9 +102,6 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
|
||||
|
||||
/* load settings */
|
||||
processSettings(true);
|
||||
|
||||
//Todo: Replace with gxs forums
|
||||
ui->typeForumRadio->setEnabled(false);
|
||||
}
|
||||
|
||||
AddFeedDialog::~AddFeedDialog()
|
||||
@ -114,7 +109,8 @@ AddFeedDialog::~AddFeedDialog()
|
||||
/* save settings */
|
||||
processSettings(false);
|
||||
|
||||
delete ui;
|
||||
delete(ui);
|
||||
delete(mTokenQueue);
|
||||
}
|
||||
|
||||
void AddFeedDialog::processSettings(bool load)
|
||||
@ -164,7 +160,7 @@ void AddFeedDialog::useStandardProxyToggled()
|
||||
void AddFeedDialog::typeForumToggled()
|
||||
{
|
||||
bool checked = ui->typeForumRadio->isChecked();
|
||||
ui->forumComboBox->setEnabled(checked);
|
||||
mStateHelper->setWidgetEnabled(ui->forumComboBox, checked);
|
||||
ui->updateForumInfoCheckBox->setEnabled(checked);
|
||||
}
|
||||
|
||||
@ -195,7 +191,11 @@ void AddFeedDialog::validate()
|
||||
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)
|
||||
@ -215,7 +215,6 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
|
||||
}
|
||||
|
||||
setWindowTitle(tr("Edit feed"));
|
||||
ui->typeGroupBox->setEnabled(false);
|
||||
|
||||
mParentId = feedInfo.parentId;
|
||||
|
||||
@ -229,28 +228,15 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
|
||||
|
||||
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) {
|
||||
mStateHelper->setWidgetEnabled(ui->forumComboBox, true);
|
||||
ui->typeForumRadio->setChecked(true);
|
||||
ui->saveCompletePageCheckBox->setEnabled(false);
|
||||
|
||||
if (feedInfo.forumId.empty()) {
|
||||
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"));
|
||||
// }
|
||||
}
|
||||
setActiveForumId(feedInfo.forumId);
|
||||
} else {
|
||||
ui->typeLocalRadio->setChecked(true);
|
||||
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
|
||||
}
|
||||
|
||||
ui->useAuthenticationCheckBox->setChecked(feedInfo.flag.authentication);
|
||||
@ -276,11 +262,28 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
|
||||
mXslt = feedInfo.xslt;
|
||||
|
||||
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
|
||||
|
||||
ui->clearCachePushButton->show();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
feedInfo.parentId = mParentId;
|
||||
@ -296,11 +299,9 @@ void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
|
||||
feedInfo.description = ui->descriptionPlainTextEdit->toPlainText().toUtf8().constData();
|
||||
|
||||
feedInfo.flag.forum = ui->typeForumRadio->isChecked();
|
||||
if (mFeedId.empty()) {
|
||||
if (feedInfo.flag.forum) {
|
||||
/* set forum (only when create a new feed) */
|
||||
feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString();
|
||||
}
|
||||
|
||||
if (feedInfo.flag.forum) {
|
||||
feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString();
|
||||
}
|
||||
|
||||
feedInfo.flag.authentication = ui->useAuthenticationCheckBox->isChecked();
|
||||
@ -362,3 +363,72 @@ void AddFeedDialog::preview()
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include "interface/rsFeedReader.h"
|
||||
#include "util/TokenQueue.h"
|
||||
|
||||
namespace Ui {
|
||||
class AddFeedDialog;
|
||||
@ -31,8 +32,9 @@ class AddFeedDialog;
|
||||
|
||||
class RsFeedReader;
|
||||
class FeedReaderNotify;
|
||||
class UIStateHelper;
|
||||
|
||||
class AddFeedDialog : public QDialog
|
||||
class AddFeedDialog : public QDialog, public TokenResponse
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -43,6 +45,9 @@ public:
|
||||
void setParent(const std::string &parentId);
|
||||
bool fillFeed(const std::string &feedId);
|
||||
|
||||
/* TokenResponse */
|
||||
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
|
||||
|
||||
private slots:
|
||||
void authenticationToggled();
|
||||
void useStandardStorageTimeToggled();
|
||||
@ -53,21 +58,31 @@ private slots:
|
||||
void validate();
|
||||
void createFeed();
|
||||
void preview();
|
||||
void clearMessageCache();
|
||||
|
||||
private:
|
||||
void processSettings(bool load);
|
||||
void getFeedInfo(FeedInfo &feedInfo);
|
||||
void setActiveForumId(const std::string &forumId);
|
||||
|
||||
void requestForumGroups();
|
||||
void loadForumGroups(const uint32_t &token);
|
||||
|
||||
private:
|
||||
RsFeedReader *mFeedReader;
|
||||
FeedReaderNotify *mNotify;
|
||||
std::string mFeedId;
|
||||
std::string mParentId;
|
||||
std::string mFillForumId;
|
||||
|
||||
RsFeedTransformationType mTransformationType;
|
||||
std::list<std::string> mXPathsToUse;
|
||||
std::list<std::string> mXPathsToRemove;
|
||||
std::string mXslt;
|
||||
|
||||
TokenQueue *mTokenQueue;
|
||||
UIStateHelper *mStateHelper;
|
||||
|
||||
Ui::AddFeedDialog *ui;
|
||||
};
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
<string>Create new feed</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../../retroshare-gui/src/gui/images.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@ -75,19 +75,6 @@
|
||||
<item>
|
||||
<widget class="QComboBox" name="forumComboBox"/>
|
||||
</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>
|
||||
</item>
|
||||
<item>
|
||||
@ -146,13 +133,6 @@
|
||||
<string>Storage time</string>
|
||||
</property>
|
||||
<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">
|
||||
<widget class="QLabel" name="storageTimeLabel">
|
||||
<property name="text">
|
||||
@ -173,6 +153,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
@ -433,8 +427,6 @@
|
||||
<tabstop>proxyPortSpinBox</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../../retroshare-gui/src/gui/images.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -119,9 +119,6 @@ QString FeedReaderStringDefs::errorString(RsFeedReaderErrorState errorState, con
|
||||
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN:
|
||||
errorText = QApplication::translate("FeedReaderStringDefs", "You are not admin of the forum");
|
||||
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:
|
||||
errorText = QApplication::translate("FeedReaderStringDefs", "Can't read html");
|
||||
|
@ -45,7 +45,6 @@ enum RsFeedReaderErrorState {
|
||||
RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE = 100,
|
||||
RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND = 101,
|
||||
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_XPATH_INTERNAL_ERROR = 151,
|
||||
@ -218,6 +217,7 @@ public:
|
||||
virtual bool processFeed(const std::string &feedId) = 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 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 processXslt(const std::string &xslt, std::string &description, std::string &errorString) = 0;
|
||||
|
@ -24,20 +24,24 @@
|
||||
#include "p3FeedReaderThread.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
#include "retroshare/rsiface.h"
|
||||
//Todo: Replace with gxs forums
|
||||
//#include "retroshare/rsforums.h"
|
||||
#include "retroshare/rsgxsforums.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "gxs/rsgenexchange.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
RsFeedReader *rsFeedReader = NULL;
|
||||
|
||||
#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
|
||||
*********/
|
||||
|
||||
p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums)
|
||||
p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsGxsForums *forums)
|
||||
: RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, 5, pgHandler),
|
||||
mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview")
|
||||
{
|
||||
@ -53,6 +57,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums)
|
||||
mForums = forums;
|
||||
mNotify = NULL;
|
||||
mSaveInBackground = false;
|
||||
mStopped = false;
|
||||
|
||||
mPreviewDownloadThread = 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->parentId = info.parentId;
|
||||
@ -144,10 +149,8 @@ static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add)
|
||||
feed->updateInterval = info.updateInterval;
|
||||
// feed->lastUpdate = info.lastUpdate;
|
||||
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->xpathsToUse.ids = info.xpathsToUse;
|
||||
@ -156,7 +159,6 @@ static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add)
|
||||
|
||||
// feed->preview = info.flag.preview;
|
||||
|
||||
uint32_t oldFlag = feed->flag;
|
||||
feed->flag = 0;
|
||||
if (info.flag.infoFromFeed) {
|
||||
feed->flag |= RS_FEED_FLAG_INFO_FROM_FEED;
|
||||
@ -182,17 +184,11 @@ static void infoToFeed(const FeedInfo &info, RsFeedReaderFeed *feed, bool add)
|
||||
if (info.flag.saveCompletePage) {
|
||||
feed->flag |= RS_FEED_FLAG_SAVE_COMPLETE_PAGE;
|
||||
}
|
||||
if (add) {
|
||||
/* only set when adding a new feed */
|
||||
if (info.flag.folder) {
|
||||
feed->flag |= RS_FEED_FLAG_FOLDER;
|
||||
}
|
||||
if (info.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.folder) {
|
||||
feed->flag |= RS_FEED_FLAG_FOLDER;
|
||||
}
|
||||
if (info.flag.forum) {
|
||||
feed->flag |= RS_FEED_FLAG_FORUM;
|
||||
}
|
||||
if (info.flag.updateForumInfo) {
|
||||
feed->flag |= RS_FEED_FLAG_UPDATE_FORUM_INFO;
|
||||
@ -311,6 +307,8 @@ void p3FeedReader::setSaveInBackground(bool saveInBackground)
|
||||
|
||||
void p3FeedReader::stop()
|
||||
{
|
||||
mStopped = true;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mPreviewMutex); /******* LOCK STACK MUTEX *********/
|
||||
|
||||
@ -458,7 +456,7 @@ RsFeedAddResult p3FeedReader::addFeed(const FeedInfo &feedInfo, std::string &fee
|
||||
}
|
||||
|
||||
RsFeedReaderFeed *fi = new RsFeedReaderFeed;
|
||||
infoToFeed(feedInfo, fi, true);
|
||||
infoToFeed(feedInfo, fi);
|
||||
rs_sprintf(fi->feedId, "%lu", mNextFeedId++);
|
||||
|
||||
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)
|
||||
{
|
||||
std::string forumId;
|
||||
//Todo: Replace with gxs forums
|
||||
// ForumInfo forumInfo;
|
||||
std::string forumName;
|
||||
std::string forumDescription;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/
|
||||
@ -522,20 +520,20 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo
|
||||
}
|
||||
|
||||
RsFeedReaderFeed *fi = feedIt->second;
|
||||
std::string oldForumId = fi->forumId;
|
||||
std::string oldName = fi->name;
|
||||
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() &&
|
||||
// (fi->name != oldName || fi->description != oldDescription)) {
|
||||
// /* name or description changed, update forum */
|
||||
// forumId = fi->forumId;
|
||||
// librs::util::ConvertUtf8ToUtf16(fi->name, forumInfo.forumName);
|
||||
// librs::util::ConvertUtf8ToUtf16(fi->description, forumInfo.forumDesc);
|
||||
// forumInfo.forumName.insert(0, FEEDREADER_FORUM_PREFIX);
|
||||
// }
|
||||
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)) {
|
||||
/* name or description changed, update forum */
|
||||
forumId = fi->forumId;
|
||||
forumName = fi->name;
|
||||
forumDescription = fi->description;
|
||||
forumName.insert(0, FEEDREADER_FORUM_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
IndicateConfigChanged();
|
||||
@ -544,19 +542,13 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo
|
||||
mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD);
|
||||
}
|
||||
|
||||
//Todo: Replace with gxs forums
|
||||
// if (!forumId.empty()) {
|
||||
// if (mForums) {
|
||||
// /* name or description changed, update forum */
|
||||
// if (!mForums->setForumInfo(forumId, forumInfo)) {
|
||||
//#ifdef FEEDREADER_DEBUG
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
if (!forumId.empty()) {
|
||||
RsGxsForumGroup forumGroup;
|
||||
if (getForumGroup(RsGxsGroupId(forumId), forumGroup)) {
|
||||
updateForumGroup(forumGroup, forumName, forumDescription);
|
||||
}
|
||||
//TODO: error
|
||||
}
|
||||
|
||||
return RS_FEED_ADD_RESULT_SUCCESS;
|
||||
}
|
||||
@ -677,7 +669,7 @@ bool p3FeedReader::addPreviewFeed(const FeedInfo &feedInfo, std::string &feedId)
|
||||
#endif
|
||||
|
||||
RsFeedReaderFeed *fi = new RsFeedReaderFeed;
|
||||
infoToFeed(feedInfo, fi, true);
|
||||
infoToFeed(feedInfo, fi);
|
||||
rs_sprintf(fi->feedId, "preview%d", mNextPreviewFeedId--);
|
||||
fi->preview = true;
|
||||
|
||||
@ -1234,6 +1226,51 @@ bool p3FeedReader::retransformMsg(const std::string &feedId, const std::string &
|
||||
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)
|
||||
{
|
||||
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::string forumId;
|
||||
RsGxsId authorId;
|
||||
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;
|
||||
RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK;
|
||||
|
||||
//Todo: Replace with gxs forums
|
||||
#if 0
|
||||
if (forum && !msgs.empty()) {
|
||||
if (mForums) {
|
||||
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 {
|
||||
if (!fi->forumId.empty()) {
|
||||
/* check forum */
|
||||
ForumInfo forumInfo;
|
||||
if (mForums->getForumInfo(fi->forumId, forumInfo)) {
|
||||
if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) == 0) {
|
||||
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 {
|
||||
RsGxsForumGroup forumGroup;
|
||||
if (getForumGroup(RsGxsGroupId(fi->forumId), forumGroup)) {
|
||||
if (IS_GROUP_PUBLISHER(forumGroup.mMeta.mSubscribeFlags) && IS_GROUP_ADMIN(forumGroup.mMeta.mSubscribeFlags)) {
|
||||
forumId = fi->forumId;
|
||||
authorId = forumGroup.mMeta.mAuthorId;
|
||||
} else {
|
||||
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN;
|
||||
}
|
||||
} else {
|
||||
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 {
|
||||
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* process msgs */
|
||||
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 (mForums) {
|
||||
// /* add messages as forum messages */
|
||||
// std::list<RsFeedReaderMsg>::iterator msgIt;
|
||||
// for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) {
|
||||
// RsFeedReaderMsg &mi = *msgIt;
|
||||
if (!forumId.empty() && !forumMsgs.empty()) {
|
||||
if (mForums) {
|
||||
/* a bit tricky */
|
||||
RsGenExchange *genExchange = dynamic_cast<RsGenExchange*>(mForums);
|
||||
if (genExchange) {
|
||||
/* add messages as forum messages */
|
||||
std::list<RsFeedReaderMsg>::iterator msgIt;
|
||||
for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) {
|
||||
RsFeedReaderMsg &mi = *msgIt;
|
||||
|
||||
// /* convert to forum messages */
|
||||
// ForumMsgInfo forumMsgInfo;
|
||||
// forumMsgInfo.forumId = forumId;
|
||||
// librs::util::ConvertUtf8ToUtf16(mi.title, forumMsgInfo.title);
|
||||
/* convert to forum messages */
|
||||
RsGxsForumMsg forumMsg;
|
||||
forumMsg.mMeta.mGroupId = RsGxsGroupId(forumId);
|
||||
forumMsg.mMeta.mMsgName = mi.title;
|
||||
forumMsg.mMeta.mAuthorId = authorId;
|
||||
|
||||
// std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed;
|
||||
// /* add link */
|
||||
// if (!mi.link.empty()) {
|
||||
// description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>";
|
||||
// }
|
||||
// librs::util::ConvertUtf8ToUtf16(description, forumMsgInfo.msg);
|
||||
std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed;
|
||||
/* add link */
|
||||
if (!mi.link.empty()) {
|
||||
description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>";
|
||||
}
|
||||
forumMsg.mMsg = description;
|
||||
|
||||
// if (mForums->ForumMessageSend(forumMsgInfo)) {
|
||||
// /* set to new */
|
||||
// mForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK);
|
||||
// } else {
|
||||
//#ifdef FEEDREADER_DEBUG
|
||||
// std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
|
||||
// }
|
||||
// }
|
||||
uint32_t token;
|
||||
if (mForums->createMsg(token, forumMsg) && waitForToken(token)) {
|
||||
RsGxsGrpMsgIdPair msgPair;
|
||||
if (mForums->acknowledgeMsg(token, msgPair)) {
|
||||
/* set to new */
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
#ifdef FEEDREADER_DEBUG
|
||||
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't add forum message " << mi.title << " for feed " << forumId << 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) {
|
||||
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 preview;
|
||||
std::string forumId;
|
||||
//Todo: Replace with gxs forums
|
||||
// ForumInfo forumInfoNew;
|
||||
std::string forumName;
|
||||
std::string forumDescription;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/
|
||||
@ -2101,14 +2113,13 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
|
||||
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) {
|
||||
// /* change forum too */
|
||||
// forumId = fi->forumId;
|
||||
// librs::util::ConvertUtf8ToUtf16(fi->name, forumInfoNew.forumName);
|
||||
// librs::util::ConvertUtf8ToUtf16(fi->description, forumInfoNew.forumDesc);
|
||||
// forumInfoNew.forumName.insert(0, FEEDREADER_FORUM_PREFIX);
|
||||
// }
|
||||
if ((fi->flag & RS_FEED_FLAG_FORUM) && (fi->flag & RS_FEED_FLAG_UPDATE_FORUM_INFO) && !fi->forumId.empty() && !preview) {
|
||||
/* change forum too */
|
||||
forumId = fi->forumId;
|
||||
forumName = fi->name;
|
||||
forumDescription = fi->description;
|
||||
forumName.insert(0, FEEDREADER_FORUM_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
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 (mForums) {
|
||||
// ForumInfo forumInfo;
|
||||
// if (mForums->getForumInfo(forumId, forumInfo)) {
|
||||
// if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) {
|
||||
// /* name or description changed, update forum */
|
||||
//#ifdef FEEDREADER_DEBUG
|
||||
// std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl;
|
||||
//#endif
|
||||
// if (!mForums->setForumInfo(forumId, forumInfoNew)) {
|
||||
//#ifdef FEEDREADER_DEBUG
|
||||
// std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
//#ifdef FEEDREADER_DEBUG
|
||||
// std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl;
|
||||
//#endif
|
||||
// }
|
||||
// } else {
|
||||
// std::cerr << "p3FeedReader::setFeedInfo - can't process forum, member mForums is not set" << std::endl;
|
||||
// }
|
||||
// }
|
||||
if (!forumId.empty()) {
|
||||
RsGxsForumGroup forumGroup;
|
||||
if (getForumGroup(RsGxsGroupId(forumId), forumGroup)) {
|
||||
updateForumGroup(forumGroup, forumName, forumDescription);
|
||||
}
|
||||
//TODO: error
|
||||
}
|
||||
}
|
||||
|
||||
bool p3FeedReader::getForumGroup(const RsGxsGroupId &groupId, RsGxsForumGroup &forumGroup)
|
||||
{
|
||||
if (!mForums) {
|
||||
std::cerr << "p3FeedReader::getForumGroup - can't get forum group " << groupId.toStdString() << ", member mForums is not set" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (groupId.isNull()) {
|
||||
std::cerr << "p3FeedReader::getForumGroup - group id is not valid" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<RsGxsGroupId> grpIds;
|
||||
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;
|
||||
}
|
||||
|
@ -26,17 +26,19 @@
|
||||
#include "plugins/rspqiservice.h"
|
||||
#include "interface/rsFeedReader.h"
|
||||
|
||||
#include "retroshare/rsgxsifacetypes.h"
|
||||
|
||||
class RsFeedReaderFeed;
|
||||
class RsFeedReaderMsg;
|
||||
class p3FeedReaderThread;
|
||||
|
||||
//Todo: Replace with gxs forums
|
||||
class RsForums;
|
||||
class RsGxsForums;
|
||||
class RsGxsForumGroup;
|
||||
|
||||
class p3FeedReader : public RsPQIService, public RsFeedReader
|
||||
{
|
||||
public:
|
||||
p3FeedReader(RsPluginHandler *pgHandler, RsForums *forums);
|
||||
p3FeedReader(RsPluginHandler *pgHandler, RsGxsForums *forums);
|
||||
|
||||
/****************** FeedReader Interface *************/
|
||||
virtual void stop();
|
||||
@ -68,6 +70,7 @@ public:
|
||||
virtual bool processFeed(const std::string &feedId);
|
||||
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 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 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);
|
||||
|
||||
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:
|
||||
/****************** p3Config STUFF *******************/
|
||||
virtual RsSerialiser *setupSerialiser();
|
||||
@ -100,9 +107,11 @@ private:
|
||||
void deleteAllMsgs_locked(RsFeedReaderFeed *fi);
|
||||
void stopPreviewThreads_locked();
|
||||
|
||||
private:
|
||||
time_t mLastClean;
|
||||
RsForums *mForums;
|
||||
RsGxsForums *mForums;
|
||||
RsFeedReaderNotify *mNotify;
|
||||
volatile bool mStopped;
|
||||
|
||||
RsMutex mFeedReaderMtx;
|
||||
std::list<RsItem*> cleanSaveData;
|
||||
|
Loading…
Reference in New Issue
Block a user