Added service pointer for forums to the plugin interface.

FeedReader:
- Used the forums pointer from the plugin interface instead of the global pointer

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6982 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-01-03 15:05:48 +00:00
parent 2a9a6f8a75
commit 76b3ccc1a5
6 changed files with 109 additions and 85 deletions

View File

@ -42,6 +42,7 @@ class RsTurtle ;
class RsDht ; class RsDht ;
class RsDisc ; class RsDisc ;
class RsMsgs ; class RsMsgs ;
class RsForums;
class p3LinkMgr ; class p3LinkMgr ;
class MainPage ; class MainPage ;
class QIcon ; class QIcon ;
@ -98,6 +99,7 @@ public:
RsTurtle *mTurtle; RsTurtle *mTurtle;
RsDisc *mDisc; RsDisc *mDisc;
RsDht *mDht; RsDht *mDht;
RsForums *mForums;
}; };
class RsPlugin class RsPlugin

View File

@ -2222,18 +2222,6 @@ int RsServer::StartupRetroShare()
rsDisc = new p3Discovery(ad); rsDisc = new p3Discovery(ad);
rsMsgs = new p3Msgs(msgSrv, chatSrv); rsMsgs = new p3Msgs(msgSrv, chatSrv);
// set interfaces for plugins
//
RsPlugInInterfaces interfaces;
interfaces.mFiles = rsFiles;
interfaces.mPeers = rsPeers;
interfaces.mMsgs = rsMsgs;
interfaces.mTurtle = rsTurtle;
interfaces.mDisc = rsDisc;
interfaces.mDht = rsDht;
mPluginsManager->setInterfaces(interfaces);
// connect components to turtle router. // connect components to turtle router.
ftserver->connectToTurtleRouter(tr) ; ftserver->connectToTurtleRouter(tr) ;
@ -2264,6 +2252,20 @@ int RsServer::StartupRetroShare()
pqih -> addService(mBlogs); /* This must be also ticked as a service */ pqih -> addService(mBlogs); /* This must be also ticked as a service */
#endif #endif
// set interfaces for plugins
//
RsPlugInInterfaces interfaces;
interfaces.mFiles = rsFiles;
interfaces.mPeers = rsPeers;
interfaces.mMsgs = rsMsgs;
interfaces.mTurtle = rsTurtle;
interfaces.mDisc = rsDisc;
interfaces.mDht = rsDht;
interfaces.mForums = mForums;
mPluginsManager->setInterfaces(interfaces);
// now add plugin objects inside the loop: // now add plugin objects inside the loop:
// - client services provided by plugins. // - client services provided by plugins.
// - cache services provided by plugins. // - cache services provided by plugins.

View File

@ -83,8 +83,9 @@ FeedReaderPlugin::FeedReaderPlugin()
mFeedNotify = NULL; mFeedNotify = NULL;
} }
void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &/*interfaces*/) void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
{ {
mInterfaces = interfaces;
} }
ConfigPage *FeedReaderPlugin::qt_config_page() const ConfigPage *FeedReaderPlugin::qt_config_page() const
@ -112,7 +113,7 @@ FeedNotify *FeedReaderPlugin::qt_feedNotify()
RsPQIService *FeedReaderPlugin::rs_pqi_service() const RsPQIService *FeedReaderPlugin::rs_pqi_service() const
{ {
if (mFeedReader == NULL) { if (mFeedReader == NULL) {
mFeedReader = new p3FeedReader(mPlugInHandler); mFeedReader = new p3FeedReader(mPlugInHandler, mInterfaces.mForums);
rsFeedReader = mFeedReader; rsFeedReader = mFeedReader;
mNotify = new FeedReaderNotify(); mNotify = new FeedReaderNotify();

View File

@ -56,6 +56,7 @@ public:
virtual FeedNotify *qt_feedNotify(); virtual FeedNotify *qt_feedNotify();
private: private:
RsPlugInInterfaces mInterfaces;
mutable p3FeedReader *mFeedReader; mutable p3FeedReader *mFeedReader;
mutable FeedReaderNotify *mNotify; mutable FeedReaderNotify *mNotify;
mutable RsPluginHandler *mPlugInHandler; mutable RsPluginHandler *mPlugInHandler;

View File

@ -36,7 +36,7 @@ RsFeedReader *rsFeedReader = NULL;
* #define FEEDREADER_DEBUG * #define FEEDREADER_DEBUG
*********/ *********/
p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler) p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler, RsForums *forums)
: RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, CONFIG_TYPE_FEEDREADER, 5, pgHandler), : RsPQIService(RS_SERVICE_TYPE_PLUGIN_FEEDREADER, CONFIG_TYPE_FEEDREADER, 5, pgHandler),
mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview") mFeedReaderMtx("p3FeedReader"), mDownloadMutex("p3FeedReaderDownload"), mProcessMutex("p3FeedReaderProcess"), mPreviewMutex("p3FeedReaderPreview")
{ {
@ -49,6 +49,7 @@ p3FeedReader::p3FeedReader(RsPluginHandler* pgHandler)
mStandardUseProxy = false; mStandardUseProxy = false;
mStandardProxyPort = 0; mStandardProxyPort = 0;
mLastClean = 0; mLastClean = 0;
mForums = forums;
mNotify = NULL; mNotify = NULL;
mSaveInBackground = false; mSaveInBackground = false;
@ -525,11 +526,15 @@ RsFeedAddResult p3FeedReader::setFeed(const std::string &feedId, const FeedInfo
} }
if (!forumId.empty()) { if (!forumId.empty()) {
/* name or description changed, update forum */ if (mForums) {
if (!rsForums->setForumInfo(forumId, forumInfo)) { /* name or description changed, update forum */
if (!mForums->setForumInfo(forumId, forumInfo)) {
#ifdef FEEDREADER_DEBUG #ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl;
#endif #endif
}
} else {
std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << ", member mForums is not set" << std::endl;
} }
} }
@ -1836,55 +1841,59 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK; RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK;
if (forum && !msgs.empty()) { if (forum && !msgs.empty()) {
if (fi->forumId.empty()) { if (mForums) {
/* create new forum */ if (fi->forumId.empty()) {
std::wstring forumName; /* create new forum */
librs::util::ConvertUtf8ToUtf16(fi->name, forumName); std::wstring forumName;
forumName.insert(0, FEEDREADER_FORUM_PREFIX); librs::util::ConvertUtf8ToUtf16(fi->name, forumName);
forumName.insert(0, FEEDREADER_FORUM_PREFIX);
long todo; // search for existing forum? long todo; // search for existing forum?
/* search for existing own forum */ /* search for existing own forum */
// std::list<ForumInfo> forumList; // std::list<ForumInfo> forumList;
// if (rsForums->getForumList(forumList)) { // if (mForums->getForumList(forumList)) {
// std::wstring wName = StringToWString(name); // std::wstring wName = StringToWString(name);
// for (std::list<ForumInfo>::iterator it = forumList.begin(); it != forumList.end(); ++it) { // for (std::list<ForumInfo>::iterator it = forumList.begin(); it != forumList.end(); ++it) {
// if (it->forumName == wName) { // if (it->forumName == wName) {
// std::cout << "DEBUG_RSS2FORUM: Found existing forum " << it->forumId << " for " << name << std::endl; // std::cout << "DEBUG_RSS2FORUM: Found existing forum " << it->forumId << " for " << name << std::endl;
// return it->forumId; // return it->forumId;
// }
// } // }
// } // }
// }
std::wstring forumDescription; std::wstring forumDescription;
librs::util::ConvertUtf8ToUtf16(fi->description, forumDescription); librs::util::ConvertUtf8ToUtf16(fi->description, forumDescription);
/* create anonymous public forum */ /* create anonymous public forum */
fi->forumId = rsForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON); fi->forumId = mForums->createForum(forumName, forumDescription, RS_DISTRIB_PUBLIC | RS_DISTRIB_AUTHEN_ANON);
forumId = fi->forumId; forumId = fi->forumId;
if (fi->forumId.empty()) { if (fi->forumId.empty()) {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE; errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE;
#ifdef FEEDREADER_DEBUG #ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't create forum for feed " << feedId << " (" << fi->name << ") - ignore all messages" << std::endl; 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 */
ForumInfo forumInfo;
if (rsForums->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 { } else {
forumId = fi->forumId; std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - forum " << fi->forumId << " (" << fi->name << ") created" << std::endl;
#endif
} }
} else { } else {
errorState = RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND; /* 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 {
forumId = fi->forumId;
}
} else {
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;
} }
} }
@ -1938,31 +1947,35 @@ void p3FeedReader::onProcessSuccess_addMsgs(const std::string &feedId, std::list
} }
if (!forumId.empty() && !forumMsgs.empty()) { if (!forumId.empty() && !forumMsgs.empty()) {
/* add messages as forum messages */ if (mForums) {
std::list<RsFeedReaderMsg>::iterator msgIt; /* add messages as forum messages */
for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) { std::list<RsFeedReaderMsg>::iterator msgIt;
RsFeedReaderMsg &mi = *msgIt; for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) {
RsFeedReaderMsg &mi = *msgIt;
/* convert to forum messages */ /* convert to forum messages */
ForumMsgInfo forumMsgInfo; ForumMsgInfo forumMsgInfo;
forumMsgInfo.forumId = forumId; forumMsgInfo.forumId = forumId;
librs::util::ConvertUtf8ToUtf16(mi.title, forumMsgInfo.title); librs::util::ConvertUtf8ToUtf16(mi.title, forumMsgInfo.title);
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); librs::util::ConvertUtf8ToUtf16(description, forumMsgInfo.msg);
if (rsForums->ForumMessageSend(forumMsgInfo)) { if (mForums->ForumMessageSend(forumMsgInfo)) {
/* set to new */ /* set to new */
rsForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK); mForums->setMessageStatus(forumMsgInfo.forumId, forumMsgInfo.msgId, 0, FORUM_MSG_STATUS_MASK);
} else { } else {
#ifdef FEEDREADER_DEBUG #ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl; std::cerr << "p3FeedReader::onProcessSuccess_filterMsg - can't add forum message " << mi.title << " for feed " << forumId << std::endl;
#endif #endif
}
} }
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl;
} }
} }
@ -2070,23 +2083,27 @@ void p3FeedReader::setFeedInfo(const std::string &feedId, const std::string &nam
} }
if (!forumId.empty()) { if (!forumId.empty()) {
ForumInfo forumInfo; if (mForums) {
if (rsForums->getForumInfo(forumId, forumInfo)) { ForumInfo forumInfo;
if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) { if (mForums->getForumInfo(forumId, forumInfo)) {
/* name or description changed, update forum */ if (forumInfo.forumName != forumInfoNew.forumName || forumInfo.forumDesc != forumInfoNew.forumDesc) {
/* name or description changed, update forum */
#ifdef FEEDREADER_DEBUG #ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl; std::cerr << "p3FeedReader::setFeed - change forum " << forumId << std::endl;
#endif #endif
if (!rsForums->setForumInfo(forumId, forumInfoNew)) { if (!mForums->setForumInfo(forumId, forumInfoNew)) {
#ifdef FEEDREADER_DEBUG #ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl; std::cerr << "p3FeedReader::setFeed - can't change forum " << forumId << std::endl;
#endif #endif
}
} }
} else {
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl;
#endif
} }
} else { } else {
#ifdef FEEDREADER_DEBUG std::cerr << "p3FeedReader::setFeedInfo - can't process forum, member mForums is not set" << std::endl;
std::cerr << "p3FeedReader::setFeed - can't get forum info " << forumId << std::endl;
#endif
} }
} }
} }

View File

@ -33,7 +33,7 @@ class p3FeedReaderThread;
class p3FeedReader : public RsPQIService, public RsFeedReader class p3FeedReader : public RsPQIService, public RsFeedReader
{ {
public: public:
p3FeedReader(RsPluginHandler *pgHandler); p3FeedReader(RsPluginHandler *pgHandler, RsForums *forums);
/****************** FeedReader Interface *************/ /****************** FeedReader Interface *************/
virtual void stop(); virtual void stop();
@ -97,6 +97,7 @@ private:
void stopPreviewThreads_locked(); void stopPreviewThreads_locked();
time_t mLastClean; time_t mLastClean;
RsForums *mForums;
RsFeedReaderNotify *mNotify; RsFeedReaderNotify *mNotify;
RsMutex mFeedReaderMtx; RsMutex mFeedReaderMtx;