Skip to content

Commit 7da5500

Browse files
committed
fix(thread): find thread title by id
All thread with or without thread type has a `a` node with id `thread_subject`, the node is visible in 爱丽丝 style and invisible in other styles. This commit use the id to select thread title to fix title not found exception. Seems server changed the style recently which breaks the old implementation.
1 parent 75e7fb9 commit 7da5500

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

lib/features/thread/bloc/thread_bloc.dart

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -265,29 +265,9 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> with LoggerMixin {
265265
threadDataNode,
266266
document.currentPage() ?? 1,
267267
);
268-
String? title;
269-
// Most threads have thread type node before the title.
270-
title =
271-
// Thread belongs to not types.
272-
document
273-
.querySelector('div#postlist h1.ts > a:nth-child(1)')
274-
?.nextNode
275-
?.text
276-
?.trim() ??
277-
// Thread belongs to some type.
278-
document
279-
.querySelector('div#postlist h1.ts > a:nth-child(1)')
280-
?.innerText
281-
.trim();
282-
if (title?.isEmpty ?? true) {
283-
// Some thread belongs to no type.
284-
title = document
285-
.querySelector('div#postlist h1.ts')
286-
?.nodes
287-
.elementAtOrNull(0)
288-
?.text
289-
?.trim();
290-
}
268+
// Title node ALWAYS has an `a` node with id `thread_subject`.
269+
// It's invisible in most styles and visible in 爱丽丝 style.
270+
final title = document.querySelector('a#thread_subject')?.text?.trim();
291271

292272
final allLinksInBreadCrumb = document.querySelectorAll('div#pt a');
293273
final forumName = switch (allLinksInBreadCrumb.length < 2) {

0 commit comments

Comments
 (0)