commit 093cf8c72062ff95e64101a8314f4333fa9f1ef9
parent be3edc02a41c05d749f6ed5ef0dbc7b00c65de7b
Author: William Casarin <jb55@jb55.com>
Date: Thu, 5 Dec 2024 10:26:15 -0800
column: switch to simplified strings for column headers
This uses less allocations, and once we switch to profile pictures in
the header the old way won't be needed
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 28 insertions(+), 81 deletions(-)
diff --git a/src/route.rs b/src/route.rs
@@ -1,16 +1,15 @@
use enostr::{NoteId, Pubkey};
-use nostrdb::{Ndb, Transaction};
use serde::{Deserialize, Serialize};
-use std::fmt::{self};
+use std::{
+ borrow::Cow,
+ fmt::{self},
+};
use crate::{
accounts::AccountsRoute,
column::Columns,
timeline::{TimelineId, TimelineRoute},
- ui::{
- add_column::AddColumnRoute,
- profile::preview::{get_note_users_displayname_string, get_profile_displayname_string},
- },
+ ui::add_column::AddColumnRoute,
};
/// App routing. These describe different places you can go inside Notedeck.
@@ -65,61 +64,37 @@ impl Route {
Route::Accounts(AccountsRoute::AddAccount)
}
- pub fn title(&self, columns: &Columns, ndb: &Ndb) -> String {
+ pub fn title(&self, columns: &Columns) -> Cow<'static, str> {
match self {
Route::Timeline(tlr) => match tlr {
TimelineRoute::Timeline(id) => {
let timeline = columns
.find_timeline(*id)
.expect("expected to find timeline");
- timeline.kind.to_title(ndb)
- }
- TimelineRoute::Thread(id) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Thread",
- get_note_users_displayname_string(&txn, ndb, id)
- )
- }
- TimelineRoute::Reply(id) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Reply",
- get_note_users_displayname_string(&txn, ndb, id)
- )
- }
- TimelineRoute::Quote(id) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Quote",
- get_note_users_displayname_string(&txn, ndb, id)
- )
- }
- TimelineRoute::Profile(pubkey) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Profile",
- get_profile_displayname_string(&txn, ndb, pubkey)
- )
+ timeline.kind.to_title()
}
+ TimelineRoute::Thread(_id) => Cow::Borrowed("Thread"),
+ TimelineRoute::Reply(_id) => Cow::Borrowed("Reply"),
+ TimelineRoute::Quote(_id) => Cow::Borrowed("Quote"),
+ TimelineRoute::Profile(_pubkey) => Cow::Borrowed("Profile"),
},
- Route::Relays => "Relays".to_owned(),
+ Route::Relays => Cow::Borrowed("Relays"),
Route::Accounts(amr) => match amr {
- AccountsRoute::Accounts => "Accounts".to_owned(),
- AccountsRoute::AddAccount => "Add Account".to_owned(),
+ AccountsRoute::Accounts => Cow::Borrowed("Accounts"),
+ AccountsRoute::AddAccount => Cow::Borrowed("Add Account"),
},
- Route::ComposeNote => "Compose Note".to_owned(),
+ Route::ComposeNote => Cow::Borrowed("Compose Note"),
Route::AddColumn(c) => match c {
- AddColumnRoute::Base => "Add Column".to_owned(),
- AddColumnRoute::UndecidedNotification => "Add Notifications Column".to_owned(),
+ AddColumnRoute::Base => Cow::Borrowed("Add Column"),
+ AddColumnRoute::UndecidedNotification => Cow::Borrowed("Add Notifications Column"),
AddColumnRoute::ExternalNotification => {
- "Add External Notifications Column".to_owned()
+ Cow::Borrowed("Add External Notifications Column")
}
- AddColumnRoute::Hashtag => "Add Hashtag Column".to_owned(),
+ AddColumnRoute::Hashtag => Cow::Borrowed("Add Hashtag Column"),
},
- Route::Support => "Damus Support".to_owned(),
+ Route::Support => Cow::Borrowed("Damus Support"),
}
}
}
diff --git a/src/timeline/kind.rs b/src/timeline/kind.rs
@@ -2,11 +2,10 @@ use crate::error::{Error, FilterError};
use crate::filter;
use crate::filter::FilterState;
use crate::timeline::Timeline;
-use crate::ui::profile::preview::get_profile_displayname_string;
use enostr::{Filter, Pubkey};
use nostrdb::{Ndb, Transaction};
use serde::{Deserialize, Serialize};
-use std::fmt::Display;
+use std::{borrow::Cow, fmt::Display};
use tracing::{error, warn};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -194,43 +193,16 @@ impl TimelineKind {
}
}
- pub fn to_title(&self, ndb: &Ndb) -> String {
+ pub fn to_title(&self) -> Cow<'static, str> {
match self {
TimelineKind::List(list_kind) => match list_kind {
- ListKind::Contact(pubkey_source) => match pubkey_source {
- PubkeySource::Explicit(pubkey) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Contacts",
- get_profile_displayname_string(&txn, ndb, pubkey)
- )
- }
- PubkeySource::DeckAuthor => "Contacts".to_owned(),
- },
- },
- TimelineKind::Notifications(pubkey_source) => match pubkey_source {
- PubkeySource::DeckAuthor => "Notifications".to_owned(),
- PubkeySource::Explicit(pk) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Notifications",
- get_profile_displayname_string(&txn, ndb, pk)
- )
- }
- },
- TimelineKind::Profile(pubkey_source) => match pubkey_source {
- PubkeySource::DeckAuthor => "Profile".to_owned(),
- PubkeySource::Explicit(pk) => {
- let txn = Transaction::new(ndb).expect("txn");
- format!(
- "{}'s Profile",
- get_profile_displayname_string(&txn, ndb, pk)
- )
- }
+ ListKind::Contact(_pubkey_source) => Cow::Borrowed("Contacts"),
},
- TimelineKind::Universe => "Universe".to_owned(),
- TimelineKind::Generic => "Custom Filter".to_owned(),
- TimelineKind::Hashtag(hashtag) => format!("#{}", hashtag),
+ TimelineKind::Notifications(_pubkey_source) => Cow::Borrowed("Notifications"),
+ TimelineKind::Profile(_pubkey_source) => Cow::Borrowed("Profile"),
+ TimelineKind::Universe => Cow::Borrowed("Universe"),
+ TimelineKind::Generic => Cow::Borrowed("Custom"),
+ TimelineKind::Hashtag(hashtag) => Cow::Owned(format!("#{}", hashtag)),
}
}
}