wip: refactor

This commit is contained in:
2025-01-02 08:34:10 +07:00
parent 3a2e5cb4ab
commit d53e75b775
21 changed files with 188 additions and 211 deletions

View File

@@ -1,8 +1,8 @@
use coop_ui::{theme::ActiveTheme, StyledExt};
use gpui::*;
use nostr_sdk::prelude::*;
use prelude::FluentBuilder;
use std::sync::Arc;
use ui::{theme::ActiveTheme, StyledExt};
use crate::{
constants::IMAGE_SERVICE,
@@ -12,23 +12,18 @@ use crate::{
views::app::{AddPanel, PanelKind},
};
pub struct InboxItem {
pub struct InboxListItem {
id: SharedString,
event: Event,
metadata: Model<Option<Metadata>>,
}
impl InboxItem {
impl InboxListItem {
pub fn new(event: Event, cx: &mut ViewContext<'_, Self>) -> Self {
let pubkeys: Vec<PublicKey> = event.tags.public_keys().copied().collect();
let id = get_room_id(&event.pubkey, &pubkeys).into();
let metadata = cx.new_model(|_| None);
drop(pubkeys);
// Request metadata
_ = cx.global::<SignalRegistry>().tx.send(event.pubkey);
// Reload when received metadata
cx.observe_global::<MetadataRegistry>(|chat, cx| {
chat.load_metadata(cx);
@@ -42,6 +37,10 @@ impl InboxItem {
}
}
pub fn request_metadata(&mut self, cx: &mut ViewContext<Self>) {
_ = cx.global::<SignalRegistry>().tx.send(self.event.pubkey);
}
pub fn load_metadata(&mut self, cx: &mut ViewContext<Self>) {
let public_key = self.event.pubkey;
let async_metadata = self.metadata.clone();
@@ -74,12 +73,12 @@ impl InboxItem {
cx.dispatch_action(Box::new(AddPanel {
panel: PanelKind::Room(room),
position: coop_ui::dock::DockPlacement::Center,
position: ui::dock::DockPlacement::Center,
}))
}
}
impl Render for InboxItem {
impl Render for InboxListItem {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let ago = ago(self.event.created_at.as_u64());
let fallback_name = show_npub(self.event.pubkey, 16);