Skip to content

Commit

Permalink
Improve profile parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
akiomik committed Jan 9, 2024
1 parent 277ff9e commit 94a7c7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/components/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ use std::collections::{hash_map::Entry, HashMap};
use std::collections::{HashSet, VecDeque};

use color_eyre::eyre::Result;
use nostr_sdk::prelude::*;
use nostr_sdk::prelude::{Metadata as NostrMetadata, *};
use ratatui::{prelude::*, widgets, widgets::*};
use sorted_vec::ReverseSortedSet;
use tokio::sync::mpsc::UnboundedSender;
use tui_textarea::{Input, Key, TextArea};
use tui_textarea::{Key, TextArea};

use super::{Component, Frame};
use crate::{
action::Action, config::Config, nostr::SortableEvent, text, widgets::ScrollableList,
action::Action,
config::Config,
nostr::{Metadata, SortableEvent},
text,
widgets::ScrollableList,
widgets::TextNote,
};

Expand All @@ -21,7 +25,7 @@ pub struct Home<'a> {
config: Config,
list_state: ListState,
notes: ReverseSortedSet<SortableEvent>,
profiles: HashMap<XOnlyPublicKey, Metadata>,
profiles: HashMap<XOnlyPublicKey, NostrMetadata>,
reactions: HashMap<EventId, HashSet<Event>>,
reposts: HashMap<EventId, HashSet<Event>>,
zap_receipts: HashMap<EventId, HashSet<Event>>,
Expand Down Expand Up @@ -52,8 +56,9 @@ impl<'a> Home<'a> {
}

fn add_profile(&mut self, event: Event) {
if let Ok(metadata) = Metadata::from_json(event.content) {
self.profiles.insert(event.pubkey, metadata);
if let Ok(metadata) = Metadata::from_json(event.content.clone()) {
self.profiles
.insert(event.pubkey, NostrMetadata::from(metadata));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/nostr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mod metadata;
pub use connection::Connection;
pub use connection_process::ConnectionProcess;
pub use event::SortableEvent;
pub use metadata::Metadata;

0 comments on commit 94a7c7d

Please sign in to comment.