Skip to content

Commit cb7bc17

Browse files
committed
Guard topic success detection in append/create flows
1 parent 9474165 commit cb7bc17

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

app/src/main/java/me/ghui/v2er/module/append/AppendTopicActivity.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public void handleError(GeneralError generalError) {
137137
.map(s -> {
138138
// First, check if this is actually a successful append
139139
// (V2EX may return the topic page on success, which triggers error handler due to redirects)
140-
BaseInfo resultInfo = APIService.fruit().fromHtml(s, TopicInfo.class);
141-
if (resultInfo.isValid()) {
142-
return resultInfo;
140+
TopicInfo topicInfo = APIService.fruit().fromHtml(s, TopicInfo.class);
141+
if (isSuccessfulTopicResponse(topicInfo)) {
142+
return topicInfo;
143143
}
144144
// If not a valid topic, try parsing as error page
145145
return APIService.fruit().fromHtml(s, AppendTopicPageInfo.class);
@@ -169,6 +169,14 @@ public void onConsume(BaseInfo baseInfo) {
169169
});
170170
}
171171

172+
private boolean isSuccessfulTopicResponse(TopicInfo topicInfo) {
173+
if (topicInfo == null || !topicInfo.isValid()) {
174+
return false;
175+
}
176+
TopicInfo.Problem problem = topicInfo.getProblem();
177+
return (problem == null || problem.isEmpty()) && Check.notEmpty(topicInfo.getTopicLink());
178+
}
179+
172180
@Override
173181
public void onAfterAppendTopic(TopicInfo topicInfo) {
174182
Utils.toggleKeyboard(false, mContentET);

app/src/main/java/me/ghui/v2er/module/create/CreateTopicActivity.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ public void handleError(GeneralError generalError) {
205205
.map(s -> {
206206
// First, check if this is actually a successful topic creation
207207
// (V2EX may return the topic page on success, which triggers error handler due to redirects)
208-
BaseInfo resultInfo = APIService.fruit().fromHtml(s, TopicInfo.class);
209-
if (resultInfo.isValid()) {
210-
return resultInfo;
208+
TopicInfo topicInfo = APIService.fruit().fromHtml(s, TopicInfo.class);
209+
if (isSuccessfulTopicResponse(topicInfo)) {
210+
return topicInfo;
211211
}
212212
// If not a valid topic, try parsing as error pages
213-
resultInfo = APIService.fruit().fromHtml(s, CreateTopicPageInfo.class);
213+
BaseInfo resultInfo = APIService.fruit().fromHtml(s, CreateTopicPageInfo.class);
214214
if (!resultInfo.isValid()) {
215215
resultInfo = APIService.fruit().fromHtml(s, NewUserBannedCreateInfo.class);
216216
}
@@ -244,4 +244,12 @@ private void onBannedCreateTopic(NewUserBannedCreateInfo bannedCreateInfo) {
244244
}).build().show();
245245
}
246246

247+
private boolean isSuccessfulTopicResponse(TopicInfo topicInfo) {
248+
if (topicInfo == null || !topicInfo.isValid()) {
249+
return false;
250+
}
251+
TopicInfo.Problem problem = topicInfo.getProblem();
252+
return (problem == null || problem.isEmpty()) && Check.notEmpty(topicInfo.getTopicLink());
253+
}
254+
247255
}

0 commit comments

Comments
 (0)