asonix
29bdf064e9
Clear profile data on suspend Clear comment body on delete Update Unfollow and Unblock operations to only delete apub IDs if present
452 lines
9.8 KiB
Rust
452 lines
9.8 KiB
Rust
use crate::store::{OwnerSource, Visibility};
|
|
use chrono::{DateTime, Utc};
|
|
use url::Url;
|
|
use uuid::Uuid;
|
|
|
|
mod apub;
|
|
mod block;
|
|
mod comment;
|
|
mod follow;
|
|
mod follow_request;
|
|
mod profile;
|
|
mod react;
|
|
mod report;
|
|
mod submission;
|
|
|
|
pub(crate) use apub::ingest;
|
|
|
|
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 }
|
|
}
|
|
}
|
|
|
|
pub struct CreateReact {
|
|
like_apub_id: Option<Url>,
|
|
submission_id: Uuid,
|
|
profile_id: Uuid,
|
|
comment_id: Option<Uuid>,
|
|
react: String,
|
|
published: DateTime<Utc>,
|
|
}
|
|
|
|
pub struct DeleteReact {
|
|
react_id: Uuid,
|
|
}
|
|
|
|
pub struct CreateComment {
|
|
note_apub_id: Option<Url>,
|
|
submission_id: Uuid,
|
|
profile_id: Uuid,
|
|
comment_id: Option<Uuid>,
|
|
body: String,
|
|
published: DateTime<Utc>,
|
|
}
|
|
|
|
impl CreateComment {
|
|
pub fn from_text(
|
|
submission_id: Uuid,
|
|
profile_id: Uuid,
|
|
comment_id: Option<Uuid>,
|
|
body: String,
|
|
) -> Self {
|
|
CreateComment {
|
|
note_apub_id: None,
|
|
submission_id,
|
|
profile_id,
|
|
comment_id,
|
|
body,
|
|
published: Utc::now(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct AnnounceComment;
|
|
|
|
pub struct UpdateComment {
|
|
update_apub_id: Option<Url>,
|
|
comment_id: Uuid,
|
|
body: Option<String>,
|
|
}
|
|
|
|
impl UpdateComment {
|
|
pub fn from_text(comment_id: Uuid, body: String) -> Self {
|
|
UpdateComment {
|
|
update_apub_id: None,
|
|
comment_id,
|
|
body: Some(body),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct DeleteComment {
|
|
comment_id: Uuid,
|
|
}
|
|
|
|
impl DeleteComment {
|
|
pub fn from_id(comment_id: Uuid) -> Self {
|
|
DeleteComment { comment_id }
|
|
}
|
|
}
|
|
|
|
pub struct CreateSubmission {
|
|
note_apub_id: Option<Url>,
|
|
profile_id: Uuid,
|
|
title: String,
|
|
description: Option<String>,
|
|
files: Vec<Uuid>,
|
|
published: Option<DateTime<Utc>>,
|
|
visibility: Visibility,
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct AnnounceSubmission;
|
|
|
|
pub struct UpdateSubmission {
|
|
submission_id: Uuid,
|
|
title: Option<String>,
|
|
description: Option<String>,
|
|
published: Option<DateTime<Utc>>,
|
|
removed_files: Option<Vec<Uuid>>,
|
|
new_files: Option<Vec<Uuid>>,
|
|
}
|
|
|
|
impl UpdateSubmission {
|
|
pub fn from_text(submission_id: Uuid, title: String, description: Option<String>) -> Self {
|
|
UpdateSubmission {
|
|
submission_id,
|
|
title: Some(title),
|
|
description,
|
|
published: None,
|
|
removed_files: None,
|
|
new_files: None,
|
|
}
|
|
}
|
|
|
|
pub fn from_new_file(submission_id: Uuid, file_id: Uuid) -> Self {
|
|
UpdateSubmission {
|
|
submission_id,
|
|
title: None,
|
|
description: None,
|
|
published: None,
|
|
removed_files: None,
|
|
new_files: Some(vec![file_id]),
|
|
}
|
|
}
|
|
|
|
pub fn from_removed_file(submission_id: Uuid, file_id: Uuid) -> Self {
|
|
UpdateSubmission {
|
|
submission_id,
|
|
title: None,
|
|
description: None,
|
|
published: None,
|
|
removed_files: Some(vec![file_id]),
|
|
new_files: None,
|
|
}
|
|
}
|
|
|
|
pub fn publish_now(submission_id: Uuid) -> Self {
|
|
UpdateSubmission {
|
|
submission_id,
|
|
title: None,
|
|
description: None,
|
|
published: Some(Utc::now()),
|
|
removed_files: None,
|
|
new_files: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct DeleteSubmission {
|
|
submission_id: Uuid,
|
|
}
|
|
|
|
impl DeleteSubmission {
|
|
pub fn from_id(submission_id: Uuid) -> Self {
|
|
DeleteSubmission { submission_id }
|
|
}
|
|
}
|
|
|
|
pub struct CreateProfileApub {
|
|
person_apub_id: Url,
|
|
public_key_id: Url,
|
|
public_key: String,
|
|
}
|
|
|
|
pub struct CreateProfile {
|
|
apub: Option<CreateProfileApub>,
|
|
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>,
|
|
}
|
|
|
|
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(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct UpdateProfile {
|
|
profile_id: Uuid,
|
|
display_name: Option<String>,
|
|
description: Option<String>,
|
|
login_required: Option<bool>,
|
|
icon: Option<Uuid>,
|
|
banner: Option<Uuid>,
|
|
public_key_id: Option<Url>,
|
|
public_key: Option<String>,
|
|
}
|
|
|
|
impl UpdateProfile {
|
|
pub fn from_text(profile_id: Uuid, display_name: String, description: String) -> Self {
|
|
UpdateProfile {
|
|
profile_id,
|
|
display_name: Some(display_name),
|
|
description: Some(description),
|
|
login_required: None,
|
|
icon: None,
|
|
banner: None,
|
|
public_key_id: None,
|
|
public_key: None,
|
|
}
|
|
}
|
|
|
|
pub fn from_icon(profile_id: Uuid, icon: Uuid) -> Self {
|
|
UpdateProfile {
|
|
profile_id,
|
|
display_name: None,
|
|
description: None,
|
|
login_required: None,
|
|
icon: Some(icon),
|
|
banner: None,
|
|
public_key_id: None,
|
|
public_key: None,
|
|
}
|
|
}
|
|
|
|
pub fn from_banner(profile_id: Uuid, banner: Uuid) -> Self {
|
|
UpdateProfile {
|
|
profile_id,
|
|
display_name: None,
|
|
description: None,
|
|
login_required: None,
|
|
icon: None,
|
|
banner: Some(banner),
|
|
public_key_id: None,
|
|
public_key: None,
|
|
}
|
|
}
|
|
|
|
pub fn from_login_required(profile_id: Uuid, login_required: bool) -> Self {
|
|
UpdateProfile {
|
|
profile_id,
|
|
display_name: None,
|
|
description: None,
|
|
login_required: Some(login_required),
|
|
icon: None,
|
|
banner: None,
|
|
public_key_id: None,
|
|
public_key: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct DeleteProfile {
|
|
profile_id: Uuid,
|
|
}
|
|
|
|
impl DeleteProfile {
|
|
pub fn from_id(profile_id: Uuid) -> Self {
|
|
DeleteProfile { profile_id }
|
|
}
|
|
}
|
|
|
|
pub struct SuspendProfile {
|
|
profile_id: Uuid,
|
|
}
|
|
|
|
impl SuspendProfile {
|
|
pub fn from_id(profile_id: Uuid) -> Self {
|
|
SuspendProfile { profile_id }
|
|
}
|
|
}
|
|
|
|
pub struct CreateFollowRequest {
|
|
follow_apub_id: Option<Url>,
|
|
followed_profile: Uuid,
|
|
followed_by_profile: Uuid,
|
|
published: DateTime<Utc>,
|
|
}
|
|
|
|
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(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct AcceptFollowRequest {
|
|
accept_apub_id: Option<Url>,
|
|
follow_request_id: Uuid,
|
|
published: DateTime<Utc>,
|
|
}
|
|
|
|
pub struct RejectFollowRequest {
|
|
follow_request_id: Uuid,
|
|
}
|
|
|
|
pub struct UndoFollowRequest {
|
|
follow_request_id: Uuid,
|
|
}
|
|
|
|
impl UndoFollowRequest {
|
|
pub fn from_id(follow_request_id: Uuid) -> Self {
|
|
UndoFollowRequest { follow_request_id }
|
|
}
|
|
}
|
|
|
|
pub struct CreateBlock {
|
|
block_apub_id: Option<Url>,
|
|
blocked_profile: Uuid,
|
|
blocked_by_profile: Uuid,
|
|
published: DateTime<Utc>,
|
|
}
|
|
|
|
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(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct DeleteBlock {
|
|
block_id: Uuid,
|
|
}
|
|
|
|
impl DeleteBlock {
|
|
pub fn from_id(block_id: Uuid) -> Self {
|
|
DeleteBlock { block_id }
|
|
}
|
|
}
|
|
|
|
pub struct UndoFollow {
|
|
follow_id: Uuid,
|
|
}
|
|
|
|
impl UndoFollow {
|
|
pub fn from_id(follow_id: Uuid) -> Self {
|
|
UndoFollow { follow_id }
|
|
}
|
|
}
|
|
|
|
pub struct UndoAcceptFollow {
|
|
follow_id: Uuid,
|
|
}
|