1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#[macro_use]
extern crate log;
use error::{Error, Result};
use uuid::Uuid;
pub use pgp;
pub mod api;
pub mod channel;
pub mod config;
pub mod error;
pub mod graphql_model;
pub mod httpapi;
pub mod hub;
pub mod permission;
pub mod server;
pub mod websocket;
pub mod signing;
pub const MAX_NAME_SIZE: usize = 128;
pub const MAX_STATUS_SIZE: usize = 128;
pub const MAX_DESCRIPTION_SIZE: usize = 8192;
pub const MESSAGE_MAX_SIZE: usize = 8192;
pub const TANTIVY_COMMIT_THRESHOLD: u8 = 10;
pub fn is_valid_name(name: &str) -> bool {
name.as_bytes().len() <= MAX_NAME_SIZE
}
pub async fn start() -> Result {
let config = config::load_config("config.json");
if std::fs::create_dir_all("data").is_err() {
Err(Error::Other("Failed to create data directory.".to_string()))
} else {
httpapi::start(config).await
}
}
pub fn check_name_validity(name: &str) -> Result {
if is_valid_name(name) {
Ok(())
} else {
Err(Error::InvalidName)
}
}
#[macro_export]
macro_rules! check_permission {
($member:expr, $perm:expr, $hub:expr) => {
if !$member.has_permission($perm, &$hub) {
return Err(Error::MissingHubPermission($perm));
}
};
($member:expr, $channel:expr, $perm:expr, $hub:expr) => {
if !$member.has_channel_permission($channel, $perm, &$hub) {
return Err(Error::MissingChannelPermission($perm));
}
};
}
#[allow(clippy::upper_case_acronyms)]
pub type ID = Uuid;
pub fn new_id() -> ID {
uuid::Uuid::new_v4()
}