From d26a7ad337a640fdfd631938c017023a3587f10c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 23 Nov 2020 10:59:06 -0500 Subject: [PATCH 1/3] Trying out cargo chef and a travis docker image cache. (#1238) * Trying out cargo chef and a travis docker image cache. * trying to change internal target. * Use latest cargo-chef with --target * Remove caching for now. * Adding back in chowns * Adding back in cache. * Remove travis caching. * Switching dev dockerfile to match prod, using cargo-chef and alpine. * Make travis happy * Trying a chown rust. * Caching cargo-chef first. * Moving the chowns * Removing many copy commands. * Go back to rust 1.47.0 due to config-rs breaking. * Adding the old volume mount version. * Adding some script comments. Co-authored-by: Luca Palmieri --- .dockerignore | 10 +-- docker/dev/Dockerfile | 77 ++++++++++++++++++------ docker/dev/docker_update.sh | 4 ++ docker/dev/docker_update_volume_mount.sh | 11 ++++ docker/dev/volume_mount.dockerfile | 35 +++++++++++ docker/prod/Dockerfile | 42 +++++++++++-- 6 files changed, 148 insertions(+), 31 deletions(-) create mode 100755 docker/dev/docker_update_volume_mount.sh create mode 100644 docker/dev/volume_mount.dockerfile diff --git a/.dockerignore b/.dockerignore index b336eeeb1..3a0f82b48 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,8 +1,8 @@ # build folders and similar which are not needed for the docker build target -docker/dev/volumes -docker/prod/volumes -docker/federation/volumes -docker/travis/volumes -.git +docker +api_tests ansible +tests +.git +*.sh diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index d10e72635..eba8e1ea8 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -1,35 +1,72 @@ -# syntax=docker/dockerfile:experimental -FROM rust:1.47-buster as rust +ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0 -ENV HOME=/home/root +# Cargo chef plan +FROM $RUST_BUILDER_IMAGE as planner +WORKDIR /app +RUN cargo install cargo-chef --version 0.1.6 + +# Copy dirs +COPY ./ ./ + +RUN sudo chown -R rust:rust . +RUN cargo chef prepare --recipe-path recipe.json + +# Cargo chef cache dependencies +FROM $RUST_BUILDER_IMAGE as cacher +ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl +WORKDIR /app +RUN cargo install cargo-chef --version 0.1.6 +COPY --from=planner /app/recipe.json ./recipe.json +RUN sudo chown -R rust:rust . +RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json + +# Build the project +FROM $RUST_BUILDER_IMAGE as builder + +ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl +ARG RUSTRELEASEDIR="debug" WORKDIR /app -# Copy the source folders -COPY . ./ +# Copy over the cached dependencies +COPY --from=cacher /app/target target +COPY --from=cacher /home/rust/.cargo /home/rust/.cargo -# Build for debug -RUN --mount=type=cache,target=/usr/local/cargo/registry \ - --mount=type=cache,target=/app/target \ - cargo build -RUN --mount=type=cache,target=/app/target \ - cp target/debug/lemmy_server lemmy_server +# Copy the rest of the dirs +COPY ./ ./ -FROM peaceiris/mdbook:v0.3.7 as docs +RUN sudo chown -R rust:rust . +RUN cargo build + +# reduce binary size +RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server + +RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server + +# Build the docs +FROM $RUST_BUILDER_IMAGE as docs WORKDIR /app -COPY docs ./docs +COPY --chown=rust:rust docs ./docs RUN mdbook build docs/ -FROM ubuntu:20.10 +# The alpine runner +FROM alpine:3.12 as lemmy -# Install libpq for postgres and espeak -RUN apt-get update -y -RUN apt-get install -y libpq-dev espeak +# Install libpq for postgres +RUN apk add libpq + +# Install Espeak for captchas +RUN apk add espeak + +RUN addgroup -g 1000 lemmy +RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy # Copy resources -COPY config/defaults.hjson /config/defaults.hjson -COPY --from=rust /app/lemmy_server /app/lemmy -COPY --from=docs /app/docs/book/ /app/documentation/ +COPY --chown=lemmy:lemmy config/defaults.hjson /config/defaults.hjson +COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy +COPY --chown=lemmy:lemmy --from=docs /app/docs/book/ /app/documentation/ +RUN chown lemmy:lemmy /app/lemmy +USER lemmy EXPOSE 8536 CMD ["/app/lemmy"] diff --git a/docker/dev/docker_update.sh b/docker/dev/docker_update.sh index d99f4ddf6..4531a1bdd 100755 --- a/docker/dev/docker_update.sh +++ b/docker/dev/docker_update.sh @@ -1,4 +1,8 @@ #!/bin/sh + +# This script uses a docker file that builds with musl, and runs on linux alpine +# Its a bit slower for development than the volume mount. + set -e mkdir -p volumes/pictrs diff --git a/docker/dev/docker_update_volume_mount.sh b/docker/dev/docker_update_volume_mount.sh new file mode 100755 index 000000000..ef68f1fd4 --- /dev/null +++ b/docker/dev/docker_update_volume_mount.sh @@ -0,0 +1,11 @@ +#!/bin/sh +set -e + +# This script uses a Dockerfile that takes advantage of docker volume mounts, +# And runs on an ubuntu image. A little faster for development than the other +# script + +mkdir -p volumes/pictrs +sudo chown -R 991:991 volumes/pictrs +sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-dev:latest +sudo docker-compose up -d diff --git a/docker/dev/volume_mount.dockerfile b/docker/dev/volume_mount.dockerfile new file mode 100644 index 000000000..d10e72635 --- /dev/null +++ b/docker/dev/volume_mount.dockerfile @@ -0,0 +1,35 @@ +# syntax=docker/dockerfile:experimental +FROM rust:1.47-buster as rust + +ENV HOME=/home/root + +WORKDIR /app + +# Copy the source folders +COPY . ./ + +# Build for debug +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/app/target \ + cargo build +RUN --mount=type=cache,target=/app/target \ + cp target/debug/lemmy_server lemmy_server + +FROM peaceiris/mdbook:v0.3.7 as docs +WORKDIR /app +COPY docs ./docs +RUN mdbook build docs/ + +FROM ubuntu:20.10 + +# Install libpq for postgres and espeak +RUN apt-get update -y +RUN apt-get install -y libpq-dev espeak + +# Copy resources +COPY config/defaults.hjson /config/defaults.hjson +COPY --from=rust /app/lemmy_server /app/lemmy +COPY --from=docs /app/docs/book/ /app/documentation/ + +EXPOSE 8536 +CMD ["/app/lemmy"] diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index b70154cd7..3a17eefc7 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -1,25 +1,55 @@ -ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:stable +ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.47.0 -FROM $RUST_BUILDER_IMAGE as rust +# Cargo chef plan +FROM $RUST_BUILDER_IMAGE as planner +WORKDIR /app +RUN cargo install cargo-chef --version 0.1.6 + +# Copy dirs +COPY ./ ./ + +RUN sudo chown -R rust:rust . +RUN cargo chef prepare --recipe-path recipe.json + +# Cargo chef cache dependencies +FROM $RUST_BUILDER_IMAGE as cacher +ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl +WORKDIR /app +RUN cargo install cargo-chef --version 0.1.6 +COPY --from=planner /app/recipe.json ./recipe.json +RUN sudo chown -R rust:rust . +RUN cargo chef cook --release --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json + +# Build the project +FROM $RUST_BUILDER_IMAGE as builder ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl ARG RUSTRELEASEDIR="release" -WORKDIR /app/server +WORKDIR /app + +# Copy over the cached dependencies +COPY --from=cacher /app/target target +COPY --from=cacher /home/rust/.cargo /home/rust/.cargo + +# Copy the rest of the dirs +COPY ./ ./ + RUN sudo chown -R rust:rust . -COPY . ./ RUN cargo build --release # reduce binary size RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server -RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/server/ +RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server +# Build the docs FROM $RUST_BUILDER_IMAGE as docs WORKDIR /app COPY --chown=rust:rust docs ./docs RUN mdbook build docs/ +# The alpine runner FROM alpine:3.12 as lemmy # Install libpq for postgres @@ -33,7 +63,7 @@ RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy # Copy resources COPY --chown=lemmy:lemmy config/defaults.hjson /config/defaults.hjson -COPY --chown=lemmy:lemmy --from=rust /app/server/lemmy_server /app/lemmy +COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy COPY --chown=lemmy:lemmy --from=docs /app/docs/book/ /app/documentation/ RUN chown lemmy:lemmy /app/lemmy From cd3f20e49b81c6725232e792f4481210284e57df Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 24 Nov 2020 18:53:43 +0100 Subject: [PATCH 2/3] Populate `content` with HTML, and `source` with markdown (ref #1220) --- Cargo.lock | 4 +- docs/src/contributing_apub_api_outline.md | 25 ++++++- lemmy_apub/Cargo.toml | 2 +- lemmy_apub/src/activities/receive/comment.rs | 10 +-- .../src/activities/receive/comment_undo.rs | 7 +- .../src/activities/receive/private_message.rs | 7 +- lemmy_apub/src/fetcher.rs | 7 +- lemmy_apub/src/lib.rs | 9 +-- lemmy_apub/src/objects/comment.rs | 31 +++++---- lemmy_apub/src/objects/community.rs | 26 ++++--- lemmy_apub/src/objects/mod.rs | 68 ++++++++++++++++++- lemmy_apub/src/objects/post.rs | 22 +++--- lemmy_apub/src/objects/private_message.rs | 32 +++++---- lemmy_apub/src/objects/user.rs | 24 ++++--- 14 files changed, 184 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5f984783..b2247c87a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "activitystreams" -version = "0.7.0-alpha.4" +version = "0.7.0-alpha.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261b423734cca2a170d7a76936f1f0f9e6c6fc297d36cfc5ea6aa15f9017f996" +checksum = "0b1afe32371e466a791ced0d6ef6e6b97822bb1a279ee4cc41c4324e61cd0b2b" dependencies = [ "chrono", "mime", diff --git a/docs/src/contributing_apub_api_outline.md b/docs/src/contributing_apub_api_outline.md index f5c7a5951..4fac3cf8d 100644 --- a/docs/src/contributing_apub_api_outline.md +++ b/docs/src/contributing_apub_api_outline.md @@ -64,6 +64,10 @@ Receives activities from user: `Follow`, `Undo/Follow`, `Create`, `Update`, `Lik "https://enterprise.lemmy.ml/u/riker" ], "content": "Welcome to the default community!", + "source": { + "content": "Welcome to the default community!", + "mediaType": "text/markdown" + }, "icon": { "type": "Image", "url": "https://enterprise.lemmy.ml/pictrs/image/Z8pFFb21cl.png" @@ -123,7 +127,11 @@ Sends and receives activities from/to other users: `Create/Note`, `Update/Note`, "type": "Person", "preferredUsername": "picard", "name": "Jean-Luc Picard", - "summary": "The user bio", + "content": "The user bio", + "source": { + "content": "The user bio", + "mediaType": "text/markdown" + }, "icon": { "type": "Image", "url": "https://enterprise.lemmy.ml/pictrs/image/DS3q0colRA.jpg" @@ -150,7 +158,7 @@ Sends and receives activities from/to other users: `Create/Note`, `Update/Note`, |---|---|---| | `preferredUsername` | yes | Name of the actor | | `name` | no | The user's displayname | -| `summary` | no | User bio | +| `content` | no | User bio | | `icon` | no | The user's avatar, shown next to the username | | `image` | no | The user's banner, shown on top of the profile | | `inbox` | no | ActivityPub inbox URL | @@ -174,6 +182,10 @@ A page with title, and optional URL and text content. The URL often leads to an "to": "https://voyager.lemmy.ml/c/main", "summary": "Test thumbnail 2", "content": "blub blub", + "source": { + "content": "blub blub", + "mediaType": "text/markdown" + }, "url": "https://voyager.lemmy.ml:/pictrs/image/fzGwCsq7BJ.jpg", "image": { "type": "Image", @@ -213,6 +225,10 @@ A reply to a post, or reply to another comment. Contains only text (including re "attributedTo": "https://enterprise.lemmy.ml/u/picard", "to": "https://enterprise.lemmy.ml/c/main", "content": "mmmk", + "source": { + "content": "mmmk", + "mediaType": "text/markdown" + }, "inReplyTo": [ "https://enterprise.lemmy.ml/post/38", "https://voyager.lemmy.ml/comment/73" @@ -243,6 +259,11 @@ A direct message from one user to another. Can not include additional users. Thr "attributedTo": "https://enterprise.lemmy.ml/u/picard", "to": "https://voyager.lemmy.ml/u/janeway", "content": "test", + "source": { + "content": "test", + "mediaType": "text/markdown" + }, + "mediaType": "text/markdown", "published": "2020-10-08T19:10:46.542820+00:00", "updated": "2020-10-08T20:13:52.547156+00:00" } diff --git a/lemmy_apub/Cargo.toml b/lemmy_apub/Cargo.toml index 50bf62f02..6dd68bc8e 100644 --- a/lemmy_apub/Cargo.toml +++ b/lemmy_apub/Cargo.toml @@ -14,7 +14,7 @@ lemmy_db = { path = "../lemmy_db" } lemmy_structs = { path = "../lemmy_structs" } lemmy_websocket = { path = "../lemmy_websocket" } diesel = "1.4" -activitystreams = "0.7.0-alpha.4" +activitystreams = "0.7.0-alpha.6" activitystreams-ext = "0.1.0-alpha.2" bcrypt = "0.8" chrono = { version = "0.4", features = ["serde"] } diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index d104d5e19..bf8de1ebd 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -3,11 +3,11 @@ use crate::{ fetcher::get_or_fetch_and_insert_comment, ActorType, FromApub, + NoteExt, }; use activitystreams::{ activity::{ActorAndObjectRefExt, Create, Dislike, Like, Remove, Update}, base::ExtendsExt, - object::Note, }; use anyhow::{anyhow, Context}; use lemmy_db::{ @@ -27,7 +27,7 @@ pub(crate) async fn receive_create_comment( request_counter: &mut i32, ) -> Result<(), LemmyError> { let user = get_actor_as_user(&create, context, request_counter).await?; - let note = Note::from_any_base(create.object().to_owned().one().context(location_info!())?)? + let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)? .context(location_info!())?; let comment = @@ -83,7 +83,7 @@ pub(crate) async fn receive_update_comment( context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let note = Note::from_any_base(update.object().to_owned().one().context(location_info!())?)? + let note = NoteExt::from_any_base(update.object().to_owned().one().context(location_info!())?)? .context(location_info!())?; let user = get_actor_as_user(&update, context, request_counter).await?; @@ -140,7 +140,7 @@ pub(crate) async fn receive_like_comment( context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)? + let note = NoteExt::from_any_base(like.object().to_owned().one().context(location_info!())?)? .context(location_info!())?; let user = get_actor_as_user(&like, context, request_counter).await?; @@ -191,7 +191,7 @@ pub(crate) async fn receive_dislike_comment( context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let note = Note::from_any_base( + let note = NoteExt::from_any_base( dislike .object() .to_owned() diff --git a/lemmy_apub/src/activities/receive/comment_undo.rs b/lemmy_apub/src/activities/receive/comment_undo.rs index 709e8481c..f44604cc1 100644 --- a/lemmy_apub/src/activities/receive/comment_undo.rs +++ b/lemmy_apub/src/activities/receive/comment_undo.rs @@ -2,8 +2,9 @@ use crate::{ activities::receive::get_actor_as_user, fetcher::get_or_fetch_and_insert_comment, FromApub, + NoteExt, }; -use activitystreams::{activity::*, object::Note, prelude::*}; +use activitystreams::{activity::*, prelude::*}; use anyhow::Context; use lemmy_db::{ comment::{Comment, CommentForm, CommentLike}, @@ -20,7 +21,7 @@ pub(crate) async fn receive_undo_like_comment( request_counter: &mut i32, ) -> Result<(), LemmyError> { let user = get_actor_as_user(like, context, request_counter).await?; - let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)? + let note = NoteExt::from_any_base(like.object().to_owned().one().context(location_info!())?)? .context(location_info!())?; let comment = CommentForm::from_apub(¬e, context, None, request_counter).await?; @@ -64,7 +65,7 @@ pub(crate) async fn receive_undo_dislike_comment( request_counter: &mut i32, ) -> Result<(), LemmyError> { let user = get_actor_as_user(dislike, context, request_counter).await?; - let note = Note::from_any_base( + let note = NoteExt::from_any_base( dislike .object() .to_owned() diff --git a/lemmy_apub/src/activities/receive/private_message.rs b/lemmy_apub/src/activities/receive/private_message.rs index 31037d1f6..8f1c95b9d 100644 --- a/lemmy_apub/src/activities/receive/private_message.rs +++ b/lemmy_apub/src/activities/receive/private_message.rs @@ -4,11 +4,12 @@ use crate::{ fetcher::get_or_fetch_and_upsert_user, inbox::get_activity_to_and_cc, FromApub, + NoteExt, }; use activitystreams::{ activity::{ActorAndObjectRefExt, Create, Delete, Undo, Update}, base::{AsBase, ExtendsExt}, - object::{AsObject, Note}, + object::AsObject, public, }; use anyhow::{anyhow, Context}; @@ -30,7 +31,7 @@ pub(crate) async fn receive_create_private_message( ) -> Result<(), LemmyError> { check_private_message_activity_valid(&create, context, request_counter).await?; - let note = Note::from_any_base( + let note = NoteExt::from_any_base( create .object() .as_one() @@ -79,7 +80,7 @@ pub(crate) async fn receive_update_private_message( .as_one() .context(location_info!())? .to_owned(); - let note = Note::from_any_base(object)?.context(location_info!())?; + let note = NoteExt::from_any_base(object)?.context(location_info!())?; let private_message_form = PrivateMessageForm::from_apub(¬e, context, Some(expected_domain), request_counter).await?; diff --git a/lemmy_apub/src/fetcher.rs b/lemmy_apub/src/fetcher.rs index b4598ea37..ec44bce17 100644 --- a/lemmy_apub/src/fetcher.rs +++ b/lemmy_apub/src/fetcher.rs @@ -3,11 +3,12 @@ use crate::{ ActorType, FromApub, GroupExt, + NoteExt, PageExt, PersonExt, APUB_JSON_CONTENT_TYPE, }; -use activitystreams::{base::BaseExt, collection::OrderedCollection, object::Note, prelude::*}; +use activitystreams::{base::BaseExt, collection::OrderedCollection, prelude::*}; use anyhow::{anyhow, Context}; use chrono::NaiveDateTime; use diesel::result::Error::NotFound; @@ -91,7 +92,7 @@ enum SearchAcceptedObjects { Person(Box), Group(Box), Page(Box), - Comment(Box), + Comment(Box), } /// Attempt to parse the query as URL, and fetch an ActivityPub object from it. @@ -488,7 +489,7 @@ pub(crate) async fn get_or_fetch_and_insert_comment( comment_ap_id ); let comment = - fetch_remote_object::(context.client(), comment_ap_id, recursion_counter).await?; + fetch_remote_object::(context.client(), comment_ap_id, recursion_counter).await?; let comment_form = CommentForm::from_apub( &comment, context, diff --git a/lemmy_apub/src/lib.rs b/lemmy_apub/src/lib.rs index 4894b036f..2e3f7bfc6 100644 --- a/lemmy_apub/src/lib.rs +++ b/lemmy_apub/src/lib.rs @@ -18,7 +18,7 @@ use activitystreams::{ activity::Follow, actor::{ApActor, Group, Person}, base::AnyBase, - object::{Page, Tombstone}, + object::{ApObject, Note, Page, Tombstone}, }; use activitystreams_ext::{Ext1, Ext2}; use anyhow::{anyhow, Context}; @@ -31,11 +31,12 @@ use std::net::IpAddr; use url::{ParseError, Url}; /// Activitystreams type for community -type GroupExt = Ext2, GroupExtension, PublicKeyExtension>; +type GroupExt = Ext2>, GroupExtension, PublicKeyExtension>; /// Activitystreams type for user -type PersonExt = Ext1, PublicKeyExtension>; +type PersonExt = Ext1>, PublicKeyExtension>; /// Activitystreams type for post -type PageExt = Ext1; +type PageExt = Ext1, PageExtension>; +type NoteExt = ApObject; pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index ca0b0e850..c3d17e6e0 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -4,12 +4,18 @@ use crate::{ get_or_fetch_and_insert_post, get_or_fetch_and_upsert_user, }, - objects::{check_object_domain, create_tombstone}, + objects::{ + check_object_domain, + create_tombstone, + get_source_markdown_value, + set_content_and_source, + }, FromApub, + NoteExt, ToApub, }; use activitystreams::{ - object::{kind::NoteType, Note, Tombstone}, + object::{kind::NoteType, ApObject, Note, Tombstone}, prelude::*, }; use anyhow::Context; @@ -32,10 +38,10 @@ use url::Url; #[async_trait::async_trait(?Send)] impl ToApub for Comment { - type ApubType = Note; + type ApubType = NoteExt; - async fn to_apub(&self, pool: &DbPool) -> Result { - let mut comment = Note::new(); + async fn to_apub(&self, pool: &DbPool) -> Result { + let mut comment = ApObject::new(Note::new()); let creator_id = self.creator_id; let creator = blocking(pool, move |conn| User_::read(conn, creator_id)).await??; @@ -63,9 +69,10 @@ impl ToApub for Comment { .set_published(convert_datetime(self.published)) .set_to(community.actor_id) .set_many_in_reply_tos(in_reply_to_vec) - .set_content(self.content.to_owned()) .set_attributed_to(creator.actor_id); + set_content_and_source(&mut comment, &self.content)?; + if let Some(u) = self.updated { comment.set_updated(convert_datetime(u)); } @@ -80,13 +87,13 @@ impl ToApub for Comment { #[async_trait::async_trait(?Send)] impl FromApub for CommentForm { - type ApubType = Note; + type ApubType = NoteExt; /// Converts a `Note` to `CommentForm`. /// /// If the parent community, post and comment(s) are not known locally, these are also fetched. async fn from_apub( - note: &Note, + note: &NoteExt, context: &LemmyContext, expected_domain: Option, request_counter: &mut i32, @@ -124,12 +131,8 @@ impl FromApub for CommentForm { } None => None, }; - let content = note - .content() - .context(location_info!())? - .as_single_xsd_string() - .context(location_info!())? - .to_string(); + + let content = get_source_markdown_value(note)?.context(location_info!())?; let content_slurs_removed = remove_slurs(&content); Ok(CommentForm { diff --git a/lemmy_apub/src/objects/community.rs b/lemmy_apub/src/objects/community.rs index d697c70b0..c5a614bad 100644 --- a/lemmy_apub/src/objects/community.rs +++ b/lemmy_apub/src/objects/community.rs @@ -1,7 +1,12 @@ use crate::{ extensions::group_extensions::GroupExtension, fetcher::get_or_fetch_and_upsert_user, - objects::{check_object_domain, create_tombstone}, + objects::{ + check_object_domain, + create_tombstone, + get_source_markdown_value, + set_content_and_source, + }, ActorType, FromApub, GroupExt, @@ -10,7 +15,7 @@ use crate::{ use activitystreams::{ actor::{kind::GroupType, ApActor, Endpoints, Group}, base::BaseExt, - object::{Image, Tombstone}, + object::{ApObject, Image, Tombstone}, prelude::*, }; use activitystreams_ext::Ext2; @@ -46,7 +51,7 @@ impl ToApub for Community { .await??; let moderators: Vec = moderators.into_iter().map(|m| m.user_actor_id).collect(); - let mut group = Group::new(); + let mut group = ApObject::new(Group::new()); group .set_context(activitystreams::context()) .set_id(Url::parse(&self.actor_id)?) @@ -58,9 +63,7 @@ impl ToApub for Community { group.set_updated(convert_datetime(u)); } if let Some(d) = self.description.to_owned() { - // TODO: this should be html, also add source field with raw markdown - // -> same for post.content and others - group.set_content(d); + set_content_and_source(&mut group, &d)?; } if let Some(icon_url) = &self.icon { @@ -138,14 +141,9 @@ impl FromApub for CommunityForm { .as_xsd_string() .context(location_info!())? .to_string(); - // TODO: should be parsed as html and tags like