parent
40960fc7fd
commit
ada719faeb
|
@ -267,6 +267,7 @@ section > pre.error-log {
|
||||||
.radiostrip {
|
.radiostrip {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.radiostrip input[type=radio] {
|
.radiostrip input[type=radio] {
|
||||||
|
@ -280,8 +281,6 @@ section > pre.error-log {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
background-color: #ededed;
|
background-color: #ededed;
|
||||||
will-change: transform;
|
|
||||||
transition: transform 50ms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.radiostrip label:not(:last-of-type) {
|
.radiostrip label:not(:last-of-type) {
|
||||||
|
@ -293,7 +292,6 @@ section > pre.error-log {
|
||||||
}
|
}
|
||||||
|
|
||||||
.radiostrip input[type=radio]:checked + label {
|
.radiostrip input[type=radio]:checked + label {
|
||||||
transform: scale(.95);
|
|
||||||
background: #37d;
|
background: #37d;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
"""add three-way media policy
|
||||||
|
|
||||||
|
Revision ID: 583cdac8eba1
|
||||||
|
Revises: 7e255d4ea34d
|
||||||
|
Create Date: 2017-12-28 00:46:56.023649
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '583cdac8eba1'
|
||||||
|
down_revision = '7e255d4ea34d'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
transitional = sa.table('accounts',
|
||||||
|
sa.column('policy_keep_media'),
|
||||||
|
sa.column('old_policy_keep_media'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
ThreeWayPolicyEnum = sa.Enum('keeponly', 'deleteonly', 'none',
|
||||||
|
name='enum_3way_policy')
|
||||||
|
op.execute("""
|
||||||
|
CREATE TYPE enum_3way_policy AS ENUM ('keeponly', 'deleteonly', 'none')
|
||||||
|
""")
|
||||||
|
op.alter_column('accounts', 'policy_keep_media',
|
||||||
|
new_column_name='old_policy_keep_media')
|
||||||
|
op.add_column(
|
||||||
|
'accounts',
|
||||||
|
sa.Column('policy_keep_media', ThreeWayPolicyEnum,
|
||||||
|
nullable=False, server_default='none'))
|
||||||
|
|
||||||
|
op.execute(transitional.update()
|
||||||
|
.where(transitional.c.old_policy_keep_media)
|
||||||
|
.values(policy_keep_media=op.inline_literal('keeponly')))
|
||||||
|
|
||||||
|
op.drop_column('accounts', 'old_policy_keep_media')
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.alter_column('accounts', 'policy_keep_media',
|
||||||
|
new_column_name='old_policy_keep_media')
|
||||||
|
op.add_column(
|
||||||
|
'accounts',
|
||||||
|
sa.Column('policy_keep_media', sa.Boolean(),
|
||||||
|
nullable=False, server_default='f'))
|
||||||
|
|
||||||
|
op.execute(transitional.update()
|
||||||
|
.where(transitional.c.old_policy_keep_media == op.inline_literal('keeponly'))
|
||||||
|
.values(policy_keep_media=op.inline_literal('t')))
|
||||||
|
|
||||||
|
op.drop_column('accounts', 'old_policy_keep_media')
|
||||||
|
op.execute("""
|
||||||
|
DROP TYPE enum_3way_policy
|
||||||
|
""")
|
14
model.py
14
model.py
|
@ -67,6 +67,10 @@ class RemoteIDMixin(object):
|
||||||
self.id = "mastodon:{}@{}".format(id_, self.mastodon_instance)
|
self.id = "mastodon:{}@{}".format(id_, self.mastodon_instance)
|
||||||
|
|
||||||
|
|
||||||
|
ThreeWayPolicyEnum = db.Enum('keeponly', 'deleteonly', 'none',
|
||||||
|
name='enum_3way_policy')
|
||||||
|
|
||||||
|
|
||||||
@decompose_interval('policy_delete_every')
|
@decompose_interval('policy_delete_every')
|
||||||
@decompose_interval('policy_keep_younger')
|
@decompose_interval('policy_keep_younger')
|
||||||
class Account(TimestampMixin, RemoteIDMixin):
|
class Account(TimestampMixin, RemoteIDMixin):
|
||||||
|
@ -79,7 +83,7 @@ class Account(TimestampMixin, RemoteIDMixin):
|
||||||
nullable=False)
|
nullable=False)
|
||||||
policy_keep_favourites = db.Column(db.Boolean, server_default='TRUE',
|
policy_keep_favourites = db.Column(db.Boolean, server_default='TRUE',
|
||||||
nullable=False)
|
nullable=False)
|
||||||
policy_keep_media = db.Column(db.Boolean, server_default='FALSE',
|
policy_keep_media = db.Column(ThreeWayPolicyEnum, server_default='none',
|
||||||
nullable=False)
|
nullable=False)
|
||||||
policy_delete_every = db.Column(db.Interval, server_default='30 minutes',
|
policy_delete_every = db.Column(db.Interval, server_default='30 minutes',
|
||||||
nullable=False)
|
nullable=False)
|
||||||
|
@ -174,9 +178,11 @@ class Account(TimestampMixin, RemoteIDMixin):
|
||||||
db.func.now() - self.policy_keep_younger)
|
db.func.now() - self.policy_keep_younger)
|
||||||
.except_(latest_n_posts))
|
.except_(latest_n_posts))
|
||||||
if(self.policy_keep_favourites):
|
if(self.policy_keep_favourites):
|
||||||
query = query.filter(db.or_(Post.favourite == False, Post.is_reblog))
|
query = query.filter(db.or_(~Post.favourite, Post.is_reblog))
|
||||||
if(self.policy_keep_media):
|
if(self.policy_keep_media != 'none'):
|
||||||
query = query.filter(db.or_(Post.has_media == False, Post.is_reblog))
|
query = query.filter(db.or_(
|
||||||
|
Post.has_media == (self.policy_keep_media == 'deleteonly'),
|
||||||
|
Post.is_reblog))
|
||||||
if(self.policy_keep_direct):
|
if(self.policy_keep_direct):
|
||||||
query = query.filter(~Post.direct)
|
query = query.filter(~Post.direct)
|
||||||
return query.count()
|
return query.count()
|
||||||
|
|
28
tasks.py
28
tasks.py
|
@ -170,26 +170,30 @@ def delete_from_account(account_id):
|
||||||
|
|
||||||
to_delete = None
|
to_delete = None
|
||||||
|
|
||||||
|
def is_eligible(post):
|
||||||
|
return (
|
||||||
|
post.is_reblog or
|
||||||
|
(
|
||||||
|
(
|
||||||
|
not account.policy_keep_favourites or not post.favourite
|
||||||
|
) and (
|
||||||
|
account.policy_keep_media == 'none' or
|
||||||
|
(account.policy_keep_media == 'keeponly' and not post.has_media) or
|
||||||
|
(account.policy_keep_media == 'deleteonly' and post.has_media)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
action = noop
|
action = noop
|
||||||
if account.service == 'twitter':
|
if account.service == 'twitter':
|
||||||
action = libforget.twitter.delete
|
action = libforget.twitter.delete
|
||||||
posts = refresh_posts(posts)
|
posts = refresh_posts(posts)
|
||||||
if posts:
|
to_delete = next(filter(is_eligible, posts), None)
|
||||||
eligible = list(( # nosec
|
|
||||||
post for post in posts if
|
|
||||||
(not account.policy_keep_favourites or not post.favourite or post.is_reblog)
|
|
||||||
and (not account.policy_keep_media or not post.has_media or post.is_reblog)
|
|
||||||
))
|
|
||||||
if eligible:
|
|
||||||
to_delete = random.choice(eligible)
|
|
||||||
elif account.service == 'mastodon':
|
elif account.service == 'mastodon':
|
||||||
action = libforget.mastodon.delete
|
action = libforget.mastodon.delete
|
||||||
for post in posts:
|
for post in posts:
|
||||||
refreshed = refresh_posts((post,))
|
refreshed = refresh_posts((post,))
|
||||||
if refreshed and \
|
if refreshed and is_eligible(refreshed[0]):
|
||||||
(not account.policy_keep_favourites or not post.favourite or post.is_reblog) \
|
|
||||||
and (not account.policy_keep_media or not post.has_media or post.is_reblog)\
|
|
||||||
and (not account.policy_keep_direct or not post.direct):
|
|
||||||
to_delete = refreshed[0]
|
to_delete = refreshed[0]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -78,12 +78,14 @@
|
||||||
<label for=policy_keep_favourites_false>No</label>
|
<label for=policy_keep_favourites_false>No</label>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p>Keep posts that have media attached
|
<p>Keep posts
|
||||||
<span class="radiostrip">
|
<span class="radiostrip">
|
||||||
<input type=radio name=policy_keep_media value=true id=policy_keep_media_true {{ "checked" if g.viewer.account.policy_keep_media }}>
|
<input type=radio name=policy_keep_media value=keeponly id=policy_keep_media_keeponly {{ "checked" if g.viewer.account.policy_keep_media == 'keeponly' }}>
|
||||||
<label for=policy_keep_media_true>Yes</label>
|
<label for=policy_keep_media_keeponly>with media attached</label>
|
||||||
<input type=radio name=policy_keep_media value=false id=policy_keep_media_false {{ "checked" if not g.viewer.account.policy_keep_media }}>
|
<input type=radio name=policy_keep_media value=deleteonly id=policy_keep_media_deleteonly {{ "checked" if g.viewer.account.policy_keep_media == 'deleteonly' }}>
|
||||||
<label for=policy_keep_media_false>No</label>
|
<label for=policy_keep_media_deleteonly>with no media attached</label>
|
||||||
|
<input type=radio name=policy_keep_media value=none id=policy_keep_media_none {{ "checked" if g.viewer.account.policy_keep_media == 'none' }}>
|
||||||
|
<label for=policy_keep_media_none>neither</label>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
{% if g.viewer.account.service == 'mastodon' %}
|
{% if g.viewer.account.service == 'mastodon' %}
|
||||||
|
|
Loading…
Reference in New Issue