Skip to content

Merge Refactor into main #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
46 changes: 39 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions src/chat/src/async_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Debug, future::Future, hash::Hash};
use std::{fmt::Debug, future::Future, hash::Hash, sync::Arc};

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

pub trait AsyncListItem: Clone + Debug {
impl<L: AsyncList> AsyncList for Arc<L> {
type Content = L::Content;

fn bounded_at_bottom_by(&self) -> impl Future<Output = Option<<Self::Content as AsyncListItem>::Identifier>> {
(**self).bounded_at_bottom_by()
}

fn bounded_at_top_by(&self) -> impl Future<Output = Option<<Self::Content as AsyncListItem>::Identifier>> {
(**self).bounded_at_top_by()
}

fn find(&self, identifier: &<Self::Content as AsyncListItem>::Identifier) -> impl Future<Output = Option<Self::Content>> {
(**self).find(identifier)
}

fn get(
&self,
index: AsyncListIndex<<Self::Content as AsyncListItem>::Identifier>,
) -> impl Future<Output = Option<AsyncListResult<Self::Content>>> + Send {
(**self).get(index)
}
}

pub trait AsyncListItem: Clone {
type Identifier: Eq + Hash + Clone + Send + Debug;

fn get_list_identifier(&self) -> Self::Identifier;
Expand Down
24 changes: 23 additions & 1 deletion src/chat/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
use std::{fmt::Debug, sync::Arc};

use tokio::sync::broadcast;

use crate::{async_list::AsyncList, message::Message};

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

fn get_receiver(&self) -> broadcast::Receiver<Self::Message>;

fn send_message(&self, content: String, nonce: String) -> Self::Message;

fn get_identifier(&self) -> Self::Identifier;
}

impl<C: Channel> Channel for Arc<C> {
type Identifier = C::Identifier;
type Message = C::Message;

fn get_identifier(&self) -> Self::Identifier {
(**self).get_identifier()
}

fn get_receiver(&self) -> broadcast::Receiver<Self::Message> {
(**self).get_receiver()
}

fn send_message(&self, content: String, nonce: String) -> Self::Message {
(**self).send_message(content, nonce)
}
}
17 changes: 17 additions & 0 deletions src/chat/src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::{fmt::Debug, future::Future};

use crate::channel::Channel;

pub trait ClientConstructor<C: Client> {
type ConstructorArguments;
type ConstructorFailure;

fn construct(args: Self::ConstructorArguments) -> impl Future<Output = Result<C, Self::ConstructorFailure>>;
}

pub trait Client {
type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq;
type Channel: Channel;

fn channel(identifier: Self::Identifier) -> impl Future<Output = Option<Self::Channel>>;
}
1 change: 1 addition & 0 deletions src/chat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod async_list;
pub mod channel;
pub mod client;
pub mod message;
53 changes: 44 additions & 9 deletions src/chat/src/message.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
use std::fmt::Debug;

use chrono::{DateTime, Utc};
use gpui::Element;
use gpui::{IntoElement, Render, View, WindowContext};

use crate::async_list::AsyncListItem;

pub trait Message: Clone + AsyncListItem + Send {
fn get_author(&self) -> &impl MessageAuthor;
fn get_content(&self) -> impl Element;
fn get_identifier(&self) -> String;
fn get_nonce(&self) -> Option<&String>;
type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq;
type Author: MessageAuthor<Identifier = <Self as Message>::Identifier>;
type Content: Render;

fn get_author(&self) -> Self::Author;
fn get_content(&self, cx: &mut WindowContext) -> View<Self::Content>;
fn get_identifier(&self) -> Option<<Self as Message>::Identifier>;
fn get_nonce(&self) -> impl PartialEq;
fn should_group(&self, previous: &Self) -> bool;
fn get_timestamp(&self) -> Option<DateTime<Utc>>;
}

#[derive(Debug, Clone, Copy)]
pub struct IconRenderConfig {
size: usize,
}

impl Default for IconRenderConfig {
fn default() -> Self {
IconRenderConfig { size: 1024 }
}
}

impl IconRenderConfig {
pub fn small() -> Self {
IconRenderConfig { size: 32 }
}

pub fn with_size(mut self, size: usize) -> IconRenderConfig {
self.size = size;
self
}

pub fn size(&self) -> usize {
self.size
}
}

pub trait MessageAuthor: PartialEq + Eq {
fn get_display_name(&self) -> impl Element;
fn get_icon(&self) -> String;
fn get_small_icon(&self) -> String;
fn get_id(&self) -> String;
type Identifier: Sized + Copy + Clone + Debug + Eq + PartialEq;
type DisplayName: IntoElement + Clone;
type Icon: IntoElement + Clone;

fn get_display_name(&self) -> Self::DisplayName;
fn get_icon(&self, config: IconRenderConfig) -> Self::Icon;
fn get_identifier(&self) -> Self::Identifier;
}
8 changes: 7 additions & 1 deletion src/discord/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ edition = "2021"
[dependencies]
gpui.workspace = true
scope-chat = { version = "0.1.0", path = "../chat" }
serenity = { git = "https://github.com/scopeclient/serenity", version = "0.12" }
serenity = { git = "https://github.com/scopeclient/serenity", version = "0.12", branch = "dev" }
tokio = "1.41.1"
chrono.workspace = true
scope-backend-cache = { version = "0.1.0", path = "../cache" }
url = "2.5.3"
querystring = "1.1.0"
catty = "0.1.5"
atomic_refcell = "0.1.13"
rand = "0.8.5"
dashmap = "6.1.0"
Loading
Loading