Skip to content

Commit c274ac9

Browse files
merge: main branch
2 parents 8265f2d + 931ca3f commit c274ac9

File tree

17 files changed

+611
-204
lines changed

17 files changed

+611
-204
lines changed

Cargo.lock

Lines changed: 37 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/chat/src/async_list.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt::Debug, future::Future, hash::Hash};
1+
use std::{fmt::Debug, future::Future, hash::Hash, sync::Arc};
22

33
pub trait AsyncList {
44
type Content: AsyncListItem;
@@ -12,7 +12,30 @@ pub trait AsyncList {
1212
fn bounded_at_bottom_by(&self) -> impl Future<Output = Option<<Self::Content as AsyncListItem>::Identifier>>;
1313
}
1414

15-
pub trait AsyncListItem: Clone + Debug {
15+
impl<L: AsyncList> AsyncList for Arc<L> {
16+
type Content = L::Content;
17+
18+
fn bounded_at_bottom_by(&self) -> impl Future<Output = Option<<Self::Content as AsyncListItem>::Identifier>> {
19+
(**self).bounded_at_bottom_by()
20+
}
21+
22+
fn bounded_at_top_by(&self) -> impl Future<Output = Option<<Self::Content as AsyncListItem>::Identifier>> {
23+
(**self).bounded_at_top_by()
24+
}
25+
26+
fn find(&self, identifier: &<Self::Content as AsyncListItem>::Identifier) -> impl Future<Output = Option<Self::Content>> {
27+
(**self).find(identifier)
28+
}
29+
30+
fn get(
31+
&self,
32+
index: AsyncListIndex<<Self::Content as AsyncListItem>::Identifier>,
33+
) -> impl Future<Output = Option<AsyncListResult<Self::Content>>> + Send {
34+
(**self).get(index)
35+
}
36+
}
37+
38+
pub trait AsyncListItem: Clone {
1639
type Identifier: Eq + Hash + Clone + Send + Debug;
1740

1841
fn get_list_identifier(&self) -> Self::Identifier;

src/chat/src/channel.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1+
use std::{fmt::Debug, sync::Arc};
2+
13
use tokio::sync::broadcast;
24

35
use crate::reaction::ReactionEvent;
46
use crate::{async_list::AsyncList, message::Message};
57

68
pub trait Channel: AsyncList<Content = Self::Message> + Send + Sync + Clone {
7-
type Message: Message;
9+
type Message: Message<Identifier = Self::Identifier>;
10+
type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq;
811

912
fn get_message_receiver(&self) -> broadcast::Receiver<Self::Message>;
1013
fn get_reaction_receiver(&self) -> broadcast::Receiver<ReactionEvent>;
1114

1215
fn send_message(&self, content: String, nonce: String) -> Self::Message;
16+
17+
fn get_identifier(&self) -> Self::Identifier;
18+
}
19+
20+
impl<C: Channel> Channel for Arc<C> {
21+
type Identifier = C::Identifier;
22+
type Message = C::Message;
23+
24+
fn get_identifier(&self) -> Self::Identifier {
25+
(**self).get_identifier()
26+
}
27+
28+
fn get_receiver(&self) -> broadcast::Receiver<Self::Message> {
29+
(**self).get_receiver()
30+
}
31+
32+
fn send_message(&self, content: String, nonce: String) -> Self::Message {
33+
(**self).send_message(content, nonce)
34+
}
1335
}

src/chat/src/client.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::{fmt::Debug, future::Future};
2+
3+
use crate::channel::Channel;
4+
5+
pub trait ClientConstructor<C: Client> {
6+
type ConstructorArguments;
7+
type ConstructorFailure;
8+
9+
fn construct(args: Self::ConstructorArguments) -> impl Future<Output = Result<C, Self::ConstructorFailure>>;
10+
}
11+
12+
pub trait Client {
13+
type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq;
14+
type Channel: Channel;
15+
16+
fn channel(identifier: Self::Identifier) -> impl Future<Output = Option<Self::Channel>>;
17+
}

src/chat/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod async_list;
22
pub mod channel;
3+
pub mod client;
34
pub mod message;
45
pub mod reaction;

src/chat/src/message.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
1+
use std::fmt::Debug;
2+
13
use chrono::{DateTime, Utc};
2-
use gpui::Element;
4+
use gpui::{IntoElement, Render, View, WindowContext};
35

46
use crate::async_list::AsyncListItem;
57
use crate::reaction::ReactionList;
68

79
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;
1218
fn should_group(&self, previous: &Self) -> bool;
1319
fn get_timestamp(&self) -> Option<DateTime<Utc>>;
1420
fn get_reactions(&mut self) -> &mut impl ReactionList;
1521
}
1622

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+
1749
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;
2257
}

src/discord/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ serenity = { git = "https://github.com/scopeclient/serenity", version = "0.12" }
1111
tokio = "1.41.1"
1212
chrono.workspace = true
1313
scope-backend-cache = { version = "0.1.0", path = "../cache" }
14+
url = "2.5.3"
15+
querystring = "1.1.0"
16+
catty = "0.1.5"
17+
atomic_refcell = "0.1.13"
18+
rand = "0.8.5"
19+
dashmap = "6.1.0"
1420
log = "0.4.22"

0 commit comments

Comments
 (0)