@@ -2,33 +2,39 @@ pub mod edit;
|
||||
pub mod picture;
|
||||
pub mod preview;
|
||||
|
||||
use crate::profile::get_display_name;
|
||||
use crate::ui::note::NoteOptions;
|
||||
use crate::{colors, images};
|
||||
use crate::{notes_holder::NotesHolder, NostrName};
|
||||
pub use edit::EditProfileView;
|
||||
use egui::load::TexturePoll;
|
||||
use egui::{vec2, Color32, Label, Layout, Rect, RichText, Rounding, ScrollArea, Sense, Stroke};
|
||||
use enostr::Pubkey;
|
||||
use enostr::{Pubkey, PubkeyRef};
|
||||
use nostrdb::{Ndb, ProfileRecord, Transaction};
|
||||
pub use picture::ProfilePic;
|
||||
pub use preview::ProfilePreview;
|
||||
use tracing::error;
|
||||
|
||||
use crate::{actionbar::NoteAction, notes_holder::NotesHolderStorage, profile::Profile};
|
||||
use crate::{
|
||||
actionbar::NoteAction,
|
||||
colors, images,
|
||||
profile::get_display_name,
|
||||
timeline::{TimelineCache, TimelineCacheKey},
|
||||
ui::{
|
||||
note::NoteOptions,
|
||||
timeline::{tabs_ui, TimelineTabView},
|
||||
},
|
||||
NostrName,
|
||||
};
|
||||
|
||||
use super::timeline::{tabs_ui, TimelineTabView};
|
||||
use notedeck::{Accounts, ImageCache, MuteFun, NoteCache, NotedeckTextStyle};
|
||||
use notedeck::{Accounts, ImageCache, MuteFun, NoteCache, NotedeckTextStyle, UnknownIds};
|
||||
|
||||
pub struct ProfileView<'a> {
|
||||
pubkey: &'a Pubkey,
|
||||
accounts: &'a Accounts,
|
||||
col_id: usize,
|
||||
profiles: &'a mut NotesHolderStorage<Profile>,
|
||||
timeline_cache: &'a mut TimelineCache,
|
||||
note_options: NoteOptions,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
is_muted: &'a MuteFun,
|
||||
}
|
||||
|
||||
@@ -43,10 +49,11 @@ impl<'a> ProfileView<'a> {
|
||||
pubkey: &'a Pubkey,
|
||||
accounts: &'a Accounts,
|
||||
col_id: usize,
|
||||
profiles: &'a mut NotesHolderStorage<Profile>,
|
||||
timeline_cache: &'a mut TimelineCache,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
is_muted: &'a MuteFun,
|
||||
note_options: NoteOptions,
|
||||
) -> Self {
|
||||
@@ -54,10 +61,11 @@ impl<'a> ProfileView<'a> {
|
||||
pubkey,
|
||||
accounts,
|
||||
col_id,
|
||||
profiles,
|
||||
timeline_cache,
|
||||
ndb,
|
||||
note_cache,
|
||||
img_cache,
|
||||
unknown_ids,
|
||||
note_options,
|
||||
is_muted,
|
||||
}
|
||||
@@ -76,23 +84,33 @@ impl<'a> ProfileView<'a> {
|
||||
action = Some(ProfileViewAction::EditProfile);
|
||||
}
|
||||
}
|
||||
let profile = self
|
||||
.profiles
|
||||
.notes_holder_mutated(self.ndb, self.note_cache, &txn, self.pubkey.bytes())
|
||||
let profile_timeline = self
|
||||
.timeline_cache
|
||||
.notes(
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
&txn,
|
||||
TimelineCacheKey::Profile(PubkeyRef::new(self.pubkey.bytes())),
|
||||
)
|
||||
.get_ptr();
|
||||
|
||||
profile.timeline.selected_view =
|
||||
tabs_ui(ui, profile.timeline.selected_view, &profile.timeline.views);
|
||||
profile_timeline.selected_view =
|
||||
tabs_ui(ui, profile_timeline.selected_view, &profile_timeline.views);
|
||||
|
||||
let reversed = false;
|
||||
// poll for new notes and insert them into our existing notes
|
||||
if let Err(e) = profile.poll_notes_into_view(&txn, self.ndb) {
|
||||
if let Err(e) = profile_timeline.poll_notes_into_view(
|
||||
self.ndb,
|
||||
&txn,
|
||||
self.unknown_ids,
|
||||
self.note_cache,
|
||||
reversed,
|
||||
) {
|
||||
error!("Profile::poll_notes_into_view: {e}");
|
||||
}
|
||||
|
||||
let reversed = false;
|
||||
|
||||
if let Some(note_action) = TimelineTabView::new(
|
||||
profile.timeline.current_view(),
|
||||
profile_timeline.current_view(),
|
||||
reversed,
|
||||
self.note_options,
|
||||
&txn,
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
use crate::{
|
||||
actionbar::NoteAction,
|
||||
notes_holder::{NotesHolder, NotesHolderStorage},
|
||||
thread::Thread,
|
||||
timeline::{TimelineCache, TimelineCacheKey},
|
||||
ui::note::NoteOptions,
|
||||
};
|
||||
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
use notedeck::{ImageCache, MuteFun, NoteCache, UnknownIds};
|
||||
use notedeck::{ImageCache, MuteFun, NoteCache, RootNoteId, UnknownIds};
|
||||
use tracing::error;
|
||||
|
||||
use super::timeline::TimelineTabView;
|
||||
|
||||
pub struct ThreadView<'a> {
|
||||
threads: &'a mut NotesHolderStorage<Thread>,
|
||||
timeline_cache: &'a mut TimelineCache,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
@@ -26,7 +25,7 @@ pub struct ThreadView<'a> {
|
||||
impl<'a> ThreadView<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
threads: &'a mut NotesHolderStorage<Thread>,
|
||||
timeline_cache: &'a mut TimelineCache,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
unknown_ids: &'a mut UnknownIds,
|
||||
@@ -37,7 +36,7 @@ impl<'a> ThreadView<'a> {
|
||||
) -> Self {
|
||||
let id_source = egui::Id::new("threadscroll_threadview");
|
||||
ThreadView {
|
||||
threads,
|
||||
timeline_cache,
|
||||
ndb,
|
||||
note_cache,
|
||||
unknown_ids,
|
||||
@@ -57,14 +56,6 @@ impl<'a> ThreadView<'a> {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<NoteAction> {
|
||||
let txn = Transaction::new(self.ndb).expect("txn");
|
||||
|
||||
let selected_note_key =
|
||||
if let Ok(key) = self.ndb.get_notekey_by_id(&txn, self.selected_note_id) {
|
||||
key
|
||||
} else {
|
||||
// TODO: render 404 ?
|
||||
return None;
|
||||
};
|
||||
|
||||
ui.label(
|
||||
egui::RichText::new("Threads ALPHA! It's not done. Things will be broken.")
|
||||
.color(egui::Color32::RED),
|
||||
@@ -76,38 +67,39 @@ impl<'a> ThreadView<'a> {
|
||||
.auto_shrink([false, false])
|
||||
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysVisible)
|
||||
.show(ui, |ui| {
|
||||
let note = if let Ok(note) = self.ndb.get_note_by_key(&txn, selected_note_key) {
|
||||
note
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
let root_id =
|
||||
match RootNoteId::new(self.ndb, self.note_cache, &txn, self.selected_note_id) {
|
||||
Ok(root_id) => root_id,
|
||||
|
||||
let root_id = {
|
||||
let cached_note = self
|
||||
.note_cache
|
||||
.cached_note_or_insert(selected_note_key, ¬e);
|
||||
Err(err) => {
|
||||
ui.label(format!("Error loading thread: {:?}", err));
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
||||
cached_note
|
||||
.reply
|
||||
.borrow(note.tags())
|
||||
.root()
|
||||
.map_or_else(|| self.selected_note_id, |nr| nr.id)
|
||||
};
|
||||
|
||||
let thread = self
|
||||
.threads
|
||||
.notes_holder_mutated(self.ndb, self.note_cache, &txn, root_id)
|
||||
let thread_timeline = self
|
||||
.timeline_cache
|
||||
.notes(
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
&txn,
|
||||
TimelineCacheKey::Thread(root_id),
|
||||
)
|
||||
.get_ptr();
|
||||
|
||||
// TODO(jb55): skip poll if ThreadResult is fresh?
|
||||
|
||||
let reversed = true;
|
||||
// poll for new notes and insert them into our existing notes
|
||||
match thread.poll_notes_into_view(&txn, self.ndb) {
|
||||
Ok(action) => {
|
||||
action.process_action(&txn, self.ndb, self.unknown_ids, self.note_cache)
|
||||
}
|
||||
Err(err) => error!("{err}"),
|
||||
};
|
||||
if let Err(err) = thread_timeline.poll_notes_into_view(
|
||||
self.ndb,
|
||||
&txn,
|
||||
self.unknown_ids,
|
||||
self.note_cache,
|
||||
reversed,
|
||||
) {
|
||||
error!("error polling notes into thread timeline: {err}");
|
||||
}
|
||||
|
||||
// This is threadview. We are not the universe view...
|
||||
let is_universe = false;
|
||||
@@ -115,7 +107,7 @@ impl<'a> ThreadView<'a> {
|
||||
note_options.set_textmode(self.textmode);
|
||||
|
||||
TimelineTabView::new(
|
||||
thread.view(),
|
||||
thread_timeline.current_view(),
|
||||
true,
|
||||
note_options,
|
||||
&txn,
|
||||
|
||||
@@ -286,10 +286,14 @@ impl<'a> TimelineTabView<'a> {
|
||||
return 0;
|
||||
};
|
||||
|
||||
let muted = is_muted(
|
||||
¬e,
|
||||
root_note_id_from_selected_id(self.ndb, self.note_cache, self.txn, note.id()),
|
||||
);
|
||||
// should we mute the thread? we might not have it!
|
||||
let muted = if let Ok(root_id) =
|
||||
root_note_id_from_selected_id(self.ndb, self.note_cache, self.txn, note.id())
|
||||
{
|
||||
is_muted(¬e, root_id.bytes())
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if !muted {
|
||||
ui::padding(8.0, ui, |ui| {
|
||||
|
||||
Reference in New Issue
Block a user