chore(monorepo): delta, january, quark

This commit is contained in:
Paul Makles
2022-06-02 00:04:22 +01:00
parent 5d8432e267
commit 2ce610e1e7
232 changed files with 18094 additions and 554 deletions

View File

@@ -0,0 +1,61 @@
use std::collections::HashSet;
use crate::models::channel::{Channel, FieldsChannel, PartialChannel};
use crate::{OverrideField, Result};
#[async_trait]
pub trait AbstractChannel: Sync + Send {
/// Fetch a channel by its id
async fn fetch_channel(&self, id: &str) -> Result<Channel>;
/// Fetch channels by their ids
async fn fetch_channels<'a>(&self, ids: &'a [String]) -> Result<Vec<Channel>>;
/// Insert a new channel into the database
async fn insert_channel(&self, channel: &Channel) -> Result<()>;
/// Update an existing channel using some data
/// ! TODO: we need separate Channel::update which also sends out the relevant events
/// ! also applies to other methods I guess, try to restrict event bound methods to
/// ! the models themselves instead of the abstract database
async fn update_channel(
&self,
id: &str,
channel: &PartialChannel,
remove: Vec<FieldsChannel>,
) -> Result<()>;
/// Delete a channel by its id
///
/// This will also delete all associated messages and files.
async fn delete_channel(&self, channel: &Channel) -> Result<()>;
/// Find all direct messages that a user is involved in
///
/// Returns group DMs, any DMs marked as "active" and saved messages.
async fn find_direct_messages(&self, user_id: &str) -> Result<Vec<Channel>>;
/// Find a direct message channel between two users
async fn find_direct_message_channel(&self, user_a: &str, user_b: &str) -> Result<Channel>;
/// Find a saved message channel owned by a user
async fn find_saved_messages_channel(&self, user_id: &str) -> Result<Channel>;
/// Add user to a group
async fn add_user_to_group(&self, channel: &str, user: &str) -> Result<()>;
/// Remove a user from a group
async fn remove_user_from_group(&self, channel: &str, user: &str) -> Result<()>;
/// Set role permission for a channel
/// ! FIXME: may want to refactor to just use normal updates
async fn set_channel_role_permission(
&self,
channel: &str,
role: &str,
permissions: OverrideField,
) -> Result<()>;
/// Validate existence of channels
async fn check_channels_exist(&self, channels: &HashSet<String>) -> Result<bool>;
}

View File

@@ -0,0 +1,17 @@
use crate::models::Invite;
use crate::Result;
#[async_trait]
pub trait AbstractChannelInvite: Sync + Send {
/// Fetch an invite by its id
async fn fetch_invite(&self, code: &str) -> Result<Invite>;
/// Insert a new invite into the database
async fn insert_invite(&self, invite: &Invite) -> Result<()>;
/// Delete an invite by its id
async fn delete_invite(&self, code: &str) -> Result<()>;
/// Fetch all invites for a server
async fn fetch_invites_for_server(&self, server: &str) -> Result<Vec<Invite>>;
}

View File

@@ -0,0 +1,22 @@
use crate::models::channel_unread::ChannelUnread;
use crate::Result;
#[async_trait]
pub trait AbstractChannelUnread: Sync + Send {
/// Acknowledge a message.
async fn acknowledge_message(&self, channel: &str, user: &str, message: &str) -> Result<()>;
/// Acknowledge many channels.
async fn acknowledge_channels(&self, user: &str, channels: &[String]) -> Result<()>;
/// Add a mention.
async fn add_mention_to_unread<'a>(
&self,
channel: &str,
user: &str,
ids: &[String],
) -> Result<()>;
/// Fetch all channel unreads for a user.
async fn fetch_unreads(&self, user: &str) -> Result<Vec<ChannelUnread>>;
}

View File

@@ -0,0 +1,45 @@
use crate::models::message::{AppendMessage, Message, MessageSort, PartialMessage};
use crate::Result;
#[async_trait]
pub trait AbstractMessage: Sync + Send {
/// Fetch a message by its id
async fn fetch_message(&self, id: &str) -> Result<Message>;
/// Insert a new message into the database
async fn insert_message(&self, message: &Message) -> Result<()>;
/// Update a given message with new information
async fn update_message(&self, id: &str, message: &PartialMessage) -> Result<()>;
/// Append information to a given message
async fn append_message(&self, id: &str, append: &AppendMessage) -> Result<()>;
/// Delete a message from the database by its id
async fn delete_message(&self, id: &str) -> Result<()>;
/// Delete messages from a channel by their ids and corresponding channel id
async fn delete_messages(&self, channel: &str, ids: Vec<String>) -> Result<()>;
/// Fetch multiple messages
async fn fetch_messages(
&self,
channel: &str,
limit: Option<i64>,
before: Option<String>,
after: Option<String>,
sort: Option<MessageSort>,
nearby: Option<String>,
) -> Result<Vec<Message>>;
/// Search for messages
async fn search_messages(
&self,
channel: &str,
query: &str,
limit: Option<i64>,
before: Option<String>,
after: Option<String>,
sort: MessageSort,
) -> Result<Vec<Message>>;
}