mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 15:34:00 +00:00
Add docs for MediaType, PublicUrl values
This commit is contained in:
parent
57b6ecaf40
commit
433ab1e78b
26 changed files with 130 additions and 53 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1760,6 +1760,7 @@ dependencies = [
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
"lemmy_websocket",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,12 @@ use lemmy_api_common::{
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
post::*,
|
post::*,
|
||||||
};
|
};
|
||||||
use lemmy_apub::{generate_apub_endpoint, ApubLikeableType, EndpointType};
|
use lemmy_apub::{
|
||||||
|
activities::post::create::CreatePost as CreateApubPost,
|
||||||
|
generate_apub_endpoint,
|
||||||
|
ApubLikeableType,
|
||||||
|
EndpointType,
|
||||||
|
};
|
||||||
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
|
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
|
||||||
use lemmy_db_schema::source::post::*;
|
use lemmy_db_schema::source::post::*;
|
||||||
use lemmy_db_views::post_view::PostView;
|
use lemmy_db_views::post_view::PostView;
|
||||||
|
@ -82,12 +87,7 @@ impl PerformCrud for CreatePost {
|
||||||
.await?
|
.await?
|
||||||
.map_err(|_| ApiError::err("couldnt_create_post"))?;
|
.map_err(|_| ApiError::err("couldnt_create_post"))?;
|
||||||
|
|
||||||
lemmy_apub::activities::post::create::CreatePost::send(
|
CreateApubPost::send(&updated_post, &local_user_view.person, context).await?;
|
||||||
&updated_post,
|
|
||||||
&local_user_view.person,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// They like their own post by default
|
// They like their own post by default
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -10,7 +10,12 @@ use crate::{
|
||||||
NoteExt,
|
NoteExt,
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::kind::CreateType, base::BaseExt};
|
use activitystreams::{activity::kind::CreateType, base::BaseExt};
|
||||||
use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{
|
||||||
|
values::PublicUrl,
|
||||||
|
verify_domains_match_opt,
|
||||||
|
ActivityCommonFields,
|
||||||
|
ActivityHandler,
|
||||||
|
};
|
||||||
use lemmy_db_schema::source::comment::Comment;
|
use lemmy_db_schema::source::comment::Comment;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
use crate::activities::{comment::send_websocket_message, verify_mod_action};
|
use crate::{
|
||||||
|
activities::{comment::send_websocket_message, verify_mod_action},
|
||||||
|
check_is_apub_id_valid,
|
||||||
|
fetcher::objects::get_or_fetch_and_insert_comment,
|
||||||
|
};
|
||||||
use activitystreams::activity::kind::RemoveType;
|
use activitystreams::activity::kind::RemoveType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use crate::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
|
use lemmy_apub_lib::{
|
||||||
use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl};
|
values::PublicUrl,
|
||||||
|
verify_domains_match,
|
||||||
|
ActivityCommonFields,
|
||||||
|
ActivityHandlerNew,
|
||||||
|
};
|
||||||
use lemmy_db_queries::source::comment::Comment_;
|
use lemmy_db_queries::source::comment::Comment_;
|
||||||
use lemmy_db_schema::source::comment::Comment;
|
use lemmy_db_schema::source::comment::Comment;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
use crate::activities::{
|
use crate::{
|
||||||
comment::{remove::RemoveComment, send_websocket_message},
|
activities::{
|
||||||
verify_mod_action,
|
comment::{remove::RemoveComment, send_websocket_message},
|
||||||
|
verify_mod_action,
|
||||||
|
},
|
||||||
|
check_is_apub_id_valid,
|
||||||
|
fetcher::objects::get_or_fetch_and_insert_comment,
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UndoType;
|
use activitystreams::activity::kind::UndoType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use crate::{check_is_apub_id_valid, fetcher::objects::get_or_fetch_and_insert_comment};
|
use lemmy_apub_lib::{
|
||||||
use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandlerNew, PublicUrl};
|
values::PublicUrl,
|
||||||
|
verify_domains_match,
|
||||||
|
ActivityCommonFields,
|
||||||
|
ActivityHandlerNew,
|
||||||
|
};
|
||||||
use lemmy_db_queries::source::comment::Comment_;
|
use lemmy_db_queries::source::comment::Comment_;
|
||||||
use lemmy_db_schema::source::comment::Comment;
|
use lemmy_db_schema::source::comment::Comment;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -10,7 +10,12 @@ use crate::{
|
||||||
NoteExt,
|
NoteExt,
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::kind::UpdateType, base::BaseExt};
|
use activitystreams::{activity::kind::UpdateType, base::BaseExt};
|
||||||
use lemmy_apub_lib::{verify_domains_match_opt, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{
|
||||||
|
values::PublicUrl,
|
||||||
|
verify_domains_match_opt,
|
||||||
|
ActivityCommonFields,
|
||||||
|
ActivityHandler,
|
||||||
|
};
|
||||||
use lemmy_db_schema::source::comment::Comment;
|
use lemmy_db_schema::source::comment::Comment;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::{activity::kind::AddType, base::AnyBase};
|
use activitystreams::{activity::kind::AddType, base::AnyBase};
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::{source::community::CommunityModerator_, Joinable};
|
use lemmy_db_queries::{source::community::CommunityModerator_, Joinable};
|
||||||
use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm};
|
use lemmy_db_schema::source::community::{CommunityModerator, CommunityModeratorForm};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -34,7 +34,7 @@ use crate::{
|
||||||
CommunityType,
|
CommunityType,
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::AnnounceType;
|
use activitystreams::activity::kind::AnnounceType;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_schema::source::community::Community;
|
use lemmy_db_schema::source::community::Community;
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::BlockType;
|
use activitystreams::activity::kind::BlockType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::{Bannable, Followable};
|
use lemmy_db_queries::{Bannable, Followable};
|
||||||
use lemmy_db_schema::source::community::{
|
use lemmy_db_schema::source::community::{
|
||||||
CommunityFollower,
|
CommunityFollower,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UndoType;
|
use activitystreams::activity::kind::UndoType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::Bannable;
|
use lemmy_db_queries::Bannable;
|
||||||
use lemmy_db_schema::source::community::{CommunityPersonBan, CommunityPersonBanForm};
|
use lemmy_db_schema::source::community::{CommunityPersonBan, CommunityPersonBanForm};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UpdateType;
|
use activitystreams::activity::kind::UpdateType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::{ApubObject, Crud};
|
use lemmy_db_queries::{ApubObject, Crud};
|
||||||
use lemmy_db_schema::source::community::{Community, CommunityForm};
|
use lemmy_db_schema::source::community::{Community, CommunityForm};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::DeleteType;
|
use activitystreams::activity::kind::DeleteType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::{
|
use lemmy_db_queries::{
|
||||||
source::{comment::Comment_, community::Community_, post::Post_},
|
source::{comment::Comment_, community::Community_, post::Post_},
|
||||||
Crud,
|
Crud,
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UndoType;
|
use activitystreams::activity::kind::UndoType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
|
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
|
||||||
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
|
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -17,11 +17,11 @@ use activitystreams::activity::kind::CreateType;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
|
values::PublicUrl,
|
||||||
verify_domains_match,
|
verify_domains_match,
|
||||||
verify_urls_match,
|
verify_urls_match,
|
||||||
ActivityCommonFields,
|
ActivityCommonFields,
|
||||||
ActivityHandler,
|
ActivityHandler,
|
||||||
PublicUrl,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_queries::Crud;
|
use lemmy_db_queries::Crud;
|
||||||
use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
|
use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UpdateType;
|
use activitystreams::activity::kind::UpdateType;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::Crud;
|
use lemmy_db_queries::Crud;
|
||||||
use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
|
use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
use activitystreams::{activity::kind::RemoveType, base::AnyBase};
|
use activitystreams::{activity::kind::RemoveType, base::AnyBase};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::{
|
use lemmy_db_queries::{
|
||||||
source::{comment::Comment_, community::Community_, post::Post_},
|
source::{comment::Comment_, community::Community_, post::Post_},
|
||||||
Joinable,
|
Joinable,
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
use activitystreams::activity::kind::UndoType;
|
use activitystreams::activity::kind::UndoType;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
|
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
|
||||||
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
|
use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::activities::{
|
||||||
voting::receive_like_or_dislike,
|
voting::receive_like_or_dislike,
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::DislikeType;
|
use activitystreams::activity::kind::DislikeType;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::activities::{
|
||||||
voting::receive_like_or_dislike,
|
voting::receive_like_or_dislike,
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::LikeType;
|
use activitystreams::activity::kind::LikeType;
|
||||||
use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::activities::{
|
||||||
voting::{dislike::DislikePostOrComment, receive_undo_like_or_dislike},
|
voting::{dislike::DislikePostOrComment, receive_undo_like_or_dislike},
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UndoType;
|
use activitystreams::activity::kind::UndoType;
|
||||||
use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::activities::{
|
||||||
voting::{like::LikePostOrComment, receive_undo_like_or_dislike},
|
voting::{like::LikePostOrComment, receive_undo_like_or_dislike},
|
||||||
};
|
};
|
||||||
use activitystreams::activity::kind::UndoType;
|
use activitystreams::activity::kind::UndoType;
|
||||||
use lemmy_apub_lib::{verify_urls_match, ActivityCommonFields, ActivityHandler, PublicUrl};
|
use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
|
||||||
use lemmy_utils::LemmyError;
|
use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
|
@ -12,6 +12,7 @@ use activitystreams::{
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
|
use lemmy_apub_lib::values::MediaTypeMarkdown;
|
||||||
use lemmy_db_queries::{ApubObject, Crud, DbPool};
|
use lemmy_db_queries::{ApubObject, Crud, DbPool};
|
||||||
use lemmy_db_schema::{CommunityId, DbUrl};
|
use lemmy_db_schema::{CommunityId, DbUrl};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
|
@ -70,18 +71,6 @@ pub trait FromApubToForm<ApubType> {
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
||||||
pub enum MediaTypeMarkdown {
|
|
||||||
#[serde(rename = "text/markdown")]
|
|
||||||
Markdown,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
|
||||||
pub enum MediaTypeHtml {
|
|
||||||
#[serde(rename = "text/html")]
|
|
||||||
Markdown,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Source {
|
pub struct Source {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
activities::extract_community,
|
activities::extract_community,
|
||||||
extensions::context::lemmy_context,
|
extensions::context::lemmy_context,
|
||||||
fetcher::person::get_or_fetch_and_upsert_person,
|
fetcher::person::get_or_fetch_and_upsert_person,
|
||||||
objects::{create_tombstone, FromApub, MediaTypeHtml, MediaTypeMarkdown, Source, ToApub},
|
objects::{create_tombstone, FromApub, Source, ToApub},
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
|
@ -16,7 +16,10 @@ use activitystreams::{
|
||||||
};
|
};
|
||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::verify_domains_match;
|
use lemmy_apub_lib::{
|
||||||
|
values::{MediaTypeHtml, MediaTypeMarkdown},
|
||||||
|
verify_domains_match,
|
||||||
|
};
|
||||||
use lemmy_db_queries::{ApubObject, Crud, DbPool};
|
use lemmy_db_queries::{ApubObject, Crud, DbPool};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
self,
|
self,
|
||||||
|
@ -126,7 +129,7 @@ impl ToApub for Post {
|
||||||
to: [community.actor_id.into(), public()],
|
to: [community.actor_id.into(), public()],
|
||||||
name: self.name.clone(),
|
name: self.name.clone(),
|
||||||
content: self.body.as_ref().map(|b| markdown_to_html(b)),
|
content: self.body.as_ref().map(|b| markdown_to_html(b)),
|
||||||
media_type: MediaTypeHtml::Markdown,
|
media_type: MediaTypeHtml::Html,
|
||||||
source,
|
source,
|
||||||
url: self.url.clone().map(|u| u.into()),
|
url: self.url.clone().map(|u| u.into()),
|
||||||
image,
|
image,
|
||||||
|
|
|
@ -12,3 +12,4 @@ activitystreams-ext = "0.1.0-alpha.2"
|
||||||
serde = { version = "1.0.123", features = ["derive"] }
|
serde = { version = "1.0.123", features = ["derive"] }
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
url = { version = "2.2.1", features = ["serde"] }
|
url = { version = "2.2.1", features = ["serde"] }
|
||||||
|
serde_json = { version = "1.0.64", features = ["preserve_order"] }
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
pub mod values;
|
||||||
|
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::AnyBase,
|
base::AnyBase,
|
||||||
error::DomainError,
|
error::DomainError,
|
||||||
|
@ -9,12 +11,6 @@ use lemmy_utils::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
|
||||||
pub enum PublicUrl {
|
|
||||||
#[serde(rename = "https://www.w3.org/ns/activitystreams#Public")]
|
|
||||||
Public,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ActivityCommonFields {
|
pub struct ActivityCommonFields {
|
||||||
|
|
61
crates/apub_lib/src/values/mod.rs
Normal file
61
crates/apub_lib/src/values/mod.rs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
//! The enums here serve to limit a json string value to a single, hardcoded value which can be
|
||||||
|
//! verified at compilation time. When using it as the type of a struct field, the struct can only
|
||||||
|
//! be constructed or deserialized if the field has the exact same value.
|
||||||
|
//!
|
||||||
|
//! If we used String as the field type, any value would be accepted, and we would have to check
|
||||||
|
//! manually at runtime that it contains the expected value.
|
||||||
|
//!
|
||||||
|
//! The enums in [`activitystreams::activity::kind`] work in the same way, and can be used to
|
||||||
|
//! distinguish different activity types.
|
||||||
|
//!
|
||||||
|
//! In the example below, `MyObject` can only be constructed or
|
||||||
|
//! deserialized if `media_type` is `text/markdown`, but not if it is `text/html`.
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! use lemmy_apub_lib::values::MediaTypeMarkdown;
|
||||||
|
//! use serde_json::from_str;
|
||||||
|
//! use serde::{Deserialize, Serialize};
|
||||||
|
//!
|
||||||
|
//! #[derive(Deserialize, Serialize)]
|
||||||
|
//! struct MyObject {
|
||||||
|
//! content: String,
|
||||||
|
//! media_type: MediaTypeMarkdown,
|
||||||
|
//! }
|
||||||
|
//!
|
||||||
|
//! let markdown_json = r#"{"content": "**test**", "media_type": "text/markdown"}"#;
|
||||||
|
//! let from_markdown = from_str::<MyObject>(markdown_json);
|
||||||
|
//! assert!(from_markdown.is_ok());
|
||||||
|
//!
|
||||||
|
//! let markdown_html = r#"{"content": "<b>test</b>", "media_type": "text/html"}"#;
|
||||||
|
//! let from_html = from_str::<MyObject>(markdown_html);
|
||||||
|
//! assert!(from_html.is_err());
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// The identifier used to address activities to the public.
|
||||||
|
///
|
||||||
|
/// <https://www.w3.org/TR/activitypub/#public-addressing>
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub enum PublicUrl {
|
||||||
|
#[serde(rename = "https://www.w3.org/ns/activitystreams#Public")]
|
||||||
|
Public,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Media type for markdown text.
|
||||||
|
///
|
||||||
|
/// <https://www.iana.org/assignments/media-types/media-types.xhtml>
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub enum MediaTypeMarkdown {
|
||||||
|
#[serde(rename = "text/markdown")]
|
||||||
|
Markdown,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Media type for HTML text/
|
||||||
|
///
|
||||||
|
/// <https://www.iana.org/assignments/media-types/media-types.xhtml>
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
pub enum MediaTypeHtml {
|
||||||
|
#[serde(rename = "text/html")]
|
||||||
|
Html,
|
||||||
|
}
|
Loading…
Reference in a new issue