Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/chat/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use gpui::Element;
pub trait Message: Clone {
fn get_author(&self) -> &impl MessageAuthor;
fn get_content(&self) -> impl Element;
fn get_images(&self) -> impl Element;
fn get_identifier(&self) -> String;
fn get_nonce(&self) -> Option<&String>;
}
Expand Down
6 changes: 5 additions & 1 deletion src/discord/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
client::DiscordClient,
message::{
author::{DiscordMessageAuthor, DisplayName},
content::DiscordMessageContent,
content::{DiscordImageContent, DiscordMessageContent},
DiscordMessage,
},
snowflake::Snowflake,
Expand Down Expand Up @@ -53,6 +53,10 @@ impl Channel for DiscordChannel {
DiscordMessage {
content: DiscordMessageContent { content, is_pending: true },
author: self.client.user().clone(),
images: DiscordImageContent {
images: vec![],
is_pending: true,
},
id: Snowflake { content: 0 },
nonce: Some(nonce),
}
Expand Down
17 changes: 16 additions & 1 deletion src/discord/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio::sync::{broadcast, Mutex, RwLock};
use crate::{
message::{
author::{DiscordMessageAuthor, DisplayName},
content::DiscordMessageContent,
content::{DiscordImageContent, DiscordMessageContent},
DiscordMessage,
},
snowflake::{self, Snowflake},
Expand Down Expand Up @@ -108,6 +108,21 @@ impl EventHandler for DiscordClient {
display_name: DisplayName(msg.author.name.clone()),
icon: msg.author.avatar_url().unwrap_or(msg.author.default_avatar_url()),
},
images: DiscordImageContent {
images: msg
.attachments
.clone()
.into_iter()
.filter(|attachment| {
if let Some(content_type) = &attachment.content_type {
content_type.starts_with("image/")
} else {
false
}
})
.collect(),
is_pending: false,
},
content: DiscordMessageContent {
content: msg.content.clone(),
is_pending: false,
Expand Down
16 changes: 15 additions & 1 deletion src/discord/src/message/content.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
use gpui::{div, IntoElement, ParentElement, Render, RenderOnce, Styled, WindowContext};
use gpui::{div, img, px, IntoElement, ParentElement, Render, RenderOnce, Styled, WindowContext};
use serenity::all::Attachment;

#[derive(Clone, IntoElement)]
pub struct DiscordMessageContent {
pub content: String,
pub is_pending: bool,
}

#[derive(Clone, IntoElement)]
pub struct DiscordImageContent {
pub images: Vec<Attachment>,
pub is_pending: bool,
}

impl RenderOnce for DiscordMessageContent {
fn render(self, _: &mut WindowContext) -> impl IntoElement {
div().opacity(if self.is_pending { 0.25 } else { 1.0 }).child(self.content.clone())
}
}
impl RenderOnce for DiscordImageContent {
fn render(self, _: &mut WindowContext) -> impl IntoElement {
div()
.opacity(if self.is_pending { 0.25 } else { 1.0 })
.children(self.images.into_iter().map(|image| img(image.url).object_fit(gpui::ObjectFit::Contain).rounded_2xl().h(px(128.)).w(px(128.))))
}
}
7 changes: 6 additions & 1 deletion src/discord/src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use author::DiscordMessageAuthor;
use content::DiscordMessageContent;
use content::{DiscordImageContent, DiscordMessageContent};
use gpui::{Element, IntoElement};
use scope_chat::message::Message;

Expand All @@ -11,6 +11,7 @@ pub mod content;
#[derive(Clone)]
pub struct DiscordMessage {
pub content: DiscordMessageContent,
pub images: DiscordImageContent,
pub author: DiscordMessageAuthor,
pub id: Snowflake,
pub nonce: Option<String>,
Expand All @@ -25,6 +26,10 @@ impl Message for DiscordMessage {
self.content.clone().into_element()
}

fn get_images(&self) -> impl Element {
self.images.clone().into_element()
}

fn get_identifier(&self) -> String {
self.id.to_string()
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ pub fn message(message: impl Message) -> impl IntoElement {
.gap_2()
.p_2()
.child(img(message.get_author().get_icon()).object_fit(gpui::ObjectFit::Fill).bg(rgb(0xFFFFFF)).rounded_full().w_12().h_12())
.child(div().flex().flex_col().child(message.get_author().get_display_name()).child(message.get_content()))
.child(div().flex().flex_col().child(message.get_author().get_display_name()).child(message.get_content()).child(message.get_images()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one other thing: this will conflict now that #11 is merged. Changing content should fix this though.

}
Loading