Skip to content

Commit ad02495

Browse files
Copilotgraycreate
andcommitted
Fix posting navigation: handle successful topic creation in error handler
Co-authored-by: graycreate <5203798+graycreate@users.noreply.github.com>
1 parent f32c1a7 commit ad02495

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,14 @@ public void handleError(GeneralError generalError) {
203203
Observable.just(response)
204204
.compose(rx(null))
205205
.map(s -> {
206-
BaseInfo resultInfo = APIService.fruit().fromHtml(s, CreateTopicPageInfo.class);
206+
// First, check if this is actually a successful topic creation
207+
// (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;
211+
}
212+
// If not a valid topic, try parsing as error pages
213+
resultInfo = APIService.fruit().fromHtml(s, CreateTopicPageInfo.class);
207214
if (!resultInfo.isValid()) {
208215
resultInfo = APIService.fruit().fromHtml(s, NewUserBannedCreateInfo.class);
209216
}
@@ -212,7 +219,10 @@ public void handleError(GeneralError generalError) {
212219
.subscribe(new GeneralConsumer<BaseInfo>(this) {
213220
@Override
214221
public void onConsume(BaseInfo baseInfo) {
215-
if (baseInfo instanceof CreateTopicPageInfo) {
222+
if (baseInfo instanceof TopicInfo) {
223+
// Actually a success! Treat it as such
224+
onPostSuccess((TopicInfo) baseInfo);
225+
} else if (baseInfo instanceof CreateTopicPageInfo) {
216226
onPostFailure((CreateTopicPageInfo) baseInfo);
217227
} else {
218228
onBannedCreateTopic((NewUserBannedCreateInfo) baseInfo);

0 commit comments

Comments
 (0)