Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use mastodon visibility #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -790,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());
}

Expand Down
7 changes: 7 additions & 0 deletions src/thread_replies.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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.
Expand Down