84 lines
1.9 KiB
Rust
84 lines
1.9 KiB
Rust
//! Hermit instance configuration.
|
|
|
|
use crate::Id;
|
|
|
|
use std::collections::HashMap as Map;
|
|
|
|
/// The main configuration for any Hermit instance.
|
|
#[derive(Clone)]
|
|
pub struct Config {
|
|
/// The domain of the instance.
|
|
pub host: String,
|
|
/// The port to host the instance on. Defaults to `6969`.
|
|
pub port: u16,
|
|
/// Filtering rules applied to each activity.
|
|
pub rules: Vec<rule::Rule>,
|
|
/// Notification configuration for each local actor.
|
|
pub notify: Map<Id, Notify>,
|
|
}
|
|
|
|
impl Config {
|
|
/// Create a new default config.
|
|
pub fn new (hostname: impl ToString) -> Config {
|
|
let (notify, rules) = def();
|
|
Config {
|
|
host: hostname.to_string(),
|
|
port: 6969,
|
|
notify,
|
|
rules,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Controls when notifications should be sent.
|
|
#[derive(Clone, Copy)]
|
|
pub struct Notify {
|
|
/// Whether to send a notification when a post is liked.
|
|
pub post_liked: bool,
|
|
/// Whether to send a notification when a post is shared.
|
|
pub post_shared: bool,
|
|
/// Whether to send a notification when a follow request is received.
|
|
pub follow_requested: bool,
|
|
/// Whether to send a notification when a follow request is accepted.
|
|
pub new_follower: bool,
|
|
}
|
|
|
|
impl Default for Notify {
|
|
fn default () -> Self {
|
|
Notify {
|
|
post_liked: true,
|
|
post_shared: true,
|
|
follow_requested: true,
|
|
new_follower: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Shortcut for creating a default instance
|
|
fn def <T> () -> T where T: Default { T::default() }
|
|
|
|
pub mod rule {
|
|
|
|
//! Filtering rules for [`Activity`] data.
|
|
|
|
use crate::Activity;
|
|
|
|
/// A filtering rule.
|
|
#[derive(Clone)]
|
|
pub struct Rule (Inner);
|
|
|
|
impl Rule {
|
|
/// Apply the rule to the activity.
|
|
pub fn apply (&self, a: Activity) -> Option<Activity> {
|
|
match self.0 {}
|
|
}
|
|
}
|
|
|
|
/// When adding new filtering rules, add a variant to this
|
|
/// enum and write your implementation in the `apply` function
|
|
/// of [`Rule`].
|
|
#[derive(Clone)]
|
|
enum Inner {}
|
|
|
|
}
|