FeedReader: Show error when some post could not be created

This commit is contained in:
thunder2 2023-05-09 22:13:38 +02:00
parent 8422d3fc8c
commit f9ca6cd3e1
6 changed files with 156 additions and 120 deletions

View File

@ -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");

View File

@ -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,

View File

@ -714,12 +714,12 @@
</message>
<message>
<location line="+3"/>
<location line="+111"/>
<location line="+114"/>
<source>Unknown</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="-94"/>
<location line="-97"/>
<source>Internal download error</source>
<translation type="unfinished"></translation>
</message>
@ -788,6 +788,11 @@
<source>Board has no author</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+3"/>
<source>Some posts could not be created</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+4"/>
<source>Can&apos;t read html</source>

View File

@ -1994,12 +1994,13 @@ void p3FeedReader::onProcessSuccess_filterMsg(uint32_t feedId, std::list<RsFeedR
}
}
void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedReaderMsg*> &msgs, bool single)
void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedReaderMsg*> &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<std::string> addedMsgs;
std::string forumId;
RsGxsId forumAuthorId;
@ -2025,7 +2026,6 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedRea
RsFeedReaderFeed *fi = it->second;
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,19 +2125,11 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedRea
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - feed " << fi->feedId << " (" << 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);
}
}
bool postError = false;
if (errorState == RS_FEED_ERRORSTATE_OK) {
if (!forumId.empty() && !forumMsgs.empty()) {
if (mForums) {
/* a bit tricky */
@ -2172,6 +2164,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedRea
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't add forum message " << mi.title << " for feed " << forumId << std::endl;
#endif
postError = true;
}
}
} else {
@ -2241,6 +2234,7 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedRea
#ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't add posted message " << mi.title << " for feed " << postedId << std::endl;
#endif
postError = true;
}
}
} else {
@ -2250,6 +2244,36 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedRea
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<uint32_t, RsFeedReaderFeed*>::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);
}
}
if (mNotify) {
mNotify->notifyFeedChanged(feedId, NOTIFY_TYPE_MOD);

View File

@ -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<RsFeedReaderMsg*> &msgs);
void onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedReaderMsg*> &msgs, bool single);
void onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedReaderMsg*> &msgs);
void onProcessError(uint32_t feedId, RsFeedReaderErrorState result, const std::string &errorString);
bool getFeedToProcess(RsFeedReaderFeed &feed, uint32_t neededFeedId);

View File

@ -107,7 +107,7 @@ void p3FeedReaderThread::threadTick()
std::list<RsFeedReaderMsg*> msgSingle;
msgSingle.push_back(mi);
mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgSingle, true);
mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgSingle);
/* delete not accepted message */
std::list<RsFeedReaderMsg*>::iterator it1;
@ -122,15 +122,18 @@ void p3FeedReaderThread::threadTick()
++it;
}
}
if (!feed.preview) {
if (isRunning()) {
if (result == RS_FEED_ERRORSTATE_OK) {
/* third, add messages */
mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgs, false);
mFeedReader->onProcessSuccess_addMsgs(feed.feedId, msgs);
} else {
mFeedReader->onProcessError(feed.feedId, result, errorString);
}
}
}
}
} else {
mFeedReader->onProcessError(feed.feedId, result, errorString);
}