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,31 @@
use revolt_quark::{
models::{User, UserSettings},
Db, Result,
};
use rocket::serde::json::Json;
use serde::{Deserialize, Serialize};
/// # Fetch Options
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct OptionsFetchSettings {
/// Keys to fetch
keys: Vec<String>,
}
/// # Fetch Settings
///
/// Fetch settings from server filtered by keys.
///
/// This will return an object with the requested keys, each value is a tuple of `(timestamp, value)`, the value is the previously uploaded data.
#[openapi(tag = "Sync")]
#[post("/settings/fetch", data = "<options>")]
pub async fn req(
db: &Db,
user: User,
options: Json<OptionsFetchSettings>,
) -> Result<Json<UserSettings>> {
db.fetch_user_settings(&user.id, &options.into_inner().keys)
.await
.map(Json)
}

View File

@@ -0,0 +1,15 @@
use revolt_quark::{
models::{ChannelUnread, User},
Db, Result,
};
use rocket::serde::json::Json;
/// # Fetch Unreads
///
/// Fetch information about unread state on channels.
#[openapi(tag = "Sync")]
#[get("/unreads")]
pub async fn req(db: &Db, user: User) -> Result<Json<Vec<ChannelUnread>>> {
db.fetch_unreads(&user.id).await.map(Json)
}

View File

@@ -0,0 +1,10 @@
use rocket::Route;
use rocket_okapi::okapi::openapi3::OpenApi;
mod get_settings;
mod get_unreads;
mod set_settings;
pub fn routes() -> (Vec<Route>, OpenApi) {
openapi_get_routes_spec![get_settings::req, set_settings::req, get_unreads::req]
}

View File

@@ -0,0 +1,50 @@
use revolt_quark::models::User;
use revolt_quark::r#impl::generic::users::user_settings::UserSettingsImpl;
use revolt_quark::{Db, EmptyResponse, Result};
use chrono::prelude::*;
use rocket::serde::json::Json;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
type Data = HashMap<String, String>;
/// # Set Options
#[derive(FromForm, Serialize, Deserialize, JsonSchema)]
pub struct OptionsSetSettings {
/// Timestamp of settings change.
///
/// Used to avoid feedback loops.
timestamp: Option<i64>,
}
/// # Set Settings
///
/// Upload data to save to settings.
#[openapi(tag = "Sync")]
#[post("/settings/set?<options..>", data = "<data>")]
pub async fn req(
db: &Db,
user: User,
data: Json<Data>,
options: OptionsSetSettings,
) -> Result<EmptyResponse> {
let data = data.into_inner();
let current_time = Utc::now().timestamp_millis();
let timestamp = if let Some(timestamp) = options.timestamp {
if timestamp > current_time {
current_time
} else {
timestamp
}
} else {
current_time
};
let mut settings = HashMap::new();
for (key, data) in data {
settings.insert(key, (timestamp, data));
}
settings.set(db, &user.id).await.map(|_| EmptyResponse)
}