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: case RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_AUTHOR:
errorText = QApplication::translate("FeedReaderStringDefs", "Board has no author"); errorText = QApplication::translate("FeedReaderStringDefs", "Board has no author");
break; 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: 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

@ -56,6 +56,7 @@ enum RsFeedReaderErrorState {
RS_FEED_ERRORSTATE_PROCESS_POSTED_NOT_FOUND = 105, RS_FEED_ERRORSTATE_PROCESS_POSTED_NOT_FOUND = 105,
RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_ADMIN = 106, RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_ADMIN = 106,
RS_FEED_ERRORSTATE_PROCESS_POSTED_NO_AUTHOR = 107, 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_HTML_ERROR = 150,
RS_FEED_ERRORSTATE_PROCESS_XPATH_INTERNAL_ERROR = 151, RS_FEED_ERRORSTATE_PROCESS_XPATH_INTERNAL_ERROR = 151,

View File

@ -714,12 +714,12 @@
</message> </message>
<message> <message>
<location line="+3"/> <location line="+3"/>
<location line="+111"/> <location line="+114"/>
<source>Unknown</source> <source>Unknown</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location line="-94"/> <location line="-97"/>
<source>Internal download error</source> <source>Internal download error</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -788,6 +788,11 @@
<source>Board has no author</source> <source>Board has no author</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<location line="+3"/>
<source>Some posts could not be created</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<location line="+4"/> <location line="+4"/>
<source>Can&apos;t read html</source> <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 #ifdef FEEDREADER_DEBUG
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - feed " << feedId << " got " << msgs.size() << " messages" << std::endl; std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - feed " << feedId << " got " << msgs.size() << " messages" << std::endl;
#endif #endif
RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK;
std::list<std::string> addedMsgs; std::list<std::string> addedMsgs;
std::string forumId; std::string forumId;
RsGxsId forumAuthorId; RsGxsId forumAuthorId;
@ -2025,7 +2026,6 @@ void p3FeedReader::onProcessSuccess_addMsgs(uint32_t feedId, std::list<RsFeedRea
RsFeedReaderFeed *fi = it->second; RsFeedReaderFeed *fi = it->second;
bool forum = (fi->flag & RS_FEED_FLAG_FORUM) && !fi->preview; bool forum = (fi->flag & RS_FEED_FLAG_FORUM) && !fi->preview;
bool posted = (fi->flag & RS_FEED_FLAG_POSTED) && !fi->preview; bool posted = (fi->flag & RS_FEED_FLAG_POSTED) && !fi->preview;
RsFeedReaderErrorState errorState = RS_FEED_ERRORSTATE_OK;
feedFlag = fi->flag; feedFlag = fi->flag;
if (forum && !msgs.empty()) { if (forum && !msgs.empty()) {
@ -2125,129 +2125,153 @@ 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; std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - feed " << fi->feedId << " (" << fi->name << ") added " << newMsgs << "/" << msgs.size() << " messages" << std::endl;
#endif #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()) { bool postError = false;
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 */ if (errorState == RS_FEED_ERRORSTATE_OK) {
RsGxsForumMsg forumMsg; if (!forumId.empty() && !forumMsgs.empty()) {
forumMsg.mMeta.mGroupId = RsGxsGroupId(forumId); if (mForums) {
forumMsg.mMeta.mMsgName = mi.title; /* a bit tricky */
forumMsg.mMeta.mAuthorId = forumAuthorId; 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;
std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed; /* convert to forum messages */
/* add link */ RsGxsForumMsg forumMsg;
if (!mi.link.empty()) { forumMsg.mMeta.mGroupId = RsGxsGroupId(forumId);
description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>"; forumMsg.mMeta.mMsgName = mi.title;
} forumMsg.mMeta.mAuthorId = forumAuthorId;
forumMsg.mMsg = description;
uint32_t token; std::string description = mi.descriptionTransformed.empty() ? mi.description : mi.descriptionTransformed;
if (mForums->createMsg(token, forumMsg) && waitForToken(mForums, token)) { /* add link */
RsGxsGrpMsgIdPair msgPair; if (!mi.link.empty()) {
if (mForums->acknowledgeMsg(token, msgPair)) { description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>";
/* 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 { forumMsg.mMsg = description;
#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 (!postedId.empty() && !postedMsgs.empty()) { uint32_t token;
if (mPosted) { if (mForums->createMsg(token, forumMsg) && waitForToken(mForums, token)) {
/* a bit tricky */ RsGxsGrpMsgIdPair msgPair;
RsGenExchange *genExchange = dynamic_cast<RsGenExchange*>(mPosted); if (mForums->acknowledgeMsg(token, msgPair)) {
if (genExchange) { /* set to new */
/* add messages as posted messages */ 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::list<RsFeedReaderMsg>::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<unsigned char> 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 { } 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 #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 #endif
postError = true;
}
} }
} else {
std::cerr << "p3FeedReader::onProcessSuccess_addMsgs - can't process forum, member mForums is not derived from RsGenExchange" << std::endl;
} }
} else { } 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<RsGenExchange*>(mPosted);
if (genExchange) {
/* add messages as posted messages */
std::list<RsFeedReaderMsg>::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<unsigned char> 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<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);
} }
} }

View File

@ -95,7 +95,7 @@ public:
void onDownloadSuccess(uint32_t feedId, const std::string &content, std::string &icon); void onDownloadSuccess(uint32_t feedId, const std::string &content, std::string &icon);
void onDownloadError(uint32_t feedId, RsFeedReaderErrorState result, const std::string &errorString); void onDownloadError(uint32_t feedId, RsFeedReaderErrorState result, const std::string &errorString);
void onProcessSuccess_filterMsg(uint32_t feedId, std::list<RsFeedReaderMsg*> &msgs); 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); void onProcessError(uint32_t feedId, RsFeedReaderErrorState result, const std::string &errorString);
bool getFeedToProcess(RsFeedReaderFeed &feed, uint32_t neededFeedId); bool getFeedToProcess(RsFeedReaderFeed &feed, uint32_t neededFeedId);

View File

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