2021-11-05 00:24:10 +00:00
|
|
|
use crate::{
|
2024-11-07 10:49:05 +00:00
|
|
|
activities::{generate_to, verify_person_in_community, verify_visibility},
|
2022-06-02 14:33:41 +00:00
|
|
|
check_apub_id_valid_with_strictness,
|
2024-10-03 12:24:05 +00:00
|
|
|
fetcher::markdown_links::markdown_rewrite_remote_links,
|
2021-11-15 22:54:25 +00:00
|
|
|
mentions::collect_non_local_mentions,
|
2025-01-28 11:37:29 +00:00
|
|
|
objects::{append_attachments_to_comment, read_from_string_or_source},
|
2022-08-22 20:55:10 +00:00
|
|
|
protocol::{
|
|
|
|
objects::{note::Note, LanguageTag},
|
2022-12-01 20:52:49 +00:00
|
|
|
InCommunity,
|
2022-08-22 20:55:10 +00:00
|
|
|
Source,
|
|
|
|
},
|
2021-11-05 00:24:10 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{
|
2023-03-21 15:03:05 +00:00
|
|
|
config::Data,
|
2024-11-07 10:49:05 +00:00
|
|
|
kinds::object::NoteType,
|
2025-01-28 11:37:29 +00:00
|
|
|
protocol::{
|
|
|
|
values::MediaTypeMarkdownOrHtml,
|
|
|
|
verification::{verify_domains_match, verify_is_remote_object},
|
|
|
|
},
|
2023-03-21 15:03:05 +00:00
|
|
|
traits::Object,
|
2022-06-02 14:33:41 +00:00
|
|
|
};
|
2023-08-24 15:27:00 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
2024-01-25 14:22:11 +00:00
|
|
|
use lemmy_api_common::{
|
|
|
|
context::LemmyContext,
|
2025-02-20 17:47:18 +00:00
|
|
|
utils::{get_url_blocklist, is_mod_or_admin, process_markdown, slur_regex},
|
2024-01-25 14:22:11 +00:00
|
|
|
};
|
2021-03-18 20:25:21 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
source::{
|
2022-10-27 09:24:07 +00:00
|
|
|
comment::{Comment, CommentInsertForm, CommentUpdateForm},
|
2021-03-22 14:08:06 +00:00
|
|
|
community::Community,
|
2021-03-18 20:25:21 +00:00
|
|
|
person::Person,
|
|
|
|
post::Post,
|
|
|
|
},
|
2021-10-16 13:33:38 +00:00
|
|
|
traits::Crud,
|
2020-10-12 14:10:09 +00:00
|
|
|
};
|
|
|
|
use lemmy_utils::{
|
Add test for unused errors, move federation errors into separate struct (#5024)
* Add test case to ensure all errors are in use
* Add test case to find errors that are only used for federation
* Move federation errors into separate enum (fixes #4926)
* clippy
* clippy
* remove serde tag
* Reduce errors dess (#5138)
* Add option to search exclusively by post title (#5015)
* Add option to search exclusively by post title
* Address format issues
* Remove duplicated 'removed' filter
* Replace url_search with search_term
* Build generic PostQuery before search match
* Create default queries. Move title_only to Search struct. Rename Url to PostURL
* Revert PostUrl to Url
* Upgrading webmention to 0.6.0, removes native-tls (#4976)
* Removing embedded pict-rs. (#5023)
Some reasons for removing this:
- Even as an optional dependency, it locks us to many specific versions
of rust deps.
- Pict-rs is a large app that can and should be run in on its own.
- Violates the philosophy of separation of concerns.
* Adding clearurls crate to clean tracking params from links and markdown. (#5018)
* Adding clearurls crate to clean tracking params from links and markdown.
- Thanks to @jenrdikw for creating this
- Fixes #4905
* Upgrading to new version of clearurls
* Fix clippy
* Remove enable nsfw (#5017)
* Remove `local_site.enable_nsfw` in favor of `site.content_warning` (fixes #4627)
* cleanup usage of SiteView::read_local
* test
* uppercase
* SSO Support (#4881)
* Added OAUTH2 OIDC support
* Fixes and improvements based on review feedback
* use derive_new::new instead of TypedBuilder
* merge migrations into a single file
* fixes based on review feedback
* remove unnecessary hostname_ui config
* improvement based on review feedback
* improvements based on review feedback
* delete user oauth accounts at account deletion
* fixes and improvements based on review feedback
* removed auto_approve_application
* support registration application with sso
* improvements based on review feedback
* making the TokenResponse an internal struct as it should be
* remove duplicate struct
* prevent oauth linking to unverified accounts
* switched to manually entered username and removed the oauth name claim
* fix cargo fmt
* fix compile error
* improvements based on review feedback
* fixes and improvements based on review feedback
---------
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
* Adding ability to restore content on user unban. (#4845)
* Adding ability to restore content on user unban.
- Fixes #4721
* Fixing api tests.
* Fix package.json
* Fixing lemmy-js-client dep.
* Adding API test for restoring content.
* Adding a default_comment_sort_type column for local_site and local_user. (#4469)
* Adding a default_comment_sort_type column for local_site and local_user.
- Renamed SortType to PostSortType in the DB and code.
- Renamed references to default_sort_type to default_post_sort_type.
- Fixes #4128
* Renaming migration to current date.
* Simplifying PostSortType.
* Simplify tests using default (#5026)
* Feature/custom emoji and tagline views (#4580)
* Add custom_emoji list route
* Add tagline list route
* Apply linting
* Remove unecessary TaglineView
* Add category filter for custom emoji
* Add create tagline endpoint
* Add update tagline endpoint
* Add delete tagline endpoint
* Format through lint.sh
* Remove custom_emojis and taglines from site resource
* Get random tagline on site requets
* Impl Crud for Tagline
Remove superfluous properties
* Move tagline endpoints under /admin
* Impl Crud for CustomEmoji
* Remove delete from tagline and custom emoji impls
* Check markdown for tagline
* Validate markdown on tagline
* Make content fields non optional
Add error types for tagline validation
* Use process_markdown instead of process_markdown_opt
* Consolidate Tagline error types
* Remove unecessary clone
* Updat misleading comments
* Remove local_site_id from tagline and custom_emoji
* Update TaglineInserForm and TaglineUpdateForm
* Add ignore_page_limits for custom emojis
EmojiPicker needs to be able to retrieve all emojis in 1 call
* Update custom_emoji_view
Only keep get_all als helper function calling list with paging ignored
Only order on category when filtering on category
* Removing pointless get_all fn.
* remove tagline length checks
* make fields of TaglineInsertForm and TaglineUpdateForm mandatory
* move emoji order statement
* add comment for GetSiteResponse.tagline
---------
Co-authored-by: Freakazoid182 <>
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
Co-authored-by: Dessalines <tyhou13@gmx.com>
Co-authored-by: Felix Ableitner <me@nutomic.com>
* Add category to RSS feeds (fixes #3446) (#5030)
* Unittest for Search by title only (#5033)
* added test for search by title only
* formatted rust files
* Upgrading to rust 1.81 (#5032)
* Remove TypedBuilder in favor of derive_new (fixes #4863) (#5020)
* Remove TypedBuilder in favor of derive_new (fixes #4863)
* fix
* fix
* Ignore zero values when setting rate limits (fixes #4280) (#5029)
* Ignore zero values when setting rate limits (fixes #4280)
Havent bothered to add an error message for such an uncommon case.
* fmt
* reorder, add test
* Always save remote image data (#4875)
* Always save remote image data
* cleanup
---------
Co-authored-by: Felix Ableitner <me@nutomic.com>
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Get rid of a lot of pointless mut form initializations. (#5037)
* Get rid of a lot of pointless mut form initializations.
- Fixes #5036
* Fix clippy.
* Simplify handling of NotFound SQL errors (fixes #4633) (#5031)
* Simplify handling of NotFound SQL errors (fixes #4633)
* fmt
* wip
* compiling
* clippy
* api tests
* fix
* Adding saved_only, liked_only, and disliked_only filters to search. (#5034)
* Adding saved_only, liked_only, and disliked_only filters to search.
- Fixes #4547
* Removing duplicate Url return type for search (was actually post).
- This now works like the post_title_only filter.
* Address PR comments.
* Add saved_only post_view test.
* Removing a few more Result<bool> . (#4977)
* Removing a few more Result<bool> .
* Running taplo fmt.
* Running fmt.
* Adding email taken test.
* Fixing tests.
* Adding back in missing admin check.
* Rename check_has_local_followers function.
* Conditionally hide comments on nsfw posts (fixes #4237) (#5028)
* Conditionally hide comments on nsfw posts (fixes #4237)
* fix test
* Post scheduling (fixes #234) (#5025)
* Post scheduling (fixes #234)
* clippy
* replace map_err with inspect_err
* ignore unpublished posts in read queries
* add api test
* fmt
* add some checks
* address some review comments
* allow updating schedule time
* rewrite scheduled task
* fmt
* machete
* compare date in sql, more filters
* check for community ban in sql
* remove api test (scheduled task only runs every 10 mins)
* remove mut
* add index
* remove Post::read impl
* fmt
* fix
* correctly handle changes to schedule time
* normal users can only schedule up to 10 posts
* Remove redundant local_user.auto_expand setting. (#5041)
- Fixes #4643
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* Add ability to search for Community by its description (or title only). (#5044)
- This changes the post_title_only for Search to title_only, since its
also used in the community query now.
- Fixes #4785
* Cleanup remaining use of Result<bool, Error> (fixes #4862) (#5047)
* Replace clippy allow annotation with expect (fixes #5012) (#5048)
* Add skip_serialize_none to OAuth structs with option fields (#5046)
* Add skip_serialize_none to OAuth structs with option fields
* PR feedback
* Remove serde and ts export from SSO db-only structs
* Apply scheduled post limit to future posts instead of past posts, and verify this in test (#5054)
* test scheduled_post_count
* fix syntax error
* fix formatting
* fix argument order
* fix user_scheduled_post_count function
* Avoid breaking changes, keep response fields as deprecated (#5058)
* Adding skip_serializing_none to another OAuth API request. (#5060)
* Handle partial settings backup (fixes #4307) (#5063)
* Handle partial settings backup (fixes #4307)
* clippy
* Avoid stack overflow when fetching nested comments, reduce max comment depth to 50 (#5009)
* Avoid stack overflow when fetching deeply nested comments
* add test case
* reduce comment depth, add docs
* decrease
* reduce max comment depth to 50
* fmt
* clippy
* cleanup
* Update Rust crate clap to v4.5.18 (#5066)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate reqwest to v0.12.8 (#5068)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate sitemap-rs to v0.2.2 (#5069)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate tracing-actix-web to v0.7.13 (#5070)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Changing renovate to run on the weekends. (#5067)
- Lemmy builds take a long time, and the current schedule only runs for
about 4 hours once a month, and renovate also rate-limits itself to
~ 2 per hour. This gives it a large enough window, without clogging
up my runner machines.
* Update Rust crate async-trait to v0.1.83 (#5065)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency @types/jest to v29.5.13 (#5071)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Attempt to fix test for fetching deeply nested comment (#5072)
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Add modlog entries for bulk removals. (#5050)
* Add modlog entries for bulk removals.
- Added unit tests for removal / restore to api_common/utils.
- Fixes #4699
* Address PR comments.
* Combining remove and restore functions.
* Trigger build.
* Trigger build 2.
* Changing allow to expect.
* Adding local site settings to reject federated upvotes or downvotes. (#5038)
* Adding local site settings to reject federated upvotes or downvotes.
- Should help defend against downvote spamming instances.
- Fixes #4086
* Adding new vote mode types.
* Simpler activitypub vote check.
* Adding undo vote for failed vote mode check.
* Update crates/api_common/src/utils.rs
---------
Co-authored-by: Nutomic <me@nutomic.com>
* Replace `clippy::unwrap_used` in tests (#5064)
* Add LemmyResult to session_middleware tests
* Add LemmyResult to inboxes tests
* Add LemmyResult to slurs tests
* Add LemmyResult to markdown tests
* Add LemmyResult to rate_limiter tests
* Add LemmyResult to error tests
* Add LemmyResult to api_common utils tests
* Add LemmyResult to request tests
* Add LemmyResult to claims tests
* Propagate registration_applications errors
* Remove clippy::unwrap_used from community tests
* Add LemmyResult to community_view tests
* Add LemmyResult to db_schema post tests
* Add LemmyResult to site_aggregates tests
* Add LemmyResult to private_message tests
* Add LemmyResult to activity tests
* Add LemmyResult to federation_allowlist tests
* Add LemmyResult to comment_aggregates tests
* Add LemmyResult to post_report tests
* Add LemmyResult to moderator tests
* Add LemmyResult to community_aggregates tests
* Add LemmyResult to person_aggregates tests
* Add LemmyResult to language tests
* Add LemmyResult to post_aggregates tests
* Add LemmyResult to db_schema comment tests
* Add LemmyResult to actor_language tests
* Add LemmyResult to vote_view tests
* Add LemmyResult to registration_application_view tests
* Add LemmyResult to private_message_view tests
* Add LemmyResult to private_message_report_view tests
* Add LemmyResult to post_report_view tests
* Add LemmyResult to comment_report_view tests
* Add LemmyResult to sitemap tests
* Replace .expect() with .unwrap()
* Format code
* Remove clippy::unwrap_used from activity tests
* Add diesel result in db_schema tests
* Format code
* Map to_bytes() error to LemmyErrorType
* Remove clippy::unwrap_used from error tests
* Removing a few more unwraps, and cleaning up language code.
* Replace map_err with unwrap_or_default
* Replace ok_or with and_then
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
* Adding a get_random_community endpoint. (#5042)
* Adding a get_random_community endpoint.
- Fixes #4698
* Fixing issue from main.
* Adding ListingType to the query.
* More concise query filter.
* Resolve links to remote posts into local URL (#5057)
* move code to new file
* rewrite markdown links (fixes #2987)
* add missing file
* add helper fn
* also convert post.url
* simplify search.rs
* clippy
* also rewrite user/community links in markdown
* Call from apub handlers, cleanup
* no network requests in test
* clippy
* fix tests
* serial
* test
* no mut
* add api test
* fix api test
* Update Rust crate clap to v4.5.19 (#5080)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate html2text to v0.12.6 (#5081)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate rustls to v0.23.14 (#5083)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update rust-futures monorepo to v0.3.31 (#5090)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate actix-web-prom to 0.9.0 (#5091)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate regex to v1.11.0 (#5093)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate serde_with to v3.10.0 (#5094)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate serde_with to v3.11.0 (#5095)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency ts-jest to v29.2.5 (#5089)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency typescript to v5.6.2 (#5098)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency eslint to v9.12.0 (#5097)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update docker/dockerfile Docker tag to v1.10 (#5099)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update pnpm to v9.12.0 (#5100)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate reqwest to v0.12.8 (#5082)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency @types/node to v22.7.4 (#5096)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update tamasfe/taplo Docker tag to v0.9.3 (#5101)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update tmknom/prettier Docker tag to v3.2.5 (#5102)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Add test case for community.hidden in post_view (ref #5074) (#5106)
* Resize post thumbnails (fixes #4053) (#5107)
* Resize post thumbnails (fixes #4053)
* 256px
* Update typescript-eslint monorepo to v8.8.1 (#5103)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update renovate config (#5109)
* Update renovate config
* ignroe rust updates, run on first day of month
* fix
* Add community alphabetic sorting (#5056)
* Started
* Finished? Need to write tests
* Formatting
* Formatting
* Formatting
* Write tests
* Formatting
* Formatting
* Formatting
* Unnecessary lifetime
* Safety
* Unwrap
* Formatting
* Formatting
* Fix local_only test
* Formatting
* Name consistency
* Adding lower to community name sort.
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Support markdown sub/superscript, use external crate for spoilers (#5135)
* Use external crate for spoiler tags
* Also add other plugins
* fix test
* Remove comment_like.post_id column which is unnecessary (ref #5122) (#5134)
* Allow admins to resolve removed or deleted objects via API (#5061)
* Allow admins to resolve removed or deleted objects via API
* Removing pointless TestUser.
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
* Remove individual user/community inboxes (#5124)
* Remove endpoints for individual community/user inboxes
fixes #4147
fixes #3928
* Remove shared_inbox_url columns
* fmt
* Fixing errors.
---------
Co-authored-by: Carlos Cabello <carloscabello364@gmail.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: privacyguard <92675882+privacyguard@users.noreply.github.com>
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
Co-authored-by: Freakazoid182 <5238563+Freakazoid182@users.noreply.github.com>
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
Co-authored-by: leoseg <70430884+leoseg@users.noreply.github.com>
Co-authored-by: Sander Saarend <sander@saarend.com>
Co-authored-by: Joseph Silva <dull.bananas0@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: netbrum <130702882+netbrum@users.noreply.github.com>
Co-authored-by: Steven Vergenz <1882376+stevenvergenz@users.noreply.github.com>
Co-authored-by: Richard Schwab <gitrichardschwab-7a2qxq42kj@central-intelligence.agency>
* Search with LemmyErrorType prefix
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Carlos Cabello <carloscabello364@gmail.com>
Co-authored-by: privacyguard <92675882+privacyguard@users.noreply.github.com>
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
Co-authored-by: Freakazoid182 <5238563+Freakazoid182@users.noreply.github.com>
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
Co-authored-by: leoseg <70430884+leoseg@users.noreply.github.com>
Co-authored-by: Sander Saarend <sander@saarend.com>
Co-authored-by: Joseph Silva <dull.bananas0@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: netbrum <130702882+netbrum@users.noreply.github.com>
Co-authored-by: Steven Vergenz <1882376+stevenvergenz@users.noreply.github.com>
Co-authored-by: Richard Schwab <gitrichardschwab-7a2qxq42kj@central-intelligence.agency>
Co-authored-by: Dessalines <tyhou13@gmx.com>
2024-10-28 15:07:13 +00:00
|
|
|
error::{FederationError, LemmyError, LemmyResult},
|
2024-01-25 14:22:11 +00:00
|
|
|
utils::markdown::markdown_to_html,
|
2020-10-12 14:10:09 +00:00
|
|
|
};
|
2021-11-05 00:24:10 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
use url::Url;
|
2021-07-31 14:57:37 +00:00
|
|
|
|
2021-10-18 21:36:44 +00:00
|
|
|
#[derive(Clone, Debug)]
|
2022-11-28 14:29:33 +00:00
|
|
|
pub struct ApubComment(pub(crate) Comment);
|
2021-10-18 21:36:44 +00:00
|
|
|
|
|
|
|
impl Deref for ApubComment {
|
|
|
|
type Target = Comment;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Comment> for ApubComment {
|
|
|
|
fn from(c: Comment) -> Self {
|
2022-03-30 14:58:03 +00:00
|
|
|
ApubComment(c)
|
2021-10-18 21:36:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
#[async_trait::async_trait]
|
|
|
|
impl Object for ApubComment {
|
2021-10-18 21:36:44 +00:00
|
|
|
type DataType = LemmyContext;
|
2023-03-21 15:03:05 +00:00
|
|
|
type Kind = Note;
|
2022-06-02 14:33:41 +00:00
|
|
|
type Error = LemmyError;
|
2021-10-18 21:36:44 +00:00
|
|
|
|
2023-08-24 15:27:00 +00:00
|
|
|
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
|
2021-10-18 21:36:44 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
async fn read_from_id(
|
2021-10-18 21:36:44 +00:00
|
|
|
object_id: Url,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<Self::DataType>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<Option<Self>> {
|
2021-10-18 21:36:44 +00:00
|
|
|
Ok(
|
2023-07-11 13:09:59 +00:00
|
|
|
Comment::read_from_apub_id(&mut context.pool(), object_id)
|
2022-11-09 10:05:00 +00:00
|
|
|
.await?
|
|
|
|
.map(Into::into),
|
2021-10-18 21:36:44 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn delete(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
|
2021-11-03 17:47:24 +00:00
|
|
|
if !self.deleted {
|
2023-08-08 09:41:41 +00:00
|
|
|
let form = CommentUpdateForm {
|
|
|
|
deleted: Some(true),
|
|
|
|
..Default::default()
|
|
|
|
};
|
2023-07-11 13:09:59 +00:00
|
|
|
Comment::update(&mut context.pool(), self.id, &form).await?;
|
2021-11-03 17:47:24 +00:00
|
|
|
}
|
2021-10-18 21:36:44 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-10-12 14:10:09 +00:00
|
|
|
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<Note> {
|
2020-10-12 14:10:09 +00:00
|
|
|
let creator_id = self.creator_id;
|
2024-09-23 15:26:50 +00:00
|
|
|
let creator = Person::read(&mut context.pool(), creator_id).await?;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
|
|
|
let post_id = self.post_id;
|
2024-09-23 15:26:50 +00:00
|
|
|
let post = Post::read(&mut context.pool(), post_id).await?;
|
2021-11-15 22:54:25 +00:00
|
|
|
let community_id = post.community_id;
|
2024-09-23 15:26:50 +00:00
|
|
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
let in_reply_to = if let Some(comment_id) = self.parent_comment_id() {
|
2024-09-23 15:26:50 +00:00
|
|
|
let parent_comment = Comment::read(&mut context.pool(), comment_id).await?;
|
2023-03-21 15:03:05 +00:00
|
|
|
parent_comment.ap_id.into()
|
2021-10-22 16:21:26 +00:00
|
|
|
} else {
|
2023-03-21 15:03:05 +00:00
|
|
|
post.ap_id.into()
|
2021-10-22 16:21:26 +00:00
|
|
|
};
|
2024-10-02 12:50:21 +00:00
|
|
|
let language = Some(LanguageTag::new_single(self.language_id, &mut context.pool()).await?);
|
2025-01-09 14:41:39 +00:00
|
|
|
let maa = collect_non_local_mentions(&self, context).await?;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
2021-07-31 14:57:37 +00:00
|
|
|
let note = Note {
|
|
|
|
r#type: NoteType::Note,
|
2023-03-21 15:03:05 +00:00
|
|
|
id: self.ap_id.clone().into(),
|
2025-02-06 03:56:37 +00:00
|
|
|
attributed_to: creator.ap_id.into(),
|
2025-01-09 14:41:39 +00:00
|
|
|
to: generate_to(&community)?,
|
2021-11-15 22:54:25 +00:00
|
|
|
cc: maa.ccs,
|
2021-11-02 11:49:28 +00:00
|
|
|
content: markdown_to_html(&self.content),
|
2022-05-06 23:53:33 +00:00
|
|
|
media_type: Some(MediaTypeMarkdownOrHtml::Html),
|
2022-04-01 18:25:19 +00:00
|
|
|
source: Some(Source::new(self.content.clone())),
|
2021-10-22 16:21:26 +00:00
|
|
|
in_reply_to,
|
2023-10-17 17:25:35 +00:00
|
|
|
published: Some(self.published),
|
|
|
|
updated: self.updated,
|
2021-11-15 22:54:25 +00:00
|
|
|
tag: maa.tags,
|
2022-08-17 11:38:52 +00:00
|
|
|
distinguished: Some(self.distinguished),
|
2022-10-06 18:27:58 +00:00
|
|
|
language,
|
2024-10-31 12:13:42 +00:00
|
|
|
attachment: vec![],
|
2021-07-31 14:57:37 +00:00
|
|
|
};
|
2020-10-12 14:10:09 +00:00
|
|
|
|
2021-07-31 14:57:37 +00:00
|
|
|
Ok(note)
|
2020-10-12 14:10:09 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 13:21:41 +00:00
|
|
|
/// Recursively fetches all parent comments. This can lead to a stack overflow so we need to
|
|
|
|
/// Box::pin all large futures on the heap.
|
2021-11-06 17:35:14 +00:00
|
|
|
async fn verify(
|
|
|
|
note: &Note,
|
2021-08-12 12:48:09 +00:00
|
|
|
expected_domain: &Url,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2024-04-10 14:14:11 +00:00
|
|
|
) -> LemmyResult<()> {
|
2021-11-03 16:26:09 +00:00
|
|
|
verify_domains_match(note.id.inner(), expected_domain)?;
|
2021-11-06 17:35:14 +00:00
|
|
|
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
2024-10-01 13:21:41 +00:00
|
|
|
let community = Box::pin(note.community(context)).await?;
|
2024-11-07 10:49:05 +00:00
|
|
|
verify_visibility(¬e.to, ¬e.cc, &community)?;
|
2024-10-01 13:21:41 +00:00
|
|
|
|
|
|
|
Box::pin(check_apub_id_valid_with_strictness(
|
|
|
|
note.id.inner(),
|
|
|
|
community.local,
|
|
|
|
context,
|
|
|
|
))
|
|
|
|
.await?;
|
2024-04-11 14:05:49 +00:00
|
|
|
verify_is_remote_object(¬e.id, context)?;
|
2024-10-01 13:21:41 +00:00
|
|
|
Box::pin(verify_person_in_community(
|
|
|
|
¬e.attributed_to,
|
|
|
|
&community,
|
|
|
|
context,
|
|
|
|
))
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let (post, _) = Box::pin(note.get_parents(context)).await?;
|
|
|
|
let creator = Box::pin(note.attributed_to.dereference(context)).await?;
|
2024-03-04 14:15:21 +00:00
|
|
|
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), &creator, community.id)
|
|
|
|
.await
|
|
|
|
.is_ok();
|
|
|
|
if post.locked && !is_mod_or_admin {
|
Add test for unused errors, move federation errors into separate struct (#5024)
* Add test case to ensure all errors are in use
* Add test case to find errors that are only used for federation
* Move federation errors into separate enum (fixes #4926)
* clippy
* clippy
* remove serde tag
* Reduce errors dess (#5138)
* Add option to search exclusively by post title (#5015)
* Add option to search exclusively by post title
* Address format issues
* Remove duplicated 'removed' filter
* Replace url_search with search_term
* Build generic PostQuery before search match
* Create default queries. Move title_only to Search struct. Rename Url to PostURL
* Revert PostUrl to Url
* Upgrading webmention to 0.6.0, removes native-tls (#4976)
* Removing embedded pict-rs. (#5023)
Some reasons for removing this:
- Even as an optional dependency, it locks us to many specific versions
of rust deps.
- Pict-rs is a large app that can and should be run in on its own.
- Violates the philosophy of separation of concerns.
* Adding clearurls crate to clean tracking params from links and markdown. (#5018)
* Adding clearurls crate to clean tracking params from links and markdown.
- Thanks to @jenrdikw for creating this
- Fixes #4905
* Upgrading to new version of clearurls
* Fix clippy
* Remove enable nsfw (#5017)
* Remove `local_site.enable_nsfw` in favor of `site.content_warning` (fixes #4627)
* cleanup usage of SiteView::read_local
* test
* uppercase
* SSO Support (#4881)
* Added OAUTH2 OIDC support
* Fixes and improvements based on review feedback
* use derive_new::new instead of TypedBuilder
* merge migrations into a single file
* fixes based on review feedback
* remove unnecessary hostname_ui config
* improvement based on review feedback
* improvements based on review feedback
* delete user oauth accounts at account deletion
* fixes and improvements based on review feedback
* removed auto_approve_application
* support registration application with sso
* improvements based on review feedback
* making the TokenResponse an internal struct as it should be
* remove duplicate struct
* prevent oauth linking to unverified accounts
* switched to manually entered username and removed the oauth name claim
* fix cargo fmt
* fix compile error
* improvements based on review feedback
* fixes and improvements based on review feedback
---------
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
* Adding ability to restore content on user unban. (#4845)
* Adding ability to restore content on user unban.
- Fixes #4721
* Fixing api tests.
* Fix package.json
* Fixing lemmy-js-client dep.
* Adding API test for restoring content.
* Adding a default_comment_sort_type column for local_site and local_user. (#4469)
* Adding a default_comment_sort_type column for local_site and local_user.
- Renamed SortType to PostSortType in the DB and code.
- Renamed references to default_sort_type to default_post_sort_type.
- Fixes #4128
* Renaming migration to current date.
* Simplifying PostSortType.
* Simplify tests using default (#5026)
* Feature/custom emoji and tagline views (#4580)
* Add custom_emoji list route
* Add tagline list route
* Apply linting
* Remove unecessary TaglineView
* Add category filter for custom emoji
* Add create tagline endpoint
* Add update tagline endpoint
* Add delete tagline endpoint
* Format through lint.sh
* Remove custom_emojis and taglines from site resource
* Get random tagline on site requets
* Impl Crud for Tagline
Remove superfluous properties
* Move tagline endpoints under /admin
* Impl Crud for CustomEmoji
* Remove delete from tagline and custom emoji impls
* Check markdown for tagline
* Validate markdown on tagline
* Make content fields non optional
Add error types for tagline validation
* Use process_markdown instead of process_markdown_opt
* Consolidate Tagline error types
* Remove unecessary clone
* Updat misleading comments
* Remove local_site_id from tagline and custom_emoji
* Update TaglineInserForm and TaglineUpdateForm
* Add ignore_page_limits for custom emojis
EmojiPicker needs to be able to retrieve all emojis in 1 call
* Update custom_emoji_view
Only keep get_all als helper function calling list with paging ignored
Only order on category when filtering on category
* Removing pointless get_all fn.
* remove tagline length checks
* make fields of TaglineInsertForm and TaglineUpdateForm mandatory
* move emoji order statement
* add comment for GetSiteResponse.tagline
---------
Co-authored-by: Freakazoid182 <>
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
Co-authored-by: Dessalines <tyhou13@gmx.com>
Co-authored-by: Felix Ableitner <me@nutomic.com>
* Add category to RSS feeds (fixes #3446) (#5030)
* Unittest for Search by title only (#5033)
* added test for search by title only
* formatted rust files
* Upgrading to rust 1.81 (#5032)
* Remove TypedBuilder in favor of derive_new (fixes #4863) (#5020)
* Remove TypedBuilder in favor of derive_new (fixes #4863)
* fix
* fix
* Ignore zero values when setting rate limits (fixes #4280) (#5029)
* Ignore zero values when setting rate limits (fixes #4280)
Havent bothered to add an error message for such an uncommon case.
* fmt
* reorder, add test
* Always save remote image data (#4875)
* Always save remote image data
* cleanup
---------
Co-authored-by: Felix Ableitner <me@nutomic.com>
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Get rid of a lot of pointless mut form initializations. (#5037)
* Get rid of a lot of pointless mut form initializations.
- Fixes #5036
* Fix clippy.
* Simplify handling of NotFound SQL errors (fixes #4633) (#5031)
* Simplify handling of NotFound SQL errors (fixes #4633)
* fmt
* wip
* compiling
* clippy
* api tests
* fix
* Adding saved_only, liked_only, and disliked_only filters to search. (#5034)
* Adding saved_only, liked_only, and disliked_only filters to search.
- Fixes #4547
* Removing duplicate Url return type for search (was actually post).
- This now works like the post_title_only filter.
* Address PR comments.
* Add saved_only post_view test.
* Removing a few more Result<bool> . (#4977)
* Removing a few more Result<bool> .
* Running taplo fmt.
* Running fmt.
* Adding email taken test.
* Fixing tests.
* Adding back in missing admin check.
* Rename check_has_local_followers function.
* Conditionally hide comments on nsfw posts (fixes #4237) (#5028)
* Conditionally hide comments on nsfw posts (fixes #4237)
* fix test
* Post scheduling (fixes #234) (#5025)
* Post scheduling (fixes #234)
* clippy
* replace map_err with inspect_err
* ignore unpublished posts in read queries
* add api test
* fmt
* add some checks
* address some review comments
* allow updating schedule time
* rewrite scheduled task
* fmt
* machete
* compare date in sql, more filters
* check for community ban in sql
* remove api test (scheduled task only runs every 10 mins)
* remove mut
* add index
* remove Post::read impl
* fmt
* fix
* correctly handle changes to schedule time
* normal users can only schedule up to 10 posts
* Remove redundant local_user.auto_expand setting. (#5041)
- Fixes #4643
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
* Add ability to search for Community by its description (or title only). (#5044)
- This changes the post_title_only for Search to title_only, since its
also used in the community query now.
- Fixes #4785
* Cleanup remaining use of Result<bool, Error> (fixes #4862) (#5047)
* Replace clippy allow annotation with expect (fixes #5012) (#5048)
* Add skip_serialize_none to OAuth structs with option fields (#5046)
* Add skip_serialize_none to OAuth structs with option fields
* PR feedback
* Remove serde and ts export from SSO db-only structs
* Apply scheduled post limit to future posts instead of past posts, and verify this in test (#5054)
* test scheduled_post_count
* fix syntax error
* fix formatting
* fix argument order
* fix user_scheduled_post_count function
* Avoid breaking changes, keep response fields as deprecated (#5058)
* Adding skip_serializing_none to another OAuth API request. (#5060)
* Handle partial settings backup (fixes #4307) (#5063)
* Handle partial settings backup (fixes #4307)
* clippy
* Avoid stack overflow when fetching nested comments, reduce max comment depth to 50 (#5009)
* Avoid stack overflow when fetching deeply nested comments
* add test case
* reduce comment depth, add docs
* decrease
* reduce max comment depth to 50
* fmt
* clippy
* cleanup
* Update Rust crate clap to v4.5.18 (#5066)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate reqwest to v0.12.8 (#5068)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate sitemap-rs to v0.2.2 (#5069)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate tracing-actix-web to v0.7.13 (#5070)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Changing renovate to run on the weekends. (#5067)
- Lemmy builds take a long time, and the current schedule only runs for
about 4 hours once a month, and renovate also rate-limits itself to
~ 2 per hour. This gives it a large enough window, without clogging
up my runner machines.
* Update Rust crate async-trait to v0.1.83 (#5065)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency @types/jest to v29.5.13 (#5071)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Attempt to fix test for fetching deeply nested comment (#5072)
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Add modlog entries for bulk removals. (#5050)
* Add modlog entries for bulk removals.
- Added unit tests for removal / restore to api_common/utils.
- Fixes #4699
* Address PR comments.
* Combining remove and restore functions.
* Trigger build.
* Trigger build 2.
* Changing allow to expect.
* Adding local site settings to reject federated upvotes or downvotes. (#5038)
* Adding local site settings to reject federated upvotes or downvotes.
- Should help defend against downvote spamming instances.
- Fixes #4086
* Adding new vote mode types.
* Simpler activitypub vote check.
* Adding undo vote for failed vote mode check.
* Update crates/api_common/src/utils.rs
---------
Co-authored-by: Nutomic <me@nutomic.com>
* Replace `clippy::unwrap_used` in tests (#5064)
* Add LemmyResult to session_middleware tests
* Add LemmyResult to inboxes tests
* Add LemmyResult to slurs tests
* Add LemmyResult to markdown tests
* Add LemmyResult to rate_limiter tests
* Add LemmyResult to error tests
* Add LemmyResult to api_common utils tests
* Add LemmyResult to request tests
* Add LemmyResult to claims tests
* Propagate registration_applications errors
* Remove clippy::unwrap_used from community tests
* Add LemmyResult to community_view tests
* Add LemmyResult to db_schema post tests
* Add LemmyResult to site_aggregates tests
* Add LemmyResult to private_message tests
* Add LemmyResult to activity tests
* Add LemmyResult to federation_allowlist tests
* Add LemmyResult to comment_aggregates tests
* Add LemmyResult to post_report tests
* Add LemmyResult to moderator tests
* Add LemmyResult to community_aggregates tests
* Add LemmyResult to person_aggregates tests
* Add LemmyResult to language tests
* Add LemmyResult to post_aggregates tests
* Add LemmyResult to db_schema comment tests
* Add LemmyResult to actor_language tests
* Add LemmyResult to vote_view tests
* Add LemmyResult to registration_application_view tests
* Add LemmyResult to private_message_view tests
* Add LemmyResult to private_message_report_view tests
* Add LemmyResult to post_report_view tests
* Add LemmyResult to comment_report_view tests
* Add LemmyResult to sitemap tests
* Replace .expect() with .unwrap()
* Format code
* Remove clippy::unwrap_used from activity tests
* Add diesel result in db_schema tests
* Format code
* Map to_bytes() error to LemmyErrorType
* Remove clippy::unwrap_used from error tests
* Removing a few more unwraps, and cleaning up language code.
* Replace map_err with unwrap_or_default
* Replace ok_or with and_then
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
* Adding a get_random_community endpoint. (#5042)
* Adding a get_random_community endpoint.
- Fixes #4698
* Fixing issue from main.
* Adding ListingType to the query.
* More concise query filter.
* Resolve links to remote posts into local URL (#5057)
* move code to new file
* rewrite markdown links (fixes #2987)
* add missing file
* add helper fn
* also convert post.url
* simplify search.rs
* clippy
* also rewrite user/community links in markdown
* Call from apub handlers, cleanup
* no network requests in test
* clippy
* fix tests
* serial
* test
* no mut
* add api test
* fix api test
* Update Rust crate clap to v4.5.19 (#5080)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate html2text to v0.12.6 (#5081)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate rustls to v0.23.14 (#5083)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update rust-futures monorepo to v0.3.31 (#5090)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate actix-web-prom to 0.9.0 (#5091)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate regex to v1.11.0 (#5093)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate serde_with to v3.10.0 (#5094)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate serde_with to v3.11.0 (#5095)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency ts-jest to v29.2.5 (#5089)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency typescript to v5.6.2 (#5098)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency eslint to v9.12.0 (#5097)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update docker/dockerfile Docker tag to v1.10 (#5099)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update pnpm to v9.12.0 (#5100)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update Rust crate reqwest to v0.12.8 (#5082)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update dependency @types/node to v22.7.4 (#5096)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update tamasfe/taplo Docker tag to v0.9.3 (#5101)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update tmknom/prettier Docker tag to v3.2.5 (#5102)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Add test case for community.hidden in post_view (ref #5074) (#5106)
* Resize post thumbnails (fixes #4053) (#5107)
* Resize post thumbnails (fixes #4053)
* 256px
* Update typescript-eslint monorepo to v8.8.1 (#5103)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Update renovate config (#5109)
* Update renovate config
* ignroe rust updates, run on first day of month
* fix
* Add community alphabetic sorting (#5056)
* Started
* Finished? Need to write tests
* Formatting
* Formatting
* Formatting
* Write tests
* Formatting
* Formatting
* Formatting
* Unnecessary lifetime
* Safety
* Unwrap
* Formatting
* Formatting
* Fix local_only test
* Formatting
* Name consistency
* Adding lower to community name sort.
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
* Support markdown sub/superscript, use external crate for spoilers (#5135)
* Use external crate for spoiler tags
* Also add other plugins
* fix test
* Remove comment_like.post_id column which is unnecessary (ref #5122) (#5134)
* Allow admins to resolve removed or deleted objects via API (#5061)
* Allow admins to resolve removed or deleted objects via API
* Removing pointless TestUser.
---------
Co-authored-by: Dessalines <tyhou13@gmx.com>
* Remove individual user/community inboxes (#5124)
* Remove endpoints for individual community/user inboxes
fixes #4147
fixes #3928
* Remove shared_inbox_url columns
* fmt
* Fixing errors.
---------
Co-authored-by: Carlos Cabello <carloscabello364@gmail.com>
Co-authored-by: Nutomic <me@nutomic.com>
Co-authored-by: privacyguard <92675882+privacyguard@users.noreply.github.com>
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
Co-authored-by: Freakazoid182 <5238563+Freakazoid182@users.noreply.github.com>
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
Co-authored-by: leoseg <70430884+leoseg@users.noreply.github.com>
Co-authored-by: Sander Saarend <sander@saarend.com>
Co-authored-by: Joseph Silva <dull.bananas0@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: netbrum <130702882+netbrum@users.noreply.github.com>
Co-authored-by: Steven Vergenz <1882376+stevenvergenz@users.noreply.github.com>
Co-authored-by: Richard Schwab <gitrichardschwab-7a2qxq42kj@central-intelligence.agency>
* Search with LemmyErrorType prefix
---------
Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
Co-authored-by: Carlos Cabello <carloscabello364@gmail.com>
Co-authored-by: privacyguard <92675882+privacyguard@users.noreply.github.com>
Co-authored-by: privacyguard <privacyguard@users.noreply.github.com>
Co-authored-by: Freakazoid182 <5238563+Freakazoid182@users.noreply.github.com>
Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com>
Co-authored-by: leoseg <70430884+leoseg@users.noreply.github.com>
Co-authored-by: Sander Saarend <sander@saarend.com>
Co-authored-by: Joseph Silva <dull.bananas0@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: netbrum <130702882+netbrum@users.noreply.github.com>
Co-authored-by: Steven Vergenz <1882376+stevenvergenz@users.noreply.github.com>
Co-authored-by: Richard Schwab <gitrichardschwab-7a2qxq42kj@central-intelligence.agency>
Co-authored-by: Dessalines <tyhou13@gmx.com>
2024-10-28 15:07:13 +00:00
|
|
|
Err(FederationError::PostIsLocked)?
|
2023-08-31 13:01:08 +00:00
|
|
|
} else {
|
|
|
|
Ok(())
|
2021-09-25 15:44:52 +00:00
|
|
|
}
|
2021-11-06 17:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Converts a `Note` to `Comment`.
|
|
|
|
///
|
|
|
|
/// If the parent community, post and comment(s) are not known locally, these are also fetched.
|
2024-04-10 14:14:11 +00:00
|
|
|
async fn from_json(note: Note, context: &Data<LemmyContext>) -> LemmyResult<ApubComment> {
|
2023-03-21 15:03:05 +00:00
|
|
|
let creator = note.attributed_to.dereference(context).await?;
|
|
|
|
let (post, parent_comment) = note.get_parents(context).await?;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
2022-05-06 23:53:33 +00:00
|
|
|
let content = read_from_string_or_source(¬e.content, ¬e.media_type, ¬e.source);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2025-02-20 17:47:18 +00:00
|
|
|
let slur_regex = slur_regex(context).await?;
|
2024-03-15 11:03:29 +00:00
|
|
|
let url_blocklist = get_url_blocklist(context).await?;
|
2024-10-31 12:13:42 +00:00
|
|
|
let content = append_attachments_to_comment(content, ¬e.attachment, context).await?;
|
2025-02-20 17:47:18 +00:00
|
|
|
let content = process_markdown(&content, &slur_regex, &url_blocklist, context).await?;
|
2024-10-03 12:24:05 +00:00
|
|
|
let content = markdown_rewrite_remote_links(content, context).await;
|
2024-10-02 12:50:21 +00:00
|
|
|
let language_id = Some(
|
|
|
|
LanguageTag::to_language_id_single(note.language.unwrap_or_default(), &mut context.pool())
|
|
|
|
.await?,
|
|
|
|
);
|
2022-08-22 20:55:10 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
let form = CommentInsertForm {
|
2020-10-12 14:10:09 +00:00
|
|
|
creator_id: creator.id,
|
|
|
|
post_id: post.id,
|
2023-07-26 18:01:15 +00:00
|
|
|
content,
|
2020-10-12 14:10:09 +00:00
|
|
|
removed: None,
|
2025-01-01 17:47:21 +00:00
|
|
|
published: note.published,
|
|
|
|
updated: note.updated,
|
2022-11-03 13:39:30 +00:00
|
|
|
deleted: Some(false),
|
2021-11-06 12:37:55 +00:00
|
|
|
ap_id: Some(note.id.into()),
|
2022-08-17 11:38:52 +00:00
|
|
|
distinguished: note.distinguished,
|
2021-03-20 20:59:07 +00:00
|
|
|
local: Some(false),
|
2022-10-06 18:27:58 +00:00
|
|
|
language_id,
|
2021-07-31 14:57:37 +00:00
|
|
|
};
|
2022-07-30 03:55:59 +00:00
|
|
|
let parent_comment_path = parent_comment.map(|t| t.0.path);
|
2024-11-15 10:21:08 +00:00
|
|
|
let timestamp: DateTime<Utc> = note.updated.or(note.published).unwrap_or_else(Utc::now);
|
2024-04-10 14:03:51 +00:00
|
|
|
let comment = Comment::insert_apub(
|
|
|
|
&mut context.pool(),
|
|
|
|
Some(timestamp),
|
|
|
|
&form,
|
|
|
|
parent_comment_path.as_ref(),
|
|
|
|
)
|
|
|
|
.await?;
|
2021-10-18 21:36:44 +00:00
|
|
|
Ok(comment.into())
|
2020-10-12 14:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-21 17:25:35 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2021-10-26 10:47:26 +00:00
|
|
|
pub(crate) mod tests {
|
2021-10-29 14:54:19 +00:00
|
|
|
use super::*;
|
2022-02-17 22:04:01 +00:00
|
|
|
use crate::{
|
|
|
|
objects::{
|
|
|
|
community::{tests::parse_lemmy_community, ApubCommunity},
|
|
|
|
instance::ApubSite,
|
|
|
|
person::{tests::parse_lemmy_person, ApubPerson},
|
|
|
|
post::ApubPost,
|
|
|
|
},
|
|
|
|
protocol::tests::file_to_json_object,
|
2021-10-21 17:25:35 +00:00
|
|
|
};
|
2021-10-29 14:54:19 +00:00
|
|
|
use assert_json_diff::assert_json_include;
|
2022-03-24 16:33:42 +00:00
|
|
|
use html2md::parse_html;
|
2025-02-20 17:47:18 +00:00
|
|
|
use lemmy_db_schema::source::{local_site::LocalSite, site::Site};
|
2024-01-04 09:47:18 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2021-10-29 14:54:19 +00:00
|
|
|
use serial_test::serial;
|
2021-10-21 17:25:35 +00:00
|
|
|
|
2021-11-01 13:05:20 +00:00
|
|
|
async fn prepare_comment_test(
|
2021-10-21 17:25:35 +00:00
|
|
|
url: &Url,
|
2023-03-21 15:03:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
2023-11-17 03:51:33 +00:00
|
|
|
) -> LemmyResult<(ApubPerson, ApubCommunity, ApubPost, ApubSite)> {
|
2024-04-17 12:35:54 +00:00
|
|
|
// use separate counter so this doesn't affect tests
|
2023-03-21 15:03:05 +00:00
|
|
|
let context2 = context.reset_request_count();
|
2023-11-17 03:51:33 +00:00
|
|
|
let (person, site) = parse_lemmy_person(&context2).await?;
|
|
|
|
let community = parse_lemmy_community(&context2).await?;
|
|
|
|
let post_json = file_to_json_object("assets/lemmy/objects/page.json")?;
|
|
|
|
ApubPost::verify(&post_json, url, &context2).await?;
|
|
|
|
let post = ApubPost::from_json(post_json, &context2).await?;
|
|
|
|
Ok((person, community, post, site))
|
2021-10-21 17:25:35 +00:00
|
|
|
}
|
|
|
|
|
2023-11-17 03:51:33 +00:00
|
|
|
async fn cleanup(
|
2024-10-31 12:12:24 +00:00
|
|
|
(person, community, post, site): (ApubPerson, ApubCommunity, ApubPost, ApubSite),
|
2023-11-17 03:51:33 +00:00
|
|
|
context: &LemmyContext,
|
|
|
|
) -> LemmyResult<()> {
|
2024-10-31 12:12:24 +00:00
|
|
|
Post::delete(&mut context.pool(), post.id).await?;
|
|
|
|
Community::delete(&mut context.pool(), community.id).await?;
|
|
|
|
Person::delete(&mut context.pool(), person.id).await?;
|
|
|
|
Site::delete(&mut context.pool(), site.id).await?;
|
2023-11-17 03:51:33 +00:00
|
|
|
LocalSite::delete(&mut context.pool()).await?;
|
|
|
|
Ok(())
|
2021-10-21 17:25:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-26 08:24:11 +00:00
|
|
|
#[tokio::test]
|
2021-10-21 17:25:35 +00:00
|
|
|
#[serial]
|
2023-11-17 03:51:33 +00:00
|
|
|
pub(crate) async fn test_parse_lemmy_comment() -> LemmyResult<()> {
|
2024-01-25 14:22:11 +00:00
|
|
|
let context = LemmyContext::init_test_context().await;
|
2023-11-17 03:51:33 +00:00
|
|
|
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
|
|
|
|
let data = prepare_comment_test(&url, &context).await?;
|
2021-10-21 17:25:35 +00:00
|
|
|
|
2024-12-02 10:28:23 +00:00
|
|
|
let json: Note = file_to_json_object("assets/lemmy/objects/comment.json")?;
|
2023-11-17 03:51:33 +00:00
|
|
|
ApubComment::verify(&json, &url, &context).await?;
|
|
|
|
let comment = ApubComment::from_json(json.clone(), &context).await?;
|
2021-10-21 17:25:35 +00:00
|
|
|
|
2021-11-05 00:24:10 +00:00
|
|
|
assert_eq!(comment.ap_id, url.into());
|
2021-10-22 16:21:26 +00:00
|
|
|
assert_eq!(comment.content.len(), 14);
|
2021-10-21 17:25:35 +00:00
|
|
|
assert!(!comment.local);
|
2023-03-21 15:03:05 +00:00
|
|
|
assert_eq!(context.request_count(), 0);
|
2021-10-21 17:25:35 +00:00
|
|
|
|
2021-11-06 12:37:55 +00:00
|
|
|
let comment_id = comment.id;
|
2023-11-17 03:51:33 +00:00
|
|
|
let to_apub = comment.into_json(&context).await?;
|
2021-10-21 17:25:35 +00:00
|
|
|
assert_json_include!(actual: json, expected: to_apub);
|
|
|
|
|
2023-11-17 03:51:33 +00:00
|
|
|
Comment::delete(&mut context.pool(), comment_id).await?;
|
|
|
|
cleanup(data, &context).await?;
|
|
|
|
Ok(())
|
2021-10-21 17:25:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-26 08:24:11 +00:00
|
|
|
#[tokio::test]
|
2021-10-21 17:25:35 +00:00
|
|
|
#[serial]
|
2023-11-17 03:51:33 +00:00
|
|
|
async fn test_parse_pleroma_comment() -> LemmyResult<()> {
|
2024-01-25 14:22:11 +00:00
|
|
|
let context = LemmyContext::init_test_context().await;
|
2023-11-17 03:51:33 +00:00
|
|
|
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
|
|
|
|
let data = prepare_comment_test(&url, &context).await?;
|
2021-10-21 17:25:35 +00:00
|
|
|
|
|
|
|
let pleroma_url =
|
2023-11-17 03:51:33 +00:00
|
|
|
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")?;
|
|
|
|
let person_json = file_to_json_object("assets/pleroma/objects/person.json")?;
|
|
|
|
ApubPerson::verify(&person_json, &pleroma_url, &context).await?;
|
|
|
|
ApubPerson::from_json(person_json, &context).await?;
|
|
|
|
let json = file_to_json_object("assets/pleroma/objects/note.json")?;
|
|
|
|
ApubComment::verify(&json, &pleroma_url, &context).await?;
|
|
|
|
let comment = ApubComment::from_json(json, &context).await?;
|
2021-10-21 17:25:35 +00:00
|
|
|
|
2021-11-05 00:24:10 +00:00
|
|
|
assert_eq!(comment.ap_id, pleroma_url.into());
|
2024-10-03 12:24:05 +00:00
|
|
|
assert_eq!(comment.content.len(), 10);
|
2021-10-21 17:25:35 +00:00
|
|
|
assert!(!comment.local);
|
2023-03-21 15:03:05 +00:00
|
|
|
assert_eq!(context.request_count(), 1);
|
2021-10-21 17:25:35 +00:00
|
|
|
|
2023-11-17 03:51:33 +00:00
|
|
|
Comment::delete(&mut context.pool(), comment.id).await?;
|
|
|
|
cleanup(data, &context).await?;
|
|
|
|
Ok(())
|
2021-10-21 17:25:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-26 08:24:11 +00:00
|
|
|
#[tokio::test]
|
2021-10-21 17:25:35 +00:00
|
|
|
#[serial]
|
|
|
|
async fn test_html_to_markdown_sanitize() {
|
|
|
|
let parsed = parse_html("<script></script><b>hello</b>");
|
|
|
|
assert_eq!(parsed, "**hello**");
|
|
|
|
}
|
|
|
|
}
|