From 6171a0572ab90e72eb3f900050448f1295f68f29 Mon Sep 17 00:00:00 2001 From: girst Date: Wed, 10 Mar 2021 16:07:03 +0100 Subject: [PATCH] add info flash when (un)pinning/(un)subscribing/etc. with undo makes it ovious what happened and allows undoing fat-fingered actions. --- app/youtube/__init__.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/youtube/__init__.py b/app/youtube/__init__.py index 18e52ce..08f4ca9 100644 --- a/app/youtube/__init__.py +++ b/app/youtube/__init__.py @@ -294,12 +294,13 @@ def subscription_manager(): def feed_post(): token = current_user.token action = next(request.form.keys(), None) - if action in ['pin', 'unpin', 'hide']: + if action in ['pin', 'unpin', 'hide', 'unhide']: video_id = request.form.get(action) display = { 'pin': 'pinned', 'unpin': None, 'hide': 'hidden', + 'unhide': None, }[action] with sqlite3.connect(cf['global']['database']) as conn: c = conn.cursor() @@ -308,6 +309,7 @@ def feed_post(): INSERT OR REPLACE INTO flags (user, video_id, display) VALUES (?, ?, ?) """, (token, video_id, display)) + undo_flash(video_id, action) else: flash("unsupported action", "error") return redirect(request.url, code=303) @@ -338,6 +340,7 @@ def manage_subscriptions(): VALUES (?, ?, ?) """, (token, some_id, id_type)) # TODO: sql-error-handling, asynchronically calling update-subs.pl + undo_flash(some_id, 'subscribe') elif 'unsubscribe' in request.form: some_id = request.form.get("unsubscribe") @@ -349,6 +352,7 @@ def manage_subscriptions(): WHERE user = ? AND channel_id = ? """, (token, some_id)) # TODO: sql-error-handling, report success + undo_flash(some_id, 'unsubscribe') else: flash("unsupported action", "error") @@ -373,6 +377,30 @@ def get_cipher(): # if db is not None: # db.close() +def undo_flash(thing_id, action): + undo_action, past_action = { + 'pin': ('unpin', 'pinned'), + 'unpin': ('pin', 'unpinned'), + 'hide': ('unhide', 'hidden'), + 'unhide': ('hide', 'unhidden'), + 'subscribe': ('unsubscribe', 'subscribed'), + 'unsubscribe': ('subscribe', 'unsubscribed'), + }.get(action) + if 'subscribe' in action and thing_id.startswith('UC'): + thing = "channel" + thing_url = url_for('.channel', channel_id=thing_id) + elif 'subscribe' in action: + thing = "playlist" + thing_url = url_for('.playlist', playlist_id=thing_id) + else: + thing = "video" + thing_url = url_for('.watch', v=thing_id) + flash(f''' +
+ {thing} {past_action}. +
''', "info") @frontend.app_template_filter('format_date') def format_date(s): -- 2.39.3