From f9ca6cd3e144081b0a397240aa4e155b3bc1d834 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Tue, 9 May 2023 22:13:38 +0200 Subject: [PATCH] FeedReader: Show error when some post could not be created --- .../FeedReader/gui/FeedReaderStringDefs.cpp | 3 + plugins/FeedReader/interface/rsFeedReader.h | 1 + plugins/FeedReader/lang/FeedReader_en.ts | 9 +- plugins/FeedReader/services/p3FeedReader.cc | 244 ++++++++++-------- plugins/FeedReader/services/p3FeedReader.h | 2 +- .../FeedReader/services/p3FeedReaderThread.cc | 17 +- 6 files changed, 156 insertions(+), 120 deletions(-) diff --git a/plugins/FeedReader/gui/FeedReaderStringDefs.cpp b/plugins/FeedReader/gui/FeedReaderStringDefs.cpp index 07f0d44ab..53a62e669 100644 --- a/plugins/FeedReader/gui/FeedReaderStringDefs.cpp +++ b/plugins/FeedReader/gui/FeedReaderStringDefs.cpp @@ -136,6 +136,9 @@ QString FeedReaderStringDefs::errorString(RsFeedReaderErrorState errorState, con case RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_AUTHOR: errorText = QApplication::translate("FeedReaderStringDefs", "Board has no author"); break; + case RS_FEED_ERRORSTATE_PROCESS_POST: + errorText = QApplication::translate("FeedReaderStringDefs", "Some posts could not be created"); + break; case RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR: errorText = QApplication::translate("FeedReaderStringDefs", "Can't read html"); diff --git a/plugins/FeedReader/interface/rsFeedReader.h b/plugins/FeedReader/interface/rsFeedReader.h index 044dcdd80..72a900654 100644 --- a/plugins/FeedReader/interface/rsFeedReader.h +++ b/plugins/FeedReader/interface/rsFeedReader.h @@ -56,6 +56,7 @@ enum RsFeedReaderErrorState { RS_FEED_ERRORSTATE_PROCESS_POSTED_NOT_FOUND = 105, RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_ADMIN = 106, RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_AUTHOR = 107, + RS_FEED_ERRORSTATE_PROCESS_POST = 108, RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR = 150, RS_FEED_ERRORSTATE_PROCESS_XPATH_INTERNAL_ERROR = 151, diff --git a/plugins/FeedReader/lang/FeedReader_en.ts b/plugins/FeedReader/lang/FeedReader_en.ts index db5748893..707c8cec9 100644 --- a/plugins/FeedReader/lang/FeedReader_en.ts +++ b/plugins/FeedReader/lang/FeedReader_en.ts @@ -714,12 +714,12 @@ - + Unknown - + Internal download error @@ -788,6 +788,11 @@ Board has no author + + + Some posts could not be created + + Can't read html diff --git a/plugins/FeedReader/services/p3FeedReader.cc b/plugins/FeedReader/services/p3FeedReader.cc index fbda4d9e1..6612210a7 100644 --- a/plugins/FeedReader/services/p3FeedReader.cc +++ b/plugins/FeedReader/services/p3FeedReader.cc @@ -1994,12 +1994,13 @@ void p3FeedReader::onProcessSuccess_filterMsg(uint32_t feedId, std::list &msgs, bool single) +void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list &msgs) { #ifdef FEEDREADER_DEBUG std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - feed " << feedId << " got " << msgs.size() << " messages" << std::endl; #endif + RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK; std::list addedMsgs; std::string forumId; RsGxsId forumAuthorId; @@ -2025,7 +2026,6 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::listsecond; bool forum = (fi->flag & RS_FEED_FLAG_FORUM) && !fi->preview; bool posted = (fi->flag & RS_FEED_FLAG_POSTED) && !fi->preview; - RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK; feedFlag = fi->flag; if (forum && !msgs.empty()) { @@ -2125,129 +2125,153 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::listfeedId << " (" << fi->name << ") added " << newMsgs << "/" << msgs.size() << " messages" << std::endl; #endif } - - if (!single) { - fi->workstate = RsFeedReaderFeed::WAITING; - fi->content.clear(); - fi->errorState = errorState; - fi->lastUpdate = time(NULL); - } - - if (!fi->preview) { - IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_NOW); - } } - if (!forumId.empty() && !forumMsgs.empty()) { - if (mForums) { - /* a bit tricky */ - RsGenExchange *genExchange = dynamic_cast(mForums); - if (genExchange) { - /* add messages as forum messages */ - std::list::iterator msgIt; - for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) { - RsFeedReaderMsg &mi = *msgIt; + bool postError = false; - /* convert to forum messages */ - RsGxsForumMsg forumMsg; - forumMsg.mMeta.mGroupId = RsGxsGroupId(forumId); - forumMsg.mMeta.mMsgName = mi.title; - forumMsg.mMeta.mAuthorId = forumAuthorId; + if (errorState == RS_FEED_ERRORSTATE_OK) { + if (!forumId.empty() && !forumMsgs.empty()) { + if (mForums) { + /* a bit tricky */ + RsGenExchange *genExchange = dynamic_cast(mForums); + if (genExchange) { + /* add messages as forum messages */ + std::list::iterator msgIt; + for (msgIt = forumMsgs.begin(); msgIt != forumMsgs.end(); ++msgIt) { + RsFeedReaderMsg &mi = *msgIt; - std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; - /* add link */ - if (!mi.link.empty()) { - description += "
" + mi.link + ""; - } - forumMsg.mMsg = description; + /* convert to forum messages */ + RsGxsForumMsg forumMsg; + forumMsg.mMeta.mGroupId = RsGxsGroupId(forumId); + forumMsg.mMeta.mMsgName = mi.title; + forumMsg.mMeta.mAuthorId = forumAuthorId; - uint32_t token; - if (mForums->createMsg(token, forumMsg) && waitForToken(mForums, 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); + std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; + /* add link */ + if (!mi.link.empty()) { + description += "
" + mi.link + ""; } - } 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; - } - } + forumMsg.mMsg = description; - if (!postedId.empty() && !postedMsgs.empty()) { - if (mPosted) { - /* a bit tricky */ - RsGenExchange *genExchange = dynamic_cast(mPosted); - if (genExchange) { - /* add messages as posted messages */ - std::list::iterator msgIt; - for (msgIt = postedMsgs.begin(); msgIt != postedMsgs.end(); ++msgIt) { - RsFeedReaderMsg &mi = *msgIt; - - /* convert to posted messages */ - RsPostedPost postedPost; - postedPost.mMeta.mGroupId = RsGxsGroupId(postedId); - postedPost.mMeta.mMsgName = mi.title; - postedPost.mMeta.mAuthorId = postedAuthorId; - postedPost.mLink = mi.link; - - std::string description; - if (feedFlag & RS_FEED_FLAG_POSTED_FIRST_IMAGE) { - if (!mi.postedFirstImage.empty()) { - /* use first image as image for posted and description without image as notes */ - if (feedFlag & RS_FEED_FLAG_POSTED_SHRINK_IMAGE) { - // shrink image - std::vector shrinkedImage; - if (shrinkImage(FeedReaderShrinkImageTask::POSTED, mi.postedFirstImage, shrinkedImage)) { - postedPost.mImage.copy(shrinkedImage.data(), shrinkedImage.size()); - } - } else { - postedPost.mImage.copy(mi.postedFirstImage.data(), mi.postedFirstImage.size()); - } - if (feedFlag & RS_FEED_FLAG_POSTED_ONLY_IMAGE) { - /* ignore description */ - } else { - description = mi.postedDescriptionWithoutFirstImage; + uint32_t token; + if (mForums->createMsg(token, forumMsg) && waitForToken(mForums, 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 { - if (feedFlag & RS_FEED_FLAG_POSTED_ONLY_IMAGE) { - /* ignore messages without image */ - continue; - } - description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; - } - } else { - description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; - } - - postedPost.mNotes = description; - - uint32_t token; - if (mPosted->createPost(token, postedPost) && waitForToken(mPosted, token)) { - RsGxsGrpMsgIdPair msgPair; - if (mPosted->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 posted message " << mi.title << " for feed " << postedId << std::endl; + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't add forum message " << mi.title << " for feed " << forumId << std::endl; #endif + postError = true; + } } + } 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 posted, member mPosted is not derived from RsGenExchange" << std::endl; + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not set" << std::endl; } - } else { - std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process posted, member mPosted is not set" << std::endl; + } + + if (!postedId.empty() && !postedMsgs.empty()) { + if (mPosted) { + /* a bit tricky */ + RsGenExchange *genExchange = dynamic_cast(mPosted); + if (genExchange) { + /* add messages as posted messages */ + std::list::iterator msgIt; + for (msgIt = postedMsgs.begin(); msgIt != postedMsgs.end(); ++msgIt) { + RsFeedReaderMsg &mi = *msgIt; + + /* convert to posted messages */ + RsPostedPost postedPost; + postedPost.mMeta.mGroupId = RsGxsGroupId(postedId); + postedPost.mMeta.mMsgName = mi.title; + postedPost.mMeta.mAuthorId = postedAuthorId; + postedPost.mLink = mi.link; + + std::string description; + if (feedFlag & RS_FEED_FLAG_POSTED_FIRST_IMAGE) { + if (!mi.postedFirstImage.empty()) { + /* use first image as image for posted and description without image as notes */ + if (feedFlag & RS_FEED_FLAG_POSTED_SHRINK_IMAGE) { + // shrink image + std::vector shrinkedImage; + if (shrinkImage(FeedReaderShrinkImageTask::POSTED, mi.postedFirstImage, shrinkedImage)) { + postedPost.mImage.copy(shrinkedImage.data(), shrinkedImage.size()); + } + } else { + postedPost.mImage.copy(mi.postedFirstImage.data(), mi.postedFirstImage.size()); + } + if (feedFlag & RS_FEED_FLAG_POSTED_ONLY_IMAGE) { + /* ignore description */ + } else { + description = mi.postedDescriptionWithoutFirstImage; + } + } else { + if (feedFlag & RS_FEED_FLAG_POSTED_ONLY_IMAGE) { + /* ignore messages without image */ + continue; + } + description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; + } + } else { + description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; + } + + postedPost.mNotes = description; + + uint32_t token; + if (mPosted->createPost(token, postedPost) && waitForToken(mPosted, token)) { + RsGxsGrpMsgIdPair msgPair; + if (mPosted->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 posted message " << mi.title << " for feed " << postedId << std::endl; +#endif + postError = true; + } + } + } else { + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process posted, member mPosted is not derived from RsGenExchange" << std::endl; + } + } else { + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process posted, member mPosted is not set" << std::endl; + } + } + } + + { + RsStackMutex stack(mFeedReaderMtx); /******* LOCK STACK MUTEX *********/ + + /* find feed */ + std::map::iterator it = mFeeds.find(feedId); + if (it == mFeeds.end()) { + /* feed not found */ +#ifdef FEEDREADER_DEBUG + std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - feed " << feedId << " not found" << std::endl; +#endif + return; + } + + RsFeedReaderFeed *fi = it->second; + + if (!fi->preview) { + fi->workstate = RsFeedReaderFeed::WAITING; + fi->content.clear(); + if (errorState == RS_FEED_ERRORSTATE_OK && postError) { + // post error occured + errorState = RS_FEED_ERRORSTATE_PROCESS_POST; + } + fi->errorState = errorState; + fi->lastUpdate = time(NULL); + + IndicateConfigChanged(RsConfigMgr::CheckPriority::SAVE_NOW); } } diff --git a/plugins/FeedReader/services/p3FeedReader.h b/plugins/FeedReader/services/p3FeedReader.h index edca9ee1e..bc20a8618 100644 --- a/plugins/FeedReader/services/p3FeedReader.h +++ b/plugins/FeedReader/services/p3FeedReader.h @@ -95,7 +95,7 @@ public: void onDownloadSuccess(uint32_t feedId, const std::string &content, std::string &icon); void onDownloadError(uint32_t feedId, RsFeedReaderErrorState result, const std::string &errorString); void onProcessSuccess_filterMsg(uint32_t feedId, std::list &msgs); - void onProcessSuccess_addMsgs(uint32_t feedId, std::list &msgs, bool single); + void onProcessSuccess_addMsgs(uint32_t feedId, std::list &msgs); void onProcessError(uint32_t feedId, RsFeedReaderErrorState result, const std::string &errorString); bool getFeedToProcess(RsFeedReaderFeed &feed, uint32_t neededFeedId); diff --git a/plugins/FeedReader/services/p3FeedReaderThread.cc b/plugins/FeedReader/services/p3FeedReaderThread.cc index 1c8714a05..5ba3ade35 100644 --- a/plugins/FeedReader/services/p3FeedReaderThread.cc +++ b/plugins/FeedReader/services/p3FeedReaderThread.cc @@ -107,7 +107,7 @@ void p3FeedReaderThread::threadTick() std::list msgSingle; msgSingle.push_back(mi); - mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgSingle, true); + mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgSingle); /* delete not accepted message */ std::list::iterator it1; @@ -122,12 +122,15 @@ void p3FeedReaderThread::threadTick() ++it; } } - if (isRunning()) { - if (result == RS_FEED_ERRORSTATE_OK) { - /* third, add messages */ - mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgs, false); - } else { - mFeedReader->onProcessError(feed.feedId, result, errorString); + + if (!feed.preview) { + if (isRunning()) { + if (result == RS_FEED_ERRORSTATE_OK) { + /* third, add messages */ + mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgs); + } else { + mFeedReader->onProcessError(feed.feedId, result, errorString); + } } } }