Merge a bunch of fixes from kernel

PRs

* 1141
* 1137
* 1136

kernelkind (10):
      Revert "feat: transitively trust images from parent note"
      feat: enable transitive trust for repost
      fix `NoteUnits` front insertion logic
      fix: don't reset scroll position when switching toolbar
      fix: no longer make the scroll position jump oddly
      fix: repost desc text size on newline
      make `tabs_ui` return `InnerResponse`
      refactor: impl transitive trust via `NoteOptions::TrustMedia`
      refactor: move `profile_body` to fn
      refactor: remove unnecessary code
This commit is contained in:
William Casarin
2025-09-16 11:28:20 -07:00
10 changed files with 242 additions and 245 deletions

View File

@@ -133,6 +133,7 @@ impl TimelineTab {
ndb: &Ndb,
txn: &Transaction,
reversed: bool,
use_front_insert: bool,
) -> Option<UnknownPks<'a>> {
if payloads.is_empty() {
return None;
@@ -158,7 +159,11 @@ impl TimelineTab {
debug!("spliced when inserting {num_refs} new notes, resetting virtual list",);
list.reset();
}
MergeKind::FrontInsert => {
MergeKind::FrontInsert => 's: {
if !use_front_insert {
break 's;
}
// only run this logic if we're reverse-chronological
// reversed in this case means chronological, since the
// default is reverse-chronological. yeah it's confusing.
@@ -210,6 +215,7 @@ pub struct Timeline {
pub selected_view: usize,
pub subscription: TimelineSub,
pub enable_front_insert: bool,
}
impl Timeline {
@@ -271,12 +277,16 @@ impl Timeline {
let subscription = TimelineSub::default();
let selected_view = 0;
// by default, disabled for profiles since they contain widgets above the list items
let enable_front_insert = !matches!(kind, TimelineKind::Profile(_));
Timeline {
kind,
filter,
views,
subscription,
selected_view,
enable_front_insert,
}
}
@@ -402,7 +412,9 @@ impl Timeline {
match view.filter {
ViewFilter::NotesAndReplies => {
let res: Vec<&NotePayload<'_>> = payloads.iter().collect();
if let Some(res) = view.insert(res, ndb, txn, reversed) {
if let Some(res) =
view.insert(res, ndb, txn, reversed, self.enable_front_insert)
{
res.process(unknown_ids, ndb, txn);
}
}
@@ -418,7 +430,13 @@ impl Timeline {
}
}
if let Some(res) = view.insert(filtered_payloads, ndb, txn, reversed) {
if let Some(res) = view.insert(
filtered_payloads,
ndb,
txn,
reversed,
self.enable_front_insert,
) {
res.process(unknown_ids, ndb, txn);
}
}

View File

@@ -101,28 +101,37 @@ impl NoteUnits {
let inserted_new = new_order.len();
let front_insertion = inserted_new > 0
&& if self.order.is_empty() || new_order.is_empty() {
true
} else if !self.reversed {
let first_new = *new_order.first().unwrap();
let last_old = *self.order.last().unwrap();
self.storage[first_new] >= self.storage[last_old]
} else {
let last_new = *new_order.last().unwrap();
let first_old = *self.order.first().unwrap();
self.storage[last_new] <= self.storage[first_old]
};
let front_insertion = if self.order.is_empty() || new_order.is_empty() {
!new_order.is_empty()
} else if self.reversed {
// reversed is true, sorting should occur less recent to most recent (oldest to newest, opposite of `self.order`)
let first_new = *new_order.first().unwrap(); // most recent unit of the new order
let last_old = *self.order.last().unwrap(); // least recent unit of the current order
// if the most recent unit of the new order is less recent than the least recent unit of the current order,
// all current order units are less recent than the new order units.
// In other words, they are all being inserted in the front
self.storage[first_new] >= self.storage[last_old]
} else {
// reversed is false, sorting should occur most recent to least recent (newest to oldest, as it is in `self.order`)
let last_new = *new_order.last().unwrap(); // least recent unit of the new order
let first_old = *self.order.first().unwrap(); // most recent unit of the current order
// if the least recent unit of the new order is more recent than the most recent unit of the current order,
// all new units are more recent than the current units.
// In other words, they are all being inserted in the front
self.storage[last_new] <= self.storage[first_old]
};
let mut merged = Vec::with_capacity(self.order.len() + new_order.len());
let (mut i, mut j) = (0, 0);
while i < self.order.len() && j < new_order.len() {
let index_left = self.order[i];
let index_right = new_order[j];
let left_item = &self.storage[index_left];
let right_item = &self.storage[index_right];
if left_item <= right_item {
// left_item is newer than right_item
let left_unit = &self.storage[index_left];
let right_unit = &self.storage[index_right];
if left_unit <= right_unit {
// the left unit is more recent than (or the same recency as) the right unit
merged.push(index_left);
i += 1;
} else {

View File

@@ -31,7 +31,6 @@ pub fn render_timeline_route(
| TimelineKind::Generic(_) => {
let note_action =
ui::TimelineView::new(kind, timeline_cache, note_context, note_options, jobs, col)
.scroll_to_top(scroll_to_top)
.ui(ui);
note_action.map(RenderNavAction::NoteAction)

View File

@@ -410,7 +410,7 @@ impl<'a, 'd> PostView<'a, 'd> {
self.note_context,
txn,
id.bytes(),
None,
nostrdb::NoteKey::new(0),
self.note_options,
self.jobs,
)

View File

@@ -39,6 +39,11 @@ pub enum ProfileViewAction {
Follow(Pubkey),
}
struct ProfileScrollResponse {
body_end_pos: f32,
action: Option<ProfileViewAction>,
}
impl<'a, 'd> ProfileView<'a, 'd> {
#[allow(clippy::too_many_arguments)]
pub fn new(
@@ -65,15 +70,13 @@ impl<'a, 'd> ProfileView<'a, 'd> {
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<ProfileViewAction> {
let scroll_id = ProfileView::scroll_id(self.col_id, self.pubkey);
let offset_id = scroll_id.with("scroll_offset");
let scroll_area = ScrollArea::vertical().id_salt(scroll_id).animated(false);
let mut scroll_area = ScrollArea::vertical().id_salt(scroll_id);
let profile_timeline = self
.timeline_cache
.get_mut(&TimelineKind::Profile(*self.pubkey))?;
if let Some(offset) = ui.data(|i| i.get_temp::<f32>(offset_id)) {
scroll_area = scroll_area.vertical_scroll_offset(offset);
}
let output = scroll_area.show(ui, |ui| 's: {
let output = scroll_area.show(ui, |ui| {
let mut action = None;
let txn = Transaction::new(self.note_context.ndb).expect("txn");
let profile = self
@@ -82,23 +85,19 @@ impl<'a, 'd> ProfileView<'a, 'd> {
.get_profile_by_pubkey(&txn, self.pubkey.bytes())
.ok();
if let Some(profile_view_action) = self.profile_body(ui, profile.as_ref()) {
if let Some(profile_view_action) =
profile_body(ui, self.pubkey, self.note_context, profile.as_ref())
{
action = Some(profile_view_action);
}
let Some(profile_timeline) = self
.timeline_cache
.get_mut(&TimelineKind::Profile(*self.pubkey))
else {
break 's action;
};
profile_timeline.selected_view = tabs_ui(
let tabs_resp = tabs_ui(
ui,
self.note_context.i18n,
profile_timeline.selected_view,
&profile_timeline.views,
);
profile_timeline.selected_view = tabs_resp.inner;
let reversed = false;
// poll for new notes and insert them into our existing notes
@@ -124,145 +123,147 @@ impl<'a, 'd> ProfileView<'a, 'd> {
action = Some(ProfileViewAction::Note(note_action));
}
action
ProfileScrollResponse {
body_end_pos: tabs_resp.response.rect.bottom(),
action,
}
});
ui.data_mut(|d| d.insert_temp(offset_id, output.state.offset.y));
// only allow front insert when the profile body is fully obstructed
profile_timeline.enable_front_insert = output.inner.body_end_pos < ui.clip_rect().top();
output.inner
output.inner.action
}
}
fn profile_body(
&mut self,
ui: &mut egui::Ui,
profile: Option<&ProfileRecord<'_>>,
) -> Option<ProfileViewAction> {
let mut action = None;
ui.vertical(|ui| {
banner(
ui,
profile
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.banner())),
120.0,
);
fn profile_body(
ui: &mut egui::Ui,
pubkey: &Pubkey,
note_context: &mut NoteContext,
profile: Option<&ProfileRecord<'_>>,
) -> Option<ProfileViewAction> {
let mut action = None;
ui.vertical(|ui| {
banner(
ui,
profile
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.banner())),
120.0,
);
let padding = 12.0;
notedeck_ui::padding(padding, ui, |ui| {
let mut pfp_rect = ui.available_rect_before_wrap();
let size = 80.0;
pfp_rect.set_width(size);
pfp_rect.set_height(size);
let pfp_rect = pfp_rect.translate(egui::vec2(0.0, -(padding + 2.0 + (size / 2.0))));
let padding = 12.0;
notedeck_ui::padding(padding, ui, |ui| {
let mut pfp_rect = ui.available_rect_before_wrap();
let size = 80.0;
pfp_rect.set_width(size);
pfp_rect.set_height(size);
let pfp_rect = pfp_rect.translate(egui::vec2(0.0, -(padding + 2.0 + (size / 2.0))));
ui.horizontal(|ui| {
ui.put(
pfp_rect,
&mut ProfilePic::new(self.note_context.img_cache, get_profile_url(profile))
.size(size)
.border(ProfilePic::border_stroke(ui)),
);
ui.horizontal(|ui| {
ui.put(
pfp_rect,
&mut ProfilePic::new(note_context.img_cache, get_profile_url(profile))
.size(size)
.border(ProfilePic::border_stroke(ui)),
);
if ui
.add(copy_key_widget(&pfp_rect, self.note_context.i18n))
.clicked()
{
let to_copy = if let Some(bech) = self.pubkey.npub() {
bech
} else {
error!("Could not convert Pubkey to bech");
String::new()
};
ui.ctx().copy_text(to_copy)
}
if ui
.add(copy_key_widget(&pfp_rect, note_context.i18n))
.clicked()
{
let to_copy = if let Some(bech) = pubkey.npub() {
bech
} else {
error!("Could not convert Pubkey to bech");
String::new()
};
ui.ctx().copy_text(to_copy)
}
ui.with_layout(Layout::right_to_left(egui::Align::RIGHT), |ui| {
ui.add_space(24.0);
ui.with_layout(Layout::right_to_left(egui::Align::RIGHT), |ui| {
ui.add_space(24.0);
let target_key = self.pubkey;
let selected = self.note_context.accounts.get_selected_account();
let target_key = pubkey;
let selected = note_context.accounts.get_selected_account();
let profile_type = if selected.key.secret_key.is_none() {
ProfileType::ReadOnly
} else if &selected.key.pubkey == self.pubkey {
ProfileType::MyProfile
} else {
ProfileType::Followable(selected.is_following(target_key.bytes()))
};
let profile_type = if selected.key.secret_key.is_none() {
ProfileType::ReadOnly
} else if &selected.key.pubkey == pubkey {
ProfileType::MyProfile
} else {
ProfileType::Followable(selected.is_following(target_key.bytes()))
};
match profile_type {
ProfileType::MyProfile => {
if ui
.add(edit_profile_button(self.note_context.i18n))
.clicked()
{
action = Some(ProfileViewAction::EditProfile);
}
match profile_type {
ProfileType::MyProfile => {
if ui.add(edit_profile_button(note_context.i18n)).clicked() {
action = Some(ProfileViewAction::EditProfile);
}
ProfileType::Followable(is_following) => {
let follow_button = ui.add(follow_button(is_following));
}
ProfileType::Followable(is_following) => {
let follow_button = ui.add(follow_button(is_following));
if follow_button.clicked() {
action = match is_following {
IsFollowing::Unknown => {
// don't do anything, we don't have contact list
None
}
if follow_button.clicked() {
action = match is_following {
IsFollowing::Unknown => {
// don't do anything, we don't have contact list
None
}
IsFollowing::Yes => {
Some(ProfileViewAction::Unfollow(target_key.to_owned()))
}
IsFollowing::Yes => {
Some(ProfileViewAction::Unfollow(target_key.to_owned()))
}
IsFollowing::No => {
Some(ProfileViewAction::Follow(target_key.to_owned()))
}
};
}
IsFollowing::No => {
Some(ProfileViewAction::Follow(target_key.to_owned()))
}
};
}
ProfileType::ReadOnly => {}
}
});
});
ui.add_space(18.0);
ui.add(display_name_widget(&get_display_name(profile), false));
ui.add_space(8.0);
ui.add(about_section_widget(profile));
ui.horizontal_wrapped(|ui| {
let website_url = profile
.as_ref()
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.website()).filter(|s| !s.is_empty()));
let lud16 = profile
.as_ref()
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.lud16()).filter(|s| !s.is_empty()));
if let Some(website_url) = website_url {
ui.horizontal(|ui| {
handle_link(ui, website_url);
});
}
if let Some(lud16) = lud16 {
if website_url.is_some() {
ui.end_row();
}
ui.horizontal(|ui| {
handle_lud16(ui, lud16);
});
ProfileType::ReadOnly => {}
}
});
});
});
action
}
ui.add_space(18.0);
ui.add(display_name_widget(&get_display_name(profile), false));
ui.add_space(8.0);
ui.add(about_section_widget(profile));
ui.horizontal_wrapped(|ui| {
let website_url = profile
.as_ref()
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.website()).filter(|s| !s.is_empty()));
let lud16 = profile
.as_ref()
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.lud16()).filter(|s| !s.is_empty()));
if let Some(website_url) = website_url {
ui.horizontal(|ui| {
handle_link(ui, website_url);
});
}
if let Some(lud16) = lud16 {
if website_url.is_some() {
ui.end_row();
}
ui.horizontal(|ui| {
handle_lud16(ui, lud16);
});
}
});
});
});
action
}
enum ProfileType {

View File

@@ -1,8 +1,9 @@
use egui::containers::scroll_area::ScrollBarVisibility;
use egui::{vec2, Color32, Direction, Layout, Margin, Pos2, ScrollArea, Sense, Stroke};
use egui::{vec2, Color32, Direction, Layout, Margin, Pos2, RichText, ScrollArea, Sense, Stroke};
use egui_tabs::TabColor;
use enostr::Pubkey;
use nostrdb::{Note, ProfileRecord, Transaction};
use notedeck::fonts::get_font_size;
use notedeck::name::get_display_name;
use notedeck::ui::is_narrow;
use notedeck::{tr_plural, JobsCache, Muted, NotedeckTextStyle};
@@ -118,7 +119,8 @@ fn timeline_ui(
note_context.i18n,
timeline.selected_view,
&timeline.views,
);
)
.inner;
// need this for some reason??
ui.add_space(3.0);
@@ -151,12 +153,6 @@ fn timeline_ui(
.auto_shrink([false, false])
.scroll_bar_visibility(ScrollBarVisibility::AlwaysVisible);
let offset_id = scroll_id.with("timeline_scroll_offset");
if let Some(offset) = ui.data(|i| i.get_temp::<f32>(offset_id)) {
scroll_area = scroll_area.vertical_scroll_offset(offset);
}
if goto_top_resp.is_some_and(|r| r.clicked()) {
scroll_area = scroll_area.vertical_scroll_offset(0.0);
}
@@ -195,8 +191,6 @@ fn timeline_ui(
.show(ui)
});
ui.data_mut(|d| d.insert_temp(offset_id, scroll_output.state.offset.y));
let at_top_after_scroll = scroll_output.state.offset.y == 0.0;
let cur_show_top_button = ui.ctx().data(|d| d.get_temp::<bool>(show_top_button_id));
@@ -284,7 +278,7 @@ pub fn tabs_ui(
i18n: &mut Localization,
selected: usize,
views: &[TimelineTab],
) -> usize {
) -> egui::InnerResponse<usize> {
ui.spacing_mut().item_spacing.y = 0.0;
let tab_res = egui_tabs::Tabs::new(views.len() as i32)
@@ -332,7 +326,9 @@ pub fn tabs_ui(
let sel = tab_res.selected().unwrap_or_default();
let (underline, underline_y) = tab_res.inner()[sel as usize].inner;
let res_inner = &tab_res.inner()[sel as usize];
let (underline, underline_y) = res_inner.inner;
let underline_width = underline.span();
let tab_anim_id = ui.id().with("tab_anim");
@@ -359,7 +355,7 @@ pub fn tabs_ui(
ui.painter().hline(underline, underline_y, stroke);
sel as usize
egui::InnerResponse::new(sel as usize, res_inner.response.clone())
}
fn get_label_width(ui: &mut egui::Ui, text: &str) -> f32 {
@@ -734,7 +730,7 @@ fn render_reaction_cluster(
fn render_composite_entry(
ui: &mut egui::Ui,
note_context: &mut NoteContext,
note_options: NoteOptions,
mut note_options: NoteOptions,
jobs: &mut JobsCache,
underlying_note: &nostrdb::Note<'_>,
profiles_to_show: Vec<ProfileEntry>,
@@ -760,6 +756,16 @@ fn render_composite_entry(
ReferencedNoteType::Yours
};
if !note_options.contains(NoteOptions::TrustMedia) {
let acc = note_context.accounts.get_selected_account();
for entry in &profiles_to_show {
if matches!(acc.is_following(entry.pk), notedeck::IsFollowing::Yes) {
note_options = note_options.union(NoteOptions::TrustMedia);
break;
}
}
}
egui::Frame::new()
.inner_margin(Margin::symmetric(8, 4))
.show(ui, |ui| {
@@ -829,7 +835,10 @@ fn render_composite_entry(
ui.horizontal(|ui| {
ui.add_space(48.0);
ui.horizontal_wrapped(|ui| {
ui.label(desc);
ui.add(egui::Label::new(
RichText::new(desc)
.size(get_font_size(ui.ctx(), &NotedeckTextStyle::Small)),
));
});
});
}
@@ -838,15 +847,14 @@ fn render_composite_entry(
let resp = ui
.horizontal(|ui| {
let mut options = note_options;
if options.contains(NoteOptions::Notification) {
options = options
if note_options.contains(NoteOptions::Notification) {
note_options = note_options
.difference(NoteOptions::ActionBar | NoteOptions::OptionsButton)
.union(NoteOptions::NotificationPreview);
ui.add_space(48.0);
};
NoteView::new(note_context, underlying_note, options, jobs).show(ui)
NoteView::new(note_context, underlying_note, note_options, jobs).show(ui)
})
.inner;