|
| 1 | +use std::fmt::Debug; |
| 2 | + |
1 | 3 | use chrono::{DateTime, Utc}; |
2 | | -use gpui::Element; |
| 4 | +use gpui::{IntoElement, Render, View, WindowContext}; |
3 | 5 |
|
4 | 6 | use crate::async_list::AsyncListItem; |
5 | 7 | use crate::reaction::ReactionList; |
6 | 8 |
|
7 | 9 | pub trait Message: Clone + AsyncListItem + Send { |
8 | | - fn get_author(&self) -> &impl MessageAuthor; |
9 | | - fn get_content(&self) -> impl Element; |
10 | | - fn get_identifier(&self) -> String; |
11 | | - fn get_nonce(&self) -> Option<&String>; |
| 10 | + type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq; |
| 11 | + type Author: MessageAuthor<Identifier = <Self as Message>::Identifier>; |
| 12 | + type Content: Render; |
| 13 | + |
| 14 | + fn get_author(&self) -> Self::Author; |
| 15 | + fn get_content(&self, cx: &mut WindowContext) -> View<Self::Content>; |
| 16 | + fn get_identifier(&self) -> Option<<Self as Message>::Identifier>; |
| 17 | + fn get_nonce(&self) -> impl PartialEq; |
12 | 18 | fn should_group(&self, previous: &Self) -> bool; |
13 | 19 | fn get_timestamp(&self) -> Option<DateTime<Utc>>; |
14 | 20 | fn get_reactions(&mut self) -> &mut impl ReactionList; |
15 | 21 | } |
16 | 22 |
|
| 23 | +#[derive(Debug, Clone, Copy)] |
| 24 | +pub struct IconRenderConfig { |
| 25 | + size: usize, |
| 26 | +} |
| 27 | + |
| 28 | +impl Default for IconRenderConfig { |
| 29 | + fn default() -> Self { |
| 30 | + IconRenderConfig { size: 1024 } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +impl IconRenderConfig { |
| 35 | + pub fn small() -> Self { |
| 36 | + IconRenderConfig { size: 32 } |
| 37 | + } |
| 38 | + |
| 39 | + pub fn with_size(mut self, size: usize) -> IconRenderConfig { |
| 40 | + self.size = size; |
| 41 | + self |
| 42 | + } |
| 43 | + |
| 44 | + pub fn size(&self) -> usize { |
| 45 | + self.size |
| 46 | + } |
| 47 | +} |
| 48 | + |
17 | 49 | pub trait MessageAuthor: PartialEq + Eq { |
18 | | - fn get_display_name(&self) -> impl Element; |
19 | | - fn get_icon(&self) -> String; |
20 | | - fn get_small_icon(&self) -> String; |
21 | | - fn get_id(&self) -> String; |
| 50 | + type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq; |
| 51 | + type DisplayName: IntoElement + Clone; |
| 52 | + type Icon: IntoElement + Clone; |
| 53 | + |
| 54 | + fn get_display_name(&self) -> Self::DisplayName; |
| 55 | + fn get_icon(&self, config: IconRenderConfig) -> Self::Icon; |
| 56 | + fn get_identifier(&self) -> Self::Identifier; |
22 | 57 | } |
0 commit comments