2021-01-17 07:27:13 +00:00
|
|
|
use crate::{
|
|
|
|
apub::Endpoints,
|
|
|
|
store::{OwnerSource, Visibility},
|
|
|
|
};
|
2021-01-04 17:34:31 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
2021-01-31 19:52:33 +00:00
|
|
|
use hyaenidae_content::bbcode;
|
2021-01-04 17:34:31 +00:00
|
|
|
use url::Url;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
mod apub;
|
|
|
|
mod block;
|
|
|
|
mod comment;
|
2021-01-16 04:25:06 +00:00
|
|
|
mod federation;
|
|
|
|
mod federation_request;
|
2021-01-04 17:34:31 +00:00
|
|
|
mod follow;
|
|
|
|
mod follow_request;
|
2021-01-16 04:25:06 +00:00
|
|
|
mod noop;
|
2021-01-04 17:34:31 +00:00
|
|
|
mod profile;
|
|
|
|
mod react;
|
2021-01-14 04:43:43 +00:00
|
|
|
mod report;
|
2021-01-16 04:25:06 +00:00
|
|
|
mod server;
|
|
|
|
mod server_block;
|
2021-01-04 17:34:31 +00:00
|
|
|
mod submission;
|
|
|
|
|
2021-01-04 17:41:34 +00:00
|
|
|
pub(crate) use apub::ingest;
|
2021-01-04 17:34:31 +00:00
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
struct CreateServerApub {
|
|
|
|
application_apub_id: Url,
|
|
|
|
public_key: String,
|
2021-01-17 07:27:13 +00:00
|
|
|
endpoints: Endpoints,
|
2021-01-16 04:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateServer {
|
|
|
|
apub: Option<CreateServerApub>,
|
|
|
|
domain: String,
|
|
|
|
title: Option<String>,
|
|
|
|
description: Option<String>,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CreateServer {
|
|
|
|
pub(crate) fn from_domain(domain: String) -> Self {
|
|
|
|
CreateServer {
|
|
|
|
apub: None,
|
|
|
|
domain,
|
|
|
|
title: None,
|
|
|
|
description: None,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-17 07:27:13 +00:00
|
|
|
struct UpdateServerApub {
|
|
|
|
public_key: String,
|
|
|
|
endpoints: Endpoints,
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
pub struct UpdateServer {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: Option<UpdateServerApub>,
|
2021-01-16 04:25:06 +00:00
|
|
|
server_id: Uuid,
|
|
|
|
title: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
title_source: Option<String>,
|
2021-01-16 04:25:06 +00:00
|
|
|
description: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: Option<String>,
|
2021-01-16 04:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateServer {
|
|
|
|
pub fn from_text(server_id: Uuid, title: Option<String>, description: Option<String>) -> Self {
|
2021-01-28 02:58:38 +00:00
|
|
|
let title_source = title.and_then(|title| {
|
|
|
|
if title.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(title.trim().to_owned())
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let description_source = description.and_then(|description| {
|
|
|
|
if description.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(description.trim().to_owned())
|
|
|
|
}
|
|
|
|
});
|
2021-01-16 04:25:06 +00:00
|
|
|
UpdateServer {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: None,
|
2021-01-16 04:25:06 +00:00
|
|
|
server_id,
|
2021-01-28 02:58:38 +00:00
|
|
|
title: title_source.clone(),
|
|
|
|
title_source,
|
2021-01-31 19:52:33 +00:00
|
|
|
description: description_source.as_deref().map(|s| bbcode(s, |v| v)),
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source,
|
2021-01-16 04:25:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DeleteServer {
|
|
|
|
server_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DeleteServer {
|
|
|
|
pub fn from_id(server_id: Uuid) -> Self {
|
|
|
|
DeleteServer { server_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 04:43:43 +00:00
|
|
|
enum Reported {
|
|
|
|
Submission(Uuid),
|
|
|
|
Comment(Uuid),
|
|
|
|
Profile(Uuid),
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Reporter {
|
|
|
|
Profile(Uuid),
|
|
|
|
Server(Uuid),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateReport {
|
|
|
|
flag_apub_id: Option<Url>,
|
|
|
|
reported_item: Reported,
|
|
|
|
reporter: Reporter,
|
|
|
|
note: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CreateReport {
|
|
|
|
pub fn from_profile(reported_profile: Uuid, reporter: Uuid, note: Option<String>) -> Self {
|
|
|
|
CreateReport {
|
|
|
|
flag_apub_id: None,
|
|
|
|
reported_item: Reported::Profile(reported_profile),
|
|
|
|
reporter: Reporter::Profile(reporter),
|
|
|
|
note,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_submission(
|
|
|
|
reported_submission: Uuid,
|
|
|
|
reporter: Uuid,
|
|
|
|
note: Option<String>,
|
|
|
|
) -> Self {
|
|
|
|
CreateReport {
|
|
|
|
flag_apub_id: None,
|
|
|
|
reported_item: Reported::Submission(reported_submission),
|
|
|
|
reporter: Reporter::Profile(reporter),
|
|
|
|
note,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_comment(reported_comment: Uuid, reporter: Uuid, note: Option<String>) -> Self {
|
|
|
|
CreateReport {
|
|
|
|
flag_apub_id: None,
|
|
|
|
reported_item: Reported::Comment(reported_comment),
|
|
|
|
reporter: Reporter::Profile(reporter),
|
|
|
|
note,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ResolveReport {
|
|
|
|
report_id: Uuid,
|
|
|
|
resolution: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ResolveReport {
|
|
|
|
pub fn from_resolution(report_id: Uuid, resolution: String) -> Self {
|
|
|
|
ResolveReport {
|
|
|
|
report_id,
|
|
|
|
resolution,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ForwardReport {
|
|
|
|
report_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ForwardReport {
|
|
|
|
pub fn from_report(report_id: Uuid) -> Self {
|
|
|
|
ForwardReport { report_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct CreateReact {
|
2021-01-05 06:09:59 +00:00
|
|
|
like_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
submission_id: Uuid,
|
|
|
|
profile_id: Uuid,
|
|
|
|
comment_id: Option<Uuid>,
|
|
|
|
react: String,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DeleteReact {
|
2021-01-05 03:13:06 +00:00
|
|
|
react_id: Uuid,
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateComment {
|
2021-01-05 06:09:59 +00:00
|
|
|
note_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
submission_id: Uuid,
|
|
|
|
profile_id: Uuid,
|
|
|
|
comment_id: Option<Uuid>,
|
|
|
|
body: String,
|
2021-01-28 02:58:38 +00:00
|
|
|
body_source: Option<String>,
|
2021-01-04 17:34:31 +00:00
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
2021-01-12 03:58:03 +00:00
|
|
|
impl CreateComment {
|
|
|
|
pub fn from_text(
|
|
|
|
submission_id: Uuid,
|
|
|
|
profile_id: Uuid,
|
|
|
|
comment_id: Option<Uuid>,
|
|
|
|
body: String,
|
|
|
|
) -> Self {
|
2021-01-28 02:58:38 +00:00
|
|
|
let body_source = body;
|
2021-01-31 19:52:33 +00:00
|
|
|
let body = bbcode(&body_source, |v| v);
|
2021-01-28 02:58:38 +00:00
|
|
|
|
2021-01-12 03:58:03 +00:00
|
|
|
CreateComment {
|
|
|
|
note_apub_id: None,
|
|
|
|
submission_id,
|
|
|
|
profile_id,
|
|
|
|
comment_id,
|
|
|
|
body,
|
2021-01-28 02:58:38 +00:00
|
|
|
body_source: Some(body_source),
|
2021-01-12 03:58:03 +00:00
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
pub struct Noop;
|
2021-01-04 17:34:31 +00:00
|
|
|
|
|
|
|
pub struct UpdateComment {
|
2021-01-05 06:09:59 +00:00
|
|
|
update_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
comment_id: Uuid,
|
|
|
|
body: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
body_source: Option<String>,
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 03:58:03 +00:00
|
|
|
impl UpdateComment {
|
|
|
|
pub fn from_text(comment_id: Uuid, body: String) -> Self {
|
2021-01-28 02:58:38 +00:00
|
|
|
let body_source = if body.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(body.trim().to_owned())
|
|
|
|
};
|
|
|
|
|
2021-01-12 03:58:03 +00:00
|
|
|
UpdateComment {
|
|
|
|
update_apub_id: None,
|
|
|
|
comment_id,
|
2021-01-31 19:52:33 +00:00
|
|
|
body: body_source.as_deref().map(|s| bbcode(s, |v| v)),
|
2021-01-28 02:58:38 +00:00
|
|
|
body_source,
|
2021-01-12 03:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct DeleteComment {
|
2021-01-16 04:25:06 +00:00
|
|
|
delete_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
comment_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-14 04:43:43 +00:00
|
|
|
impl DeleteComment {
|
|
|
|
pub fn from_id(comment_id: Uuid) -> Self {
|
2021-01-16 04:25:06 +00:00
|
|
|
DeleteComment {
|
|
|
|
delete_apub_id: None,
|
|
|
|
comment_id,
|
|
|
|
}
|
2021-01-14 04:43:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct CreateSubmission {
|
2021-01-05 06:09:59 +00:00
|
|
|
note_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
profile_id: Uuid,
|
|
|
|
title: String,
|
|
|
|
description: Option<String>,
|
|
|
|
files: Vec<Uuid>,
|
2021-01-10 01:48:04 +00:00
|
|
|
published: Option<DateTime<Utc>>,
|
2021-01-04 17:34:31 +00:00
|
|
|
visibility: Visibility,
|
2021-02-02 03:56:41 +00:00
|
|
|
local_only: bool,
|
|
|
|
logged_in_only: bool,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: bool,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Option<DateTime<Utc>>,
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-10 01:48:04 +00:00
|
|
|
impl CreateSubmission {
|
|
|
|
pub fn from_file(profile_id: Uuid, file_id: Uuid) -> Self {
|
|
|
|
CreateSubmission {
|
|
|
|
note_apub_id: None,
|
|
|
|
profile_id,
|
|
|
|
title: "".to_owned(),
|
|
|
|
description: None,
|
|
|
|
files: vec![file_id],
|
|
|
|
published: None,
|
|
|
|
visibility: Visibility::Public,
|
2021-02-02 03:56:41 +00:00
|
|
|
local_only: false,
|
|
|
|
logged_in_only: false,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: false,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct UpdateSubmission {
|
|
|
|
submission_id: Uuid,
|
|
|
|
title: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
title_source: Option<String>,
|
2021-01-04 17:34:31 +00:00
|
|
|
description: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: Option<String>,
|
2021-02-02 01:02:15 +00:00
|
|
|
visibility: Option<Visibility>,
|
2021-02-02 03:56:41 +00:00
|
|
|
local_only: Option<bool>,
|
|
|
|
logged_in_only: Option<bool>,
|
2021-01-10 01:48:04 +00:00
|
|
|
published: Option<DateTime<Utc>>,
|
2021-02-02 03:56:41 +00:00
|
|
|
updated: Option<DateTime<Utc>>,
|
2021-01-10 01:48:04 +00:00
|
|
|
removed_files: Option<Vec<Uuid>>,
|
|
|
|
new_files: Option<Vec<Uuid>>,
|
2021-01-18 17:21:41 +00:00
|
|
|
only_files: Option<Vec<Uuid>>,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: Option<bool>,
|
2021-01-10 01:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateSubmission {
|
2021-02-02 03:56:41 +00:00
|
|
|
pub fn from_text(submission_id: Uuid, title: String, description: Option<String>) -> Self {
|
2021-01-28 02:58:38 +00:00
|
|
|
let title_source = if title.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(title.trim().to_owned())
|
|
|
|
};
|
|
|
|
|
|
|
|
let description_source = description.and_then(|s| {
|
|
|
|
if s.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(s.trim().to_owned())
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-10 01:48:04 +00:00
|
|
|
UpdateSubmission {
|
|
|
|
submission_id,
|
2021-01-28 02:58:38 +00:00
|
|
|
title: title_source.clone(),
|
|
|
|
title_source,
|
2021-01-31 19:52:33 +00:00
|
|
|
description: description_source.as_deref().map(|s| bbcode(s, |v| v)),
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source,
|
2021-02-02 03:56:41 +00:00
|
|
|
visibility: None,
|
|
|
|
local_only: None,
|
|
|
|
logged_in_only: None,
|
|
|
|
published: None,
|
|
|
|
updated: Some(Utc::now()),
|
|
|
|
removed_files: None,
|
|
|
|
new_files: None,
|
|
|
|
only_files: None,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: None,
|
2021-02-02 03:56:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_visibility(
|
|
|
|
submission_id: Uuid,
|
|
|
|
visibility: Visibility,
|
|
|
|
local_only: bool,
|
|
|
|
logged_in_only: bool,
|
|
|
|
) -> Self {
|
|
|
|
UpdateSubmission {
|
|
|
|
submission_id,
|
|
|
|
title: None,
|
|
|
|
title_source: None,
|
|
|
|
description: None,
|
|
|
|
description_source: None,
|
|
|
|
visibility: Some(visibility),
|
|
|
|
local_only: Some(local_only),
|
|
|
|
logged_in_only: Some(logged_in_only),
|
2021-01-10 01:48:04 +00:00
|
|
|
published: None,
|
2021-02-02 03:56:41 +00:00
|
|
|
updated: Some(Utc::now()),
|
2021-01-10 01:48:04 +00:00
|
|
|
removed_files: None,
|
|
|
|
new_files: None,
|
2021-01-18 17:21:41 +00:00
|
|
|
only_files: None,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_new_file(submission_id: Uuid, file_id: Uuid) -> Self {
|
|
|
|
UpdateSubmission {
|
|
|
|
submission_id,
|
|
|
|
title: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
title_source: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
description: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: None,
|
2021-02-02 01:02:15 +00:00
|
|
|
visibility: None,
|
2021-02-02 03:56:41 +00:00
|
|
|
local_only: None,
|
|
|
|
logged_in_only: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
published: None,
|
2021-02-02 03:56:41 +00:00
|
|
|
updated: Some(Utc::now()),
|
2021-01-10 01:48:04 +00:00
|
|
|
removed_files: None,
|
|
|
|
new_files: Some(vec![file_id]),
|
2021-01-18 17:21:41 +00:00
|
|
|
only_files: None,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_removed_file(submission_id: Uuid, file_id: Uuid) -> Self {
|
|
|
|
UpdateSubmission {
|
|
|
|
submission_id,
|
|
|
|
title: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
title_source: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
description: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: None,
|
2021-02-02 01:02:15 +00:00
|
|
|
visibility: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
published: None,
|
2021-02-02 03:56:41 +00:00
|
|
|
updated: Some(Utc::now()),
|
|
|
|
local_only: None,
|
|
|
|
logged_in_only: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
removed_files: Some(vec![file_id]),
|
|
|
|
new_files: None,
|
2021-01-18 17:21:41 +00:00
|
|
|
only_files: None,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_sensitive(submission_id: Uuid, sensitive: bool) -> Self {
|
|
|
|
UpdateSubmission {
|
|
|
|
submission_id,
|
|
|
|
title: None,
|
|
|
|
title_source: None,
|
|
|
|
description: None,
|
|
|
|
description_source: None,
|
|
|
|
visibility: None,
|
|
|
|
local_only: None,
|
|
|
|
logged_in_only: None,
|
|
|
|
published: None,
|
|
|
|
updated: None,
|
|
|
|
removed_files: None,
|
|
|
|
new_files: None,
|
|
|
|
only_files: None,
|
|
|
|
sensitive: Some(sensitive),
|
2021-01-10 01:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn publish_now(submission_id: Uuid) -> Self {
|
|
|
|
UpdateSubmission {
|
|
|
|
submission_id,
|
|
|
|
title: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
title_source: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
description: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: None,
|
2021-02-02 01:02:15 +00:00
|
|
|
visibility: None,
|
2021-02-02 03:56:41 +00:00
|
|
|
local_only: None,
|
|
|
|
logged_in_only: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
published: Some(Utc::now()),
|
2021-02-02 03:56:41 +00:00
|
|
|
updated: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
removed_files: None,
|
|
|
|
new_files: None,
|
2021-01-18 17:21:41 +00:00
|
|
|
only_files: None,
|
2021-02-03 03:19:29 +00:00
|
|
|
sensitive: None,
|
2021-01-10 01:48:04 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DeleteSubmission {
|
|
|
|
submission_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-10 01:48:04 +00:00
|
|
|
impl DeleteSubmission {
|
|
|
|
pub fn from_id(submission_id: Uuid) -> Self {
|
|
|
|
DeleteSubmission { submission_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 08:21:17 +00:00
|
|
|
pub struct CreateProfileApub {
|
|
|
|
person_apub_id: Url,
|
|
|
|
public_key: String,
|
2021-01-17 07:27:13 +00:00
|
|
|
endpoints: Endpoints,
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct CreateProfile {
|
2021-01-06 08:21:17 +00:00
|
|
|
apub: Option<CreateProfileApub>,
|
2021-01-04 17:34:31 +00:00
|
|
|
owner_source: OwnerSource,
|
|
|
|
handle: String,
|
|
|
|
domain: String,
|
|
|
|
display_name: Option<String>,
|
|
|
|
description: Option<String>,
|
|
|
|
login_required: bool,
|
|
|
|
icon: Option<Uuid>,
|
|
|
|
banner: Option<Uuid>,
|
|
|
|
published: DateTime<Utc>,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Option<DateTime<Utc>>,
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 08:21:17 +00:00
|
|
|
impl CreateProfile {
|
|
|
|
pub fn from_local(owner_id: Uuid, handle: String, domain: String) -> Self {
|
|
|
|
CreateProfile {
|
|
|
|
apub: None,
|
|
|
|
owner_source: OwnerSource::Local(owner_id),
|
|
|
|
handle,
|
|
|
|
domain,
|
|
|
|
display_name: None,
|
|
|
|
description: None,
|
|
|
|
login_required: true,
|
|
|
|
icon: None,
|
|
|
|
banner: None,
|
|
|
|
published: Utc::now(),
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-17 07:27:13 +00:00
|
|
|
struct UpdateProfileApub {
|
|
|
|
public_key: String,
|
|
|
|
endpoints: Endpoints,
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct UpdateProfile {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: Option<UpdateProfileApub>,
|
2021-01-04 17:34:31 +00:00
|
|
|
profile_id: Uuid,
|
|
|
|
display_name: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
display_name_source: Option<String>,
|
2021-01-04 17:34:31 +00:00
|
|
|
description: Option<String>,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: Option<String>,
|
2021-01-06 08:21:17 +00:00
|
|
|
login_required: Option<bool>,
|
2021-01-04 17:34:31 +00:00
|
|
|
icon: Option<Uuid>,
|
|
|
|
banner: Option<Uuid>,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Option<DateTime<Utc>>,
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateProfile {
|
|
|
|
pub fn from_text(profile_id: Uuid, display_name: String, description: String) -> Self {
|
2021-01-28 02:58:38 +00:00
|
|
|
let display_name_source = if display_name.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(display_name.trim().to_owned())
|
|
|
|
};
|
|
|
|
|
|
|
|
let description_source = if description.trim().is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(description.trim().to_owned())
|
|
|
|
};
|
|
|
|
|
2021-01-06 08:21:17 +00:00
|
|
|
UpdateProfile {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
profile_id,
|
2021-01-28 02:58:38 +00:00
|
|
|
display_name: display_name_source.clone(),
|
|
|
|
display_name_source,
|
2021-01-31 19:52:33 +00:00
|
|
|
description: description_source.as_deref().map(|s| bbcode(s, |v| v)),
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source,
|
2021-01-06 08:21:17 +00:00
|
|
|
login_required: None,
|
|
|
|
icon: None,
|
|
|
|
banner: None,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Some(Utc::now()),
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_icon(profile_id: Uuid, icon: Uuid) -> Self {
|
|
|
|
UpdateProfile {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
profile_id,
|
|
|
|
display_name: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
display_name_source: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
description: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
login_required: None,
|
|
|
|
icon: Some(icon),
|
|
|
|
banner: None,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Some(Utc::now()),
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_banner(profile_id: Uuid, banner: Uuid) -> Self {
|
|
|
|
UpdateProfile {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
profile_id,
|
|
|
|
display_name: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
display_name_source: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
description: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
login_required: None,
|
|
|
|
icon: None,
|
|
|
|
banner: Some(banner),
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Some(Utc::now()),
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_login_required(profile_id: Uuid, login_required: bool) -> Self {
|
|
|
|
UpdateProfile {
|
2021-01-17 07:27:13 +00:00
|
|
|
apub: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
profile_id,
|
|
|
|
display_name: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
display_name_source: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
description: None,
|
2021-01-28 02:58:38 +00:00
|
|
|
description_source: None,
|
2021-01-06 08:21:17 +00:00
|
|
|
login_required: Some(login_required),
|
|
|
|
icon: None,
|
|
|
|
banner: None,
|
2021-02-09 00:23:09 +00:00
|
|
|
updated: Some(Utc::now()),
|
2021-01-06 08:21:17 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DeleteProfile {
|
|
|
|
profile_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-09 04:34:13 +00:00
|
|
|
impl DeleteProfile {
|
|
|
|
pub fn from_id(profile_id: Uuid) -> Self {
|
|
|
|
DeleteProfile { profile_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 04:43:43 +00:00
|
|
|
pub struct SuspendProfile {
|
|
|
|
profile_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SuspendProfile {
|
|
|
|
pub fn from_id(profile_id: Uuid) -> Self {
|
|
|
|
SuspendProfile { profile_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct CreateFollowRequest {
|
2021-01-05 06:09:59 +00:00
|
|
|
follow_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
followed_profile: Uuid,
|
|
|
|
followed_by_profile: Uuid,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
2021-01-15 02:41:53 +00:00
|
|
|
impl CreateFollowRequest {
|
|
|
|
pub fn from_profiles(followed_profile: Uuid, followed_by_profile: Uuid) -> Self {
|
|
|
|
CreateFollowRequest {
|
|
|
|
follow_apub_id: None,
|
|
|
|
followed_profile,
|
|
|
|
followed_by_profile,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct AcceptFollowRequest {
|
2021-01-05 06:09:59 +00:00
|
|
|
accept_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
follow_request_id: Uuid,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
2021-01-15 05:50:26 +00:00
|
|
|
impl AcceptFollowRequest {
|
|
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
|
|
AcceptFollowRequest {
|
|
|
|
accept_apub_id: None,
|
|
|
|
follow_request_id,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct RejectFollowRequest {
|
|
|
|
follow_request_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-15 05:50:26 +00:00
|
|
|
impl RejectFollowRequest {
|
|
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
|
|
RejectFollowRequest { follow_request_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 06:09:59 +00:00
|
|
|
pub struct UndoFollowRequest {
|
2021-01-04 17:34:31 +00:00
|
|
|
follow_request_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-15 02:41:53 +00:00
|
|
|
impl UndoFollowRequest {
|
|
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
|
|
UndoFollowRequest { follow_request_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
pub struct UndoFollow {
|
|
|
|
follow_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UndoAcceptFollow {
|
|
|
|
follow_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UndoFollow {
|
|
|
|
pub fn from_id(follow_id: Uuid) -> Self {
|
|
|
|
UndoFollow { follow_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateFederationRequest {
|
|
|
|
follow_apub_id: Option<Url>,
|
|
|
|
followed_server: Uuid,
|
|
|
|
followed_by_server: Uuid,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CreateFederationRequest {
|
|
|
|
pub fn from_servers(followed_server: Uuid, followed_by_server: Uuid) -> Self {
|
|
|
|
CreateFederationRequest {
|
|
|
|
follow_apub_id: None,
|
|
|
|
followed_server,
|
|
|
|
followed_by_server,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct AcceptFederationRequest {
|
|
|
|
accept_apub_id: Option<Url>,
|
|
|
|
follow_request_id: Uuid,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AcceptFederationRequest {
|
|
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
|
|
AcceptFederationRequest {
|
|
|
|
accept_apub_id: None,
|
|
|
|
follow_request_id,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct RejectFederationRequest {
|
|
|
|
follow_request_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RejectFederationRequest {
|
|
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
|
|
RejectFederationRequest { follow_request_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UndoFederationRequest {
|
|
|
|
follow_request_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UndoFederationRequest {
|
|
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
|
|
UndoFederationRequest { follow_request_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UndoFederation {
|
|
|
|
follow_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UndoFederation {
|
|
|
|
pub fn from_id(follow_id: Uuid) -> Self {
|
|
|
|
UndoFederation { follow_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UndoAcceptFederation {
|
|
|
|
follow_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-17 07:27:13 +00:00
|
|
|
impl UndoAcceptFederation {
|
|
|
|
pub fn from_id(follow_id: Uuid) -> Self {
|
|
|
|
UndoAcceptFederation { follow_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct CreateBlock {
|
2021-01-05 06:09:59 +00:00
|
|
|
block_apub_id: Option<Url>,
|
2021-01-04 17:34:31 +00:00
|
|
|
blocked_profile: Uuid,
|
|
|
|
blocked_by_profile: Uuid,
|
|
|
|
published: DateTime<Utc>,
|
|
|
|
}
|
|
|
|
|
2021-01-15 02:41:53 +00:00
|
|
|
impl CreateBlock {
|
|
|
|
pub fn from_profiles(blocked_profile: Uuid, blocked_by_profile: Uuid) -> Self {
|
|
|
|
CreateBlock {
|
|
|
|
block_apub_id: None,
|
|
|
|
blocked_profile,
|
|
|
|
blocked_by_profile,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:34:31 +00:00
|
|
|
pub struct DeleteBlock {
|
|
|
|
block_id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-01-15 02:41:53 +00:00
|
|
|
impl DeleteBlock {
|
|
|
|
pub fn from_id(block_id: Uuid) -> Self {
|
|
|
|
DeleteBlock { block_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
pub struct CreateServerBlock {
|
|
|
|
blocked_server: Uuid,
|
|
|
|
blocked_by_server: Uuid,
|
|
|
|
published: DateTime<Utc>,
|
2021-01-05 06:09:59 +00:00
|
|
|
}
|
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
impl CreateServerBlock {
|
|
|
|
pub fn from_servers(blocked_server: Uuid, blocked_by_server: Uuid) -> Self {
|
|
|
|
CreateServerBlock {
|
|
|
|
blocked_server,
|
|
|
|
blocked_by_server,
|
|
|
|
published: Utc::now(),
|
|
|
|
}
|
2021-01-15 02:41:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:25:06 +00:00
|
|
|
pub struct DeleteServerBlock {
|
|
|
|
block_id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DeleteServerBlock {
|
|
|
|
pub fn from_id(block_id: Uuid) -> Self {
|
|
|
|
DeleteServerBlock { block_id }
|
|
|
|
}
|
2021-01-04 17:34:31 +00:00
|
|
|
}
|