2023-06-06 16:27:22 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod build_response;
|
2023-10-09 10:46:12 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod claims;
|
2021-03-25 19:19:40 +00:00
|
|
|
pub mod comment;
|
|
|
|
pub mod community;
|
2022-11-28 14:29:33 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod context;
|
2023-03-20 21:32:31 +00:00
|
|
|
pub mod custom_emoji;
|
2021-03-25 19:19:40 +00:00
|
|
|
pub mod person;
|
|
|
|
pub mod post;
|
2022-09-19 22:58:42 +00:00
|
|
|
pub mod private_message;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod request;
|
2023-07-19 13:49:41 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod send_activity;
|
2022-05-06 20:55:07 +00:00
|
|
|
pub mod sensitive;
|
2021-03-25 19:19:40 +00:00
|
|
|
pub mod site;
|
2022-05-03 17:44:13 +00:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub mod utils;
|
2022-06-08 15:30:20 +00:00
|
|
|
|
|
|
|
pub extern crate lemmy_db_schema;
|
|
|
|
pub extern crate lemmy_db_views;
|
|
|
|
pub extern crate lemmy_db_views_actor;
|
|
|
|
pub extern crate lemmy_db_views_moderator;
|
2024-02-25 00:54:27 +00:00
|
|
|
pub extern crate lemmy_utils;
|
2023-10-09 10:46:12 +00:00
|
|
|
|
2024-02-25 00:54:27 +00:00
|
|
|
pub use lemmy_utils::LemmyErrorType;
|
2023-10-09 10:46:12 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2024-04-09 23:33:01 +00:00
|
|
|
use std::{cmp::min, time::Duration};
|
2023-10-09 10:46:12 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
#[cfg_attr(feature = "full", derive(ts_rs::TS))]
|
|
|
|
#[cfg_attr(feature = "full", ts(export))]
|
|
|
|
/// Saves settings for your user.
|
|
|
|
pub struct SuccessResponse {
|
|
|
|
pub success: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for SuccessResponse {
|
|
|
|
fn default() -> Self {
|
|
|
|
SuccessResponse { success: true }
|
|
|
|
}
|
|
|
|
}
|
2023-11-06 21:07:04 +00:00
|
|
|
|
2024-04-09 23:33:01 +00:00
|
|
|
// TODO: use from_days once stabilized
|
|
|
|
// https://github.com/rust-lang/rust/issues/120301
|
|
|
|
const DAY: Duration = Duration::from_secs(24 * 60 * 60);
|
|
|
|
|
|
|
|
/// Calculate how long to sleep until next federation send based on how many
|
|
|
|
/// retries have already happened. Uses exponential backoff with maximum of one day. The first
|
|
|
|
/// error is ignored.
|
2023-11-06 21:07:04 +00:00
|
|
|
pub fn federate_retry_sleep_duration(retry_count: i32) -> Duration {
|
2024-04-09 23:33:01 +00:00
|
|
|
debug_assert!(retry_count != 0);
|
|
|
|
if retry_count == 1 {
|
|
|
|
return Duration::from_secs(0);
|
|
|
|
}
|
|
|
|
let retry_count = retry_count - 1;
|
|
|
|
let pow = 1.25_f64.powf(retry_count.into());
|
|
|
|
let pow = Duration::try_from_secs_f64(pow).unwrap_or(DAY);
|
|
|
|
min(DAY, pow)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
pub(crate) mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_federate_retry_sleep_duration() {
|
|
|
|
assert_eq!(Duration::from_secs(0), federate_retry_sleep_duration(1));
|
|
|
|
assert_eq!(
|
|
|
|
Duration::new(1, 250000000),
|
|
|
|
federate_retry_sleep_duration(2)
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
Duration::new(2, 441406250),
|
|
|
|
federate_retry_sleep_duration(5)
|
|
|
|
);
|
|
|
|
assert_eq!(DAY, federate_retry_sleep_duration(100));
|
|
|
|
}
|
2023-11-06 21:07:04 +00:00
|
|
|
}
|