From 884853b99789b194aba6cb7425d71c75b99920a0 Mon Sep 17 00:00:00 2001 From: 9Lukas5 Date: Sun, 16 Apr 2023 14:34:56 +0200 Subject: [PATCH 1/2] feat(sync): decide on mastodon visibility if toot is synced --- src/sync.rs | 9 ++++++--- src/thread_replies.rs | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/sync.rs b/src/sync.rs index 1b2aedf..f5d457e 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -3,6 +3,7 @@ use anyhow::Result; use egg_mode::tweet::Tweet; use egg_mode_text::character_count; use elefren::entities::status::Status; +use elefren::status_builder::Visibility; use regex::Regex; use std::collections::HashSet; use std::fs; @@ -134,9 +135,11 @@ pub fn determine_posts( None => tweet_shorten(&fulltext, &toot.url), Some(reblog) => tweet_shorten(&fulltext, &reblog.url), }; - // Skip direct toots to other Mastodon users, even if they are public. - if post.starts_with('@') { - continue; + + // ignore toots that are not public or unlisted + match toot.visibility { + Visibility::Public | Visibility::Unlisted => (), + _ => continue, } for tweet in twitter_statuses { diff --git a/src/thread_replies.rs b/src/thread_replies.rs index c3529f5..76e7b48 100644 --- a/src/thread_replies.rs +++ b/src/thread_replies.rs @@ -1,6 +1,7 @@ use crate::sync::*; use egg_mode::tweet::Tweet; use elefren::entities::status::Status; +use elefren::status_builder::Visibility; // A reply to a post that has the ID to the parent post. #[derive(Debug)] @@ -82,6 +83,12 @@ pub fn determine_thread_replies( continue; } + // ignore toots that are not public or unlisted + match toot.visibility { + Visibility::Public | Visibility::Unlisted => (), + _ => continue, + } + for tweet in twitter_statuses { // If the toot already exists we can stop here and know that we are // synced. From 0d28a0a047a7669cf6bc9b401a05e0f6af09d681 Mon Sep 17 00:00:00 2001 From: 9Lukas5 Date: Sun, 16 Apr 2023 14:35:04 +0200 Subject: [PATCH 2/2] chore(sync): add tests for visibility logic --- src/sync.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/sync.rs b/src/sync.rs index f5d457e..70cd769 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -793,15 +793,51 @@ UNLISTED 🔓 ✅ Tagged people assert!(posts.tweets.is_empty()); } - // Test that direct toots starting with "@" are not copied to twitter. + // Test that direct toots are not copied to twitter. #[test] fn direct_toot() { + let mut status = get_mastodon_status(); + status.content = "Test Hello! http://example.com".to_string(); + status.visibility = Visibility::Direct; + let tweets = Vec::new(); + let statuses = vec![status]; + let posts = determine_posts(&statuses, &tweets, &DEFAULT_SYNC_OPTIONS); + assert!(posts.tweets.is_empty()); + } + + // test that public toots are synced + #[test] + fn public_toot() { let mut status = get_mastodon_status(); status.content = "@Test Hello! http://example.com".to_string(); + status.visibility = Visibility::Public; + let tweets = Vec::new(); + let statuses = vec![status]; + let posts = determine_posts(&statuses, &tweets, &DEFAULT_SYNC_OPTIONS); + assert_eq!(posts.tweets.len(), 1); + } + + // test that unlisted toots are synced + #[test] + fn unlisted_toot() { + let mut status = get_mastodon_status(); + status.content = "Test Hello! http://example.com".to_string(); + status.visibility = Visibility::Unlisted; + let tweets = Vec::new(); + let statuses = vec![status]; + let posts = determine_posts(&statuses, &tweets, &DEFAULT_SYNC_OPTIONS); + assert_eq!(posts.tweets.len(), 1); + } + + // test that private toots are NOT synced + #[test] + fn private_toot() { + let mut status = get_mastodon_status(); + status.content = "Test Hello! http://example.com".to_string(); + status.visibility = Visibility::Private; let tweets = Vec::new(); let statuses = vec![status]; let posts = determine_posts(&statuses, &tweets, &DEFAULT_SYNC_OPTIONS); - assert!(posts.toots.is_empty()); assert!(posts.tweets.is_empty()); }