diff --git a/migrations/versions/abcdef012345_conditional_posting_with_faves.py b/migrations/versions/abcdef012345_conditional_posting_with_faves.py new file mode 100644 index 0000000..a324299 --- /dev/null +++ b/migrations/versions/abcdef012345_conditional_posting_with_faves.py @@ -0,0 +1,29 @@ +"""empty message + +Revision ID: abcdef012345 +Revises: 52a6ff8551e1 +Create Date: 2019-03-10 20:44:12.345678 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'abcdef012345' +down_revision = '52a6ff8551e1' +branch_labels = None +depends_on = None + + +def upgrade(): + ## Rename existing conditional_posting column for clarity. + # op.alter_column('settings', 'conditional_posting', new_column_name='conditional_posting_hashtags') + op.add_column('settings', sa.Column('conditional_posting_faves', sa.Boolean(), nullable=False)) + + +def downgrade(): + ## Should be dropped in dc37a95190f6, provided it's correctly renamed back. + # op.alter_column('settings', 'conditional_posting_hashtags', new_column_name='conditional_posting') + op.drop_column('settings', 'conditional_posting_faves') + \ No newline at end of file diff --git a/moa/forms.py b/moa/forms.py index e6acd41..5c503ff 100644 --- a/moa/forms.py +++ b/moa/forms.py @@ -6,6 +6,7 @@ class SettingsForm(FlaskForm): enabled = BooleanField('Bridging Enabled?') conditional_posting = BooleanField('Conditionally cross-post with hashtags #nt and #nm?') + conditional_posting_faves = BooleanField('Conditionally cross-post by marking your posts as faves?') post_to_twitter = BooleanField('Post Public toots to Twitter?') post_private_to_twitter = BooleanField('Post Private toots to Twitter?') diff --git a/moa/models.py b/moa/models.py index 1221cb3..16a0377 100644 --- a/moa/models.py +++ b/moa/models.py @@ -51,6 +51,7 @@ class TSettings(Base): id = Column(Integer, primary_key=True) bridge = relationship('Bridge', backref='t_settings', lazy='dynamic') conditional_posting = Column(Boolean, nullable=False, default=False) + conditional_posting_faves = Column(Boolean, nullable=False, default=False) # Masto -> Twitter post_to_twitter = Column(Boolean, nullable=False, default=True) # This means post public toots diff --git a/moa/toot.py b/moa/toot.py index 42c7b7b..b9b8d12 100644 --- a/moa/toot.py +++ b/moa/toot.py @@ -77,6 +77,10 @@ def is_reply(self): def is_self_reply(self): return self.is_reply and self.data['in_reply_to_account_id'] == self.data['account']['id'] + @property + def is_favourited(self): + return self.data['favourited'] + @property def is_boost(self): return self.data['reblog'] is not None @@ -146,6 +150,11 @@ def should_skip(self): # If it's a boost and boosts are allowed then post it even # if public toots aren't allowed pass + + elif self.settings.conditional_posting_faves and not self.is_favourited: + logger.info(f'Skipping: Not posting unfavourited toot') + return True + elif self.settings.conditional_posting: for ht in self.data['tags']: diff --git a/moa/tweet.py b/moa/tweet.py index f4b36be..3be6c98 100644 --- a/moa/tweet.py +++ b/moa/tweet.py @@ -98,6 +98,10 @@ def should_skip(self): # Posting retweets pass + elif self.settings.conditional_posting_faves and not self.is_favorited: + logger.info(f'Skipping: Not posting unfavorited tweet') + return True + elif self.settings.conditional_posting: for ht in self.data.hashtags: @@ -138,6 +142,10 @@ def is_retweet(self): def is_quoted(self): return self.data.quoted_status is not None + @property + def is_favorited(self): + return self.data.favorited + @property def is_reply(self): diff --git a/templates/index.html.j2 b/templates/index.html.j2 index 370f768..799510c 100644 --- a/templates/index.html.j2 +++ b/templates/index.html.j2 @@ -37,6 +37,7 @@
  • {{ form.enabled(checked=g.bridge.enabled) }}{{ form.enabled.label }}
  • {{ form.conditional_posting }}{{ form.conditional_posting.label }}
  • +
  • {{ form.conditional_posting_faves }}{{ form.conditional_posting_faves.label }}
  • {% endif %} {% if g.bridge.twitter_oauth_token and g.bridge.mastodon_access_code %}