Skip to content

Commit

Permalink
fix(thread): find thread title by id
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
realth000 committed Jan 1, 2025
1 parent 75e7fb9 commit 7da5500
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions lib/features/thread/bloc/thread_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,29 +265,9 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> with LoggerMixin {
threadDataNode,
document.currentPage() ?? 1,
);
String? title;
// Most threads have thread type node before the title.
title =
// Thread belongs to not types.
document
.querySelector('div#postlist h1.ts > a:nth-child(1)')
?.nextNode
?.text
?.trim() ??
// Thread belongs to some type.
document
.querySelector('div#postlist h1.ts > a:nth-child(1)')
?.innerText
.trim();
if (title?.isEmpty ?? true) {
// Some thread belongs to no type.
title = document
.querySelector('div#postlist h1.ts')
?.nodes
.elementAtOrNull(0)
?.text
?.trim();
}
// Title node ALWAYS has an `a` node with id `thread_subject`.
// It's invisible in most styles and visible in 爱丽丝 style.
final title = document.querySelector('a#thread_subject')?.text?.trim();

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

0 comments on commit 7da5500

Please sign in to comment.