diff --git a/README.md b/README.md index c463ab0..ebf4fbf 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,6 @@ Todo list for the future, not implemented yet: - Build portable binaries on Github without OpenSSL dependencies - Add open graph link preview when posting to Bluesky - Parallel execution of fetching and syncing requests at the same time -- Remove username escaping with backslash from Bluesky, not needed ## Acknowledgements diff --git a/src/sync.rs b/src/sync.rs index b65af58..2cace09 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -229,9 +229,7 @@ fn unify_post_content(content: String) -> String { result = result.replace("http://", ""); result = result.replace("https://", ""); - // Escape direct user mentions with \@. - result = result.replace(" \\@", " @"); - result.replace(" @\\", " @") + result } // Extend URLs and HTML entity decode &. @@ -400,9 +398,6 @@ pub fn mastodon_toot_get_text(toot: &Status) -> String { replaced = voca_rs::strip::strip_tags(&replaced); - // Escape direct user mentions with @\. - replaced = replaced.replace(" @", " @\\").replace(" @\\\\", " @\\"); - html_escape::decode_html_entities(&replaced).to_string() } @@ -718,6 +713,18 @@ https://github.com/klausi/mastodon-bluesky-sync/releases/tag/v0.2.0" https://www.derstandard.at/story/3000000250190/der-fall-pelicot-unfassbar-monstroes?ref=article"); } + // Test that a user mention on mastodon is posted as is to Bluesky. We don't + // need to escape it. + #[test] + fn mastodon_user_mention() { + let post = read_mastodon_post_from_json("tests/mastodon_mention.json"); + let posts = determine_posts(&vec![post], &Vec::new(), &SyncOptions::default()); + assert_eq!( + posts.bsky_posts[0].text, + "Finally watched #RebelRidge recommended by @mekkaokereke a while ago... Good stuff! 🎬" + ); + } + // Read static bluesky post from test file. fn read_bsky_post_from_json(file_name: &str) -> Object { let json = fs::read_to_string(file_name).unwrap(); diff --git a/tests/mastodon_mention.json b/tests/mastodon_mention.json new file mode 100644 index 0000000..359a97e --- /dev/null +++ b/tests/mastodon_mention.json @@ -0,0 +1,85 @@ +{ + "id": "113693143551648776", + "uri": "https://mastodon.social/users/klausi/statuses/113693143551648776", + "url": "https://mastodon.social/@klausi/113693143551648776", + "account": { + "id": "28407", + "username": "klausi", + "acct": "klausi", + "display_name": "klausi", + "locked": false, + "discoverable": true, + "group": false, + "noindex": true, + "moved": null, + "suspended": null, + "limited": null, + "created_at": "2017-04-01T00:00:00Z", + "followers_count": 530, + "following_count": 1026, + "statuses_count": 126, + "note": "

💻 Software Engineer

🌍 Location: Vienna, Austria #WienLiebe
🏷️ Identity: upper middle class, 80% male, white, 80% straight, cis, dya
💼 Work: Jobiqo, #Drupal, #PHP, #D7Security
🎓 Education: Computer Science, soft skill focus on Gender Studies
💡 Interests: tech, politics, infosec, #rustlang, ethics, social justice
🚩🏴 Politics: somewhere on the left, drawing from anarchism, communism, liberalism
🗣️ Languages: German, English
🏳️‍🌈 Pronouns: He/him or they/them
🏳️‍⚧️ Support: trans and nonbinary people

", + "url": "https://mastodon.social/@klausi", + "avatar": "https://files.mastodon.social/accounts/avatars/000/028/407/original/638b002381039f45.png", + "avatar_static": "https://files.mastodon.social/accounts/avatars/000/028/407/original/638b002381039f45.png", + "header": "https://files.mastodon.social/accounts/headers/000/028/407/original/AUK6UYSC52D9.png", + "header_static": "https://files.mastodon.social/accounts/headers/000/028/407/original/AUK6UYSC52D9.png", + "emojis": [], + "fields": [ + { + "name": "Blog", + "value": "https://klau.si", + "verified_at": "2019-11-23T23:49:42.885Z", + "verified": null + } + ], + "bot": false, + "source": null, + "role": null, + "mute_expires_at": null + }, + "in_reply_to_id": null, + "in_reply_to_account_id": null, + "reblog": null, + "content": "

Finally watched #RebelRidge recommended by @mekkaokereke a while ago... Good stuff! 🎬

", + "plain_content": null, + "created_at": "2024-12-21T22:21:35.323Z", + "edited_at": "2024-12-22T06:53:41.848Z", + "emojis": [], + "replies_count": 0, + "reblogs_count": 0, + "favourites_count": 1, + "reblogged": false, + "favourited": false, + "muted": false, + "sensitive": false, + "spoiler_text": "", + "visibility": "public", + "media_attachments": [], + "mentions": [ + { + "id": "109387287658543773", + "username": "mekkaokereke", + "url": "https://hachyderm.io/@mekkaokereke", + "acct": "mekkaokereke@hachyderm.io" + } + ], + "tags": [ + { + "name": "rebelridge", + "url": "https://mastodon.social/tags/rebelridge" + } + ], + "card": null, + "poll": null, + "application": { + "name": "Mastodon for Android", + "website": "https://app.joinmastodon.org/android", + "vapid_key": null + }, + "language": "en", + "pinned": false, + "emoji_reactions": null, + "quote": false, + "bookmarked": false +} \ No newline at end of file