mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
FeedReader: Show error when some post could not be created
This commit is contained in:
parent
8422d3fc8c
commit
f9ca6cd3e1
@ -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");
|
||||
|
@ -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,
|
||||
|
@ -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't read html</source>
|
||||
|
@ -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,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;
|
||||
#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<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;
|
||||
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<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;
|
||||
/* add link */
|
||||
if (!mi.link.empty()) {
|
||||
description += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>";
|
||||
}
|
||||
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 += "<br><a href=\"" + mi.link + "\">" + mi.link + "</a>";
|
||||
}
|
||||
} 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<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;
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user