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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
use axum::extract::FromRef;
use sqlx::sqlite::SqlitePool;
#[cfg(test)]
use crate::user::app::Users;
use crate::{
boot::app::Boot,
conversation::app::Conversations,
event::{self, app::Events},
invite::app::Invites,
login::app::Logins,
message::app::Messages,
push::app::Push,
setup::app::Setup,
token::{self, app::Tokens},
vapid::app::Vapid,
};
#[derive(Clone)]
pub struct App {
db: SqlitePool,
events: event::Broadcaster,
token_events: token::Broadcaster,
}
impl App {
pub fn from(db: SqlitePool) -> Self {
let events = event::Broadcaster::default();
let token_events = token::Broadcaster::default();
Self {
db,
events,
token_events,
}
}
}
impl App {
pub fn boot(&self) -> Boot {
Boot::new(self.db.clone())
}
pub fn conversations(&self) -> Conversations {
Conversations::new(self.db.clone(), self.events.clone())
}
pub fn events(&self) -> Events {
Events::new(self.db.clone(), self.events.clone())
}
pub fn invites(&self) -> Invites {
Invites::new(self.db.clone(), self.events.clone())
}
pub fn logins(&self) -> Logins {
Logins::new(self.db.clone(), self.token_events.clone())
}
pub fn messages(&self) -> Messages {
Messages::new(self.db.clone(), self.events.clone())
}
pub fn push(&self) -> Push {
Push::new(self.db.clone())
}
pub fn setup(&self) -> Setup {
Setup::new(self.db.clone(), self.events.clone())
}
pub fn tokens(&self) -> Tokens {
Tokens::new(self.db.clone(), self.token_events.clone())
}
#[cfg(test)]
pub fn users(&self) -> Users {
Users::new(self.db.clone(), self.events.clone())
}
pub fn vapid(&self) -> Vapid {
Vapid::new(self.db.clone(), self.events.clone())
}
}
impl FromRef<App> for Boot {
fn from_ref(app: &App) -> Self {
app.boot()
}
}
impl FromRef<App> for Conversations {
fn from_ref(app: &App) -> Self {
app.conversations()
}
}
impl FromRef<App> for Invites {
fn from_ref(app: &App) -> Self {
app.invites()
}
}
impl FromRef<App> for Logins {
fn from_ref(app: &App) -> Self {
app.logins()
}
}
impl FromRef<App> for Messages {
fn from_ref(app: &App) -> Self {
app.messages()
}
}
impl FromRef<App> for Push {
fn from_ref(app: &App) -> Self {
app.push()
}
}
impl FromRef<App> for Setup {
fn from_ref(app: &App) -> Self {
app.setup()
}
}
impl FromRef<App> for Tokens {
fn from_ref(app: &App) -> Self {
app.tokens()
}
}
impl FromRef<App> for Vapid {
fn from_ref(app: &App) -> Self {
app.vapid()
}
}
|