tangled
alpha
login
or
join now
zzstoatzz.io
/
status
0
fork
atom
slack status without the slack
status.zzstoatzz.io/
quickslice
0
fork
atom
overview
issues
pulls
pipelines
fix(clippy): remove unused import after extraction
zzstoatzz.io
6 months ago
a6290d15
24e08bf7
+45
-51
3 changed files
expand all
collapse all
unified
split
src
api
mod.rs
status.rs
status_util.rs
+1
src/api/mod.rs
···
1
pub mod auth;
2
pub mod preferences;
3
pub mod status;
0
4
pub mod webhooks;
5
6
pub use auth::OAuthClientType;
···
1
pub mod auth;
2
pub mod preferences;
3
pub mod status;
4
+
pub mod status_util;
5
pub mod webhooks;
6
7
pub use auth::OAuthClientType;
+4
-51
src/api/status.rs
···
10
lexicons::record::KnownRecord,
11
rate_limiter::RateLimiter,
12
templates::{ErrorTemplate, FeedTemplate, Profile, StatusTemplate},
13
-
webhooks::{StatusEvent, send_status_event},
14
};
15
use actix_multipart::Multipart;
16
use actix_session::Session;
···
31
};
32
use atrium_oauth::DefaultHttpClient;
33
use futures_util::TryStreamExt as _;
34
-
use serde::{Deserialize, Serialize};
35
use std::{collections::HashMap, sync::Arc};
36
37
/// HandleResolver to make it easier to access the OAuthClient in web requests
···
45
did == ADMIN_DID
46
}
47
48
-
/// The post body for changing your status
49
-
#[derive(Serialize, Deserialize, Clone)]
50
-
pub struct StatusForm {
51
-
pub status: String,
52
-
pub text: Option<String>,
53
-
pub expires_in: Option<String>, // e.g., "1h", "30m", "1d", etc.
54
-
}
55
-
56
-
/// The post body for deleting a specific status
57
-
#[derive(Serialize, Deserialize)]
58
-
pub struct DeleteRequest {
59
-
pub uri: String,
60
-
}
61
-
62
-
/// Hide/unhide a status (admin only)
63
-
#[derive(Deserialize)]
64
-
pub struct HideStatusRequest {
65
-
pub uri: String,
66
-
pub hidden: bool,
67
-
}
68
-
69
-
/// Parse duration string like "1h", "30m", "1d" into chrono::Duration
70
-
fn parse_duration(duration_str: &str) -> Option<chrono::Duration> {
71
-
if duration_str.is_empty() {
72
-
return None;
73
-
}
74
-
75
-
let (num_str, unit) = duration_str.split_at(duration_str.len() - 1);
76
-
let num: i64 = num_str.parse().ok()?;
77
-
78
-
match unit {
79
-
"m" => Some(chrono::Duration::minutes(num)),
80
-
"h" => Some(chrono::Duration::hours(num)),
81
-
"d" => Some(chrono::Duration::days(num)),
82
-
"w" => Some(chrono::Duration::weeks(num)),
83
-
_ => None,
84
-
}
85
-
}
86
87
/// Homepage - shows logged-in user's status, or owner's status if not logged in
88
#[get("/")]
···
1252
let did_for_event = did_string.clone();
1253
let uri = req.uri.clone();
1254
tokio::spawn(async move {
1255
-
let event = StatusEvent {
1256
-
event: "status.deleted",
1257
-
did: &did_for_event,
1258
-
handle: None,
1259
-
status: None,
1260
-
text: None,
1261
-
uri: Some(&uri),
1262
-
since: None,
1263
-
expires: None,
1264
-
};
1265
-
send_status_event(pool, &did_for_event, event).await;
1266
});
1267
}
1268
···
10
lexicons::record::KnownRecord,
11
rate_limiter::RateLimiter,
12
templates::{ErrorTemplate, FeedTemplate, Profile, StatusTemplate},
0
13
};
14
use actix_multipart::Multipart;
15
use actix_session::Session;
···
30
};
31
use atrium_oauth::DefaultHttpClient;
32
use futures_util::TryStreamExt as _;
33
+
use serde::Serialize;
34
use std::{collections::HashMap, sync::Arc};
35
36
/// HandleResolver to make it easier to access the OAuthClient in web requests
···
44
did == ADMIN_DID
45
}
46
47
+
use crate::api::status_util::{DeleteRequest, HideStatusRequest, StatusForm, parse_duration};
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
48
49
/// Homepage - shows logged-in user's status, or owner's status if not logged in
50
#[get("/")]
···
1214
let did_for_event = did_string.clone();
1215
let uri = req.uri.clone();
1216
tokio::spawn(async move {
1217
+
crate::webhooks::emit_deleted(pool, &did_for_event, &uri)
1218
+
.await;
0
0
0
0
0
0
0
0
0
1219
});
1220
}
1221
+40
src/api/status_util.rs
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
1
+
use serde::{Deserialize, Serialize};
2
+
3
+
/// The post body for changing your status
4
+
#[derive(Serialize, Deserialize, Clone)]
5
+
pub struct StatusForm {
6
+
pub status: String,
7
+
pub text: Option<String>,
8
+
pub expires_in: Option<String>, // e.g., "1h", "30m", "1d", etc.
9
+
}
10
+
11
+
/// The post body for deleting a specific status
12
+
#[derive(Serialize, Deserialize)]
13
+
pub struct DeleteRequest {
14
+
pub uri: String,
15
+
}
16
+
17
+
/// Hide/unhide a status (admin only)
18
+
#[derive(Deserialize)]
19
+
pub struct HideStatusRequest {
20
+
pub uri: String,
21
+
pub hidden: bool,
22
+
}
23
+
24
+
/// Parse duration string like "1h", "30m", "1d" into chrono::Duration
25
+
pub fn parse_duration(duration_str: &str) -> Option<chrono::Duration> {
26
+
if duration_str.is_empty() {
27
+
return None;
28
+
}
29
+
30
+
let (num_str, unit) = duration_str.split_at(duration_str.len() - 1);
31
+
let num: i64 = num_str.parse().ok()?;
32
+
33
+
match unit {
34
+
"m" => Some(chrono::Duration::minutes(num)),
35
+
"h" => Some(chrono::Duration::hours(num)),
36
+
"d" => Some(chrono::Duration::days(num)),
37
+
"w" => Some(chrono::Duration::weeks(num)),
38
+
_ => None,
39
+
}
40
+
}