integrate new threads conception

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-06-17 12:49:09 -04:00
parent f6753bae97
commit d560e84eab
10 changed files with 260 additions and 185 deletions

View File

@@ -1,7 +1,7 @@
use crate::{
nav::RenderNavAction,
profile::ProfileAction,
timeline::{TimelineCache, TimelineKind},
timeline::{thread::Threads, ThreadSelection, TimelineCache, TimelineKind},
ui::{self, ProfileView},
};
@@ -16,7 +16,7 @@ pub fn render_timeline_route(
accounts: &mut Accounts,
kind: &TimelineKind,
col: usize,
mut note_options: NoteOptions,
note_options: NoteOptions,
depth: usize,
ui: &mut egui::Ui,
note_context: &mut NoteContext,
@@ -74,32 +74,40 @@ pub fn render_timeline_route(
note_action.map(RenderNavAction::NoteAction)
}
}
TimelineKind::Thread(id) => {
// don't truncate thread notes for now, since they are
// default truncated everywher eelse
note_options.set_truncate(false);
// text is selectable in threads
note_options.set_selectable_text(true);
ui::ThreadView::new(
timeline_cache,
unknown_ids,
id.selected_or_root(),
note_options,
&accounts.mutefun(),
note_context,
&accounts.get_selected_account().map(|a| (&a.key).into()),
jobs,
)
.id_source(egui::Id::new(("threadscroll", col)))
.ui(ui)
.map(Into::into)
}
}
}
#[allow(clippy::too_many_arguments)]
pub fn render_thread_route(
unknown_ids: &mut UnknownIds,
threads: &mut Threads,
accounts: &mut Accounts,
selection: &ThreadSelection,
col: usize,
mut note_options: NoteOptions,
ui: &mut egui::Ui,
note_context: &mut NoteContext,
jobs: &mut JobsCache,
) -> Option<RenderNavAction> {
// don't truncate thread notes for now, since they are
// default truncated everywher eelse
note_options.set_truncate(false);
ui::ThreadView::new(
threads,
unknown_ids,
selection.selected_or_root(),
note_options,
&accounts.mutefun(),
note_context,
&accounts.get_selected_account().map(|a| (&a.key).into()),
jobs,
)
.id_source(col)
.ui(ui)
.map(Into::into)
}
#[allow(clippy::too_many_arguments)]
pub fn render_profile_route(
pubkey: &Pubkey,
@@ -139,30 +147,3 @@ pub fn render_profile_route(
None
}
}
#[cfg(test)]
mod tests {
use enostr::NoteId;
use tokenator::{TokenParser, TokenWriter};
use crate::timeline::{ThreadSelection, TimelineKind};
use enostr::Pubkey;
use notedeck::RootNoteIdBuf;
#[test]
fn test_timeline_route_serialize() {
let note_id_hex = "1c54e5b0c386425f7e017d9e068ddef8962eb2ce1bb08ed27e24b93411c12e60";
let note_id = NoteId::from_hex(note_id_hex).unwrap();
let data_str = format!("thread:{}", note_id_hex);
let data = &data_str.split(":").collect::<Vec<&str>>();
let mut token_writer = TokenWriter::default();
let mut parser = TokenParser::new(&data);
let parsed = TimelineKind::parse(&mut parser, &Pubkey::new(*note_id.bytes())).unwrap();
let expected = TimelineKind::Thread(ThreadSelection::from_root_id(
RootNoteIdBuf::new_unsafe(*note_id.bytes()),
));
parsed.serialize_tokens(&mut token_writer);
assert_eq!(expected, parsed);
assert_eq!(token_writer.str(), data_str);
}
}