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

WIP: Conditional posting via favourites #109

Open
wants to merge 5 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
29 changes: 29 additions & 0 deletions migrations/versions/abcdef012345_conditional_posting_with_faves.py
Original file line number Diff line number Diff line change
@@ -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')

1 change: 1 addition & 0 deletions moa/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?')
Expand Down
1 change: 1 addition & 0 deletions moa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions moa/toot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']:
Expand Down
8 changes: 8 additions & 0 deletions moa/tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):

Expand Down
1 change: 1 addition & 0 deletions templates/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<hr>
<li>{{ form.enabled(checked=g.bridge.enabled) }}{{ form.enabled.label }}</li>
<li>{{ form.conditional_posting }}{{ form.conditional_posting.label }}</li>
<li>{{ form.conditional_posting_faves }}{{ form.conditional_posting_faves.label }}</li>
{% endif %}

{% if g.bridge.twitter_oauth_token and g.bridge.mastodon_access_code %}
Expand Down