chore: refactor tasks into quark

This commit is contained in:
Paul Makles
2022-04-21 13:52:35 +01:00
parent 3adbf29060
commit 5ce0c133e8
15 changed files with 18 additions and 551 deletions

View File

@@ -1,8 +1,9 @@
use crate::util::{regex::RE_USERNAME, variables::MAX_BOT_COUNT};
use crate::util::regex::RE_USERNAME;
use nanoid::nanoid;
use revolt_quark::{
models::{user::BotInformation, Bot, User},
variables::delta::MAX_BOT_COUNT,
Db, Error, Result,
};

View File

@@ -3,6 +3,7 @@ use std::{collections::HashSet, iter::FromIterator};
use revolt_quark::{
get_relationship,
models::{user::RelationshipStatus, Channel, User},
variables::delta::MAX_GROUP_SIZE,
Db, Error, Result,
};
@@ -11,8 +12,6 @@ use serde::{Deserialize, Serialize};
use ulid::Ulid;
use validator::Validate;
use crate::util::variables::MAX_GROUP_SIZE;
/// # Group Data
#[derive(Validate, Serialize, Deserialize, JsonSchema)]
pub struct DataCreateGroup {

View File

@@ -81,7 +81,7 @@ pub async fn req(
// Queue up a task for processing embeds
if let Some(content) = edit.content {
crate::tasks::process_embeds::queue(
revolt_quark::tasks::process_embeds::queue(
message.channel.to_string(),
message.id.to_string(),
content,

View File

@@ -3,12 +3,9 @@ use std::collections::HashSet;
use revolt_quark::{
models::{
message::{Content, Masquerade, Reply, SendableEmbed},
Channel, Message, User,
Message, User,
},
perms,
presence::presence_filter_online,
types::push::PushNotification,
Db, Error, Permission, Ref, Result,
perms, Db, Error, Permission, Ref, Result,
};
use regex::Regex;
@@ -18,7 +15,6 @@ use ulid::Ulid;
use validator::Validate;
use crate::util::idempotency::IdempotencyKey;
use crate::util::variables::{APP_URL, AUTUMN_URL, PUBLIC_URL};
#[derive(Validate, Serialize, Deserialize, JsonSchema)]
pub struct DataMessageSend {
@@ -175,58 +171,15 @@ pub async fn message_send(
// 7. Pass-through nonce value for clients
message.nonce = Some(idempotency.into_key());
message.create(db).await?;
message.create(db, &channel, Some(&user)).await?;
// Queue up a task for processing embeds
crate::tasks::process_embeds::queue(
revolt_quark::tasks::process_embeds::queue(
channel.id().to_string(),
message.id.to_string(),
data.content,
)
.await;
// ! FIXME: this should be part of quark.
// ! Actually, so should be the thing above
// ! probably the entire task queue system
// ! should be moved
crate::tasks::web_push::queue(
{
let mut target_ids = vec![];
match &channel {
Channel::DirectMessage { recipients, .. } | Channel::Group { recipients, .. } => {
target_ids = (&recipients.iter().cloned().collect::<HashSet<String>>()
- &presence_filter_online(recipients).await)
.into_iter()
.collect::<Vec<String>>();
}
Channel::TextChannel { .. } => {
if let Some(mentions) = &message.mentions {
target_ids.append(&mut mentions.clone());
}
}
_ => {}
};
target_ids
},
json!(PushNotification::new(
message.clone(),
user,
channel.id(),
&*AUTUMN_URL,
&*PUBLIC_URL,
&*APP_URL,
))
.to_string(),
)
.await;
// ! ANOTHER ONE
crate::tasks::last_message_id::queue(
channel.id().to_string(),
message.id.to_string(),
channel.is_direct_dm(),
)
.await;
Ok(Json(message))
}

View File

@@ -1,13 +1,12 @@
use revolt_quark::{
models::{Channel, Invite, Server, User},
variables::delta::MAX_SERVER_COUNT,
Db, Error, Ref, Result,
};
use rocket::serde::json::Json;
use serde::Serialize;
use crate::util::variables::MAX_SERVER_COUNT;
/// # Join Response
#[derive(Serialize, JsonSchema)]
#[serde(tag = "type")]

View File

@@ -1,14 +1,13 @@
use crate::util::variables::{
use revolt_quark::variables::delta::{
APP_URL, AUTUMN_URL, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, JANUARY_URL, USE_AUTUMN,
USE_EMAIL, USE_HCAPTCHA, USE_JANUARY, USE_VOSO, VAPID_PUBLIC_KEY, VOSO_URL, VOSO_WS_HOST,
};
use revolt_quark::Result;
use rocket::http::Status;
use rocket::serde::json::Json;
use serde::Serialize;
use revolt_quark::Result;
/// # hCaptcha Configuration
#[derive(Serialize, JsonSchema, Debug)]
pub struct CaptchaFeature {

View File

@@ -2,6 +2,7 @@ use std::collections::HashMap;
use revolt_quark::{
models::{Channel, Server, User},
variables::delta::MAX_SERVER_COUNT,
Db, Error, Result, DEFAULT_PERMISSION_SERVER,
};
@@ -10,8 +11,6 @@ use serde::{Deserialize, Serialize};
use ulid::Ulid;
use validator::Validate;
use crate::util::variables::MAX_SERVER_COUNT;
/// # Server Data
#[derive(Validate, Deserialize, JsonSchema)]
pub struct DataCreateServer {