Skip to content

Commit d09a0ce

Browse files
committed
chore: display profile's display name in reaction tooltip
1 parent 15d4623 commit d09a0ce

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

crates/rostra-core/src/event.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ array_type_define!(
237237
64
238238
);
239239

240+
impl fmt::Display for EventSignature {
241+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
242+
data_encoding::BASE64URL_NOPAD.encode_write(&self.0, f)
243+
}
244+
}
245+
240246
#[cfg_attr(feature = "bincode", derive(::bincode::Encode, ::bincode::Decode))]
241247
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
242248
pub struct EventKind([u8; 2]);

crates/rostra-core/src/id.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ array_type_define_public!(struct ShortRostraId, 16);
131131

132132
array_type_define_public!(struct RestRostraId, 16);
133133

134+
impl fmt::Display for RestRostraId {
135+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136+
data_encoding::BASE64URL_NOPAD.encode_write(&self.0, f)
137+
}
138+
}
134139
impl fmt::Display for ShortRostraId {
135140
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136141
f.write_str("rs")?;

crates/rostra-core/src/macros.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ macro_rules! array_type_define {
66
) => {
77
$(#[$outer])*
88
#[cfg_attr(feature = "bincode", derive(::bincode::Encode, ::bincode::Decode))]
9-
#[derive(Copy, Clone, Hash, Debug)]
9+
#[derive(Copy, Clone, Hash)]
1010
pub struct $t([u8; $n]);
1111

1212
impl $t {
@@ -26,6 +26,12 @@ macro_rules! array_type_define {
2626
self.0
2727
}
2828
}
29+
30+
impl std::fmt::Debug for $t {
31+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32+
<Self as std::fmt::Display>::fmt(self, f)
33+
}
34+
}
2935
}
3036
}
3137

crates/rostra-web-ui/src/routes/timeline.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashSet;
1+
use std::collections::{HashMap, HashSet};
22
use std::time::Duration;
33

44
use axum::extract::ws::WebSocket;
@@ -534,12 +534,37 @@ impl UiState {
534534
vec![]
535535
};
536536

537+
let mut reaction_social_profiles: HashMap<RostraId, IdSocialProfileRecord> = HashMap::new();
538+
539+
for reaction_author in reactions
540+
.iter()
541+
.map(|reaction| reaction.author)
542+
// collect to deduplicate
543+
.collect::<HashSet<_>>()
544+
{
545+
// TODO: make a batched request for all profiles in one go
546+
if let Some(reaction_user_profile) =
547+
self.get_social_profile_opt(reaction_author, client).await
548+
{
549+
// HashSet above must have deduped it
550+
assert!(reaction_social_profiles
551+
.insert(reaction_author, reaction_user_profile)
552+
.is_none());
553+
}
554+
}
555+
537556
let reactions_html = html! {
538557
@for reaction in reactions {
539558
@if let Some(reaction_text) = reaction.content.get_reaction() {
540559

541560
span .m-postOverview__reaction
542-
title=(format!("by {}", reaction.author))
561+
title=(
562+
format!("by {}",
563+
reaction_social_profiles.get(&reaction.author)
564+
.map(|r| r.display_name.clone())
565+
.unwrap_or_else(|| reaction.author.to_string())
566+
)
567+
)
543568
{
544569
(reaction_text)
545570
}

0 commit comments

Comments
 (0)