wip: refactor
This commit is contained in:
@@ -1,46 +1,28 @@
|
||||
use crate::states::chat::room::Member;
|
||||
use gpui::{
|
||||
div, img, prelude::FluentBuilder, InteractiveElement, IntoElement, ParentElement, RenderOnce,
|
||||
SharedString, Styled, WindowContext,
|
||||
div, img, InteractiveElement, IntoElement, ParentElement, RenderOnce, SharedString, Styled,
|
||||
WindowContext,
|
||||
};
|
||||
use nostr_sdk::prelude::*;
|
||||
use ui::{theme::ActiveTheme, StyledExt};
|
||||
|
||||
use crate::{
|
||||
constants::IMAGE_SERVICE,
|
||||
utils::{ago, show_npub},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, IntoElement)]
|
||||
pub struct RoomMessage {
|
||||
#[allow(dead_code)]
|
||||
author: PublicKey,
|
||||
fallback: SharedString,
|
||||
metadata: Metadata,
|
||||
pub struct Message {
|
||||
member: Member,
|
||||
content: SharedString,
|
||||
created_at: SharedString,
|
||||
ago: SharedString,
|
||||
}
|
||||
|
||||
impl RoomMessage {
|
||||
pub fn new(
|
||||
author: PublicKey,
|
||||
metadata: Metadata,
|
||||
content: String,
|
||||
created_at: Timestamp,
|
||||
) -> Self {
|
||||
let created_at = ago(created_at.as_u64()).into();
|
||||
let fallback = show_npub(author, 16).into();
|
||||
|
||||
impl Message {
|
||||
pub fn new(member: Member, content: SharedString, ago: SharedString) -> Self {
|
||||
Self {
|
||||
author,
|
||||
metadata,
|
||||
fallback,
|
||||
created_at,
|
||||
content: content.into(),
|
||||
member,
|
||||
content,
|
||||
ago,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for RoomMessage {
|
||||
impl RenderOnce for Message {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
div()
|
||||
.flex()
|
||||
@@ -54,19 +36,12 @@ impl RenderOnce for RoomMessage {
|
||||
.border_color(cx.theme().primary_active)
|
||||
.text_color(cx.theme().muted_foreground)
|
||||
})
|
||||
.child(div().flex_shrink_0().map(|this| {
|
||||
if let Some(picture) = self.metadata.picture {
|
||||
this.child(
|
||||
img(format!(
|
||||
"{}/?url={}&w=100&h=100&fit=cover&mask=circle&n=-1",
|
||||
IMAGE_SERVICE, picture
|
||||
))
|
||||
.size_8(),
|
||||
)
|
||||
} else {
|
||||
this.child(img("brand/avatar.png").size_8().rounded_full())
|
||||
}
|
||||
}))
|
||||
.child(
|
||||
img(self.member.avatar())
|
||||
.size_8()
|
||||
.rounded_full()
|
||||
.flex_shrink_0(),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
@@ -79,16 +54,10 @@ impl RenderOnce for RoomMessage {
|
||||
.items_baseline()
|
||||
.gap_2()
|
||||
.text_xs()
|
||||
.child(div().font_semibold().map(|this| {
|
||||
if let Some(display_name) = self.metadata.display_name {
|
||||
this.child(display_name)
|
||||
} else {
|
||||
this.child(self.fallback)
|
||||
}
|
||||
}))
|
||||
.child(div().font_semibold().child(self.member.name()))
|
||||
.child(
|
||||
div()
|
||||
.child(self.created_at)
|
||||
.child(self.ago)
|
||||
.text_color(cx.theme().muted_foreground),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user