From 315a249ef6c730105ab408510e09e8e6e0b18c44 Mon Sep 17 00:00:00 2001 From: magical Date: Mon, 8 Aug 2022 01:38:20 +0000 Subject: [PATCH] check for empty post before asking for confirmation before this change, BBJ would give the big "You are posting anonymously!" warning even if the post body was empty (say, because you accidentally started a post and closed the editor immediately). only after confirming that you _really_ wanted to post anonymously would it notice that, hey, the post body is empty and discard the post. it makes more sense to do the checks the other way around. --- clients/urwid/main.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/clients/urwid/main.py b/clients/urwid/main.py index 85077f9..e9c6e59 100644 --- a/clients/urwid/main.py +++ b/clients/urwid/main.py @@ -1982,6 +1982,18 @@ class ExternalEditor(urwid.Terminal): def exterminate(self, *_, anon_confirmed=False): + # close the editor and grab the post body + app.close_editor() + with open(self.path) as _: + body = _.read().strip() + os.remove(self.path) + + # make sure its not empty + if not body or re.search("^>>[0-9]+$", body): + app.temp_footer_message("EMPTY POST DISCARDED") + return + + # are we anonymous? check if the user wants to log in first if app.prefs["confirm_anon"] \ and not anon_confirmed \ and app.network.user["user_name"] == "anonymous": @@ -2020,27 +2032,20 @@ class ExternalEditor(urwid.Terminal): log_in(True) app.loop.start() - app.close_editor() - with open(self.path) as _: - body = _.read().strip() - os.remove(self.path) + # ok; do the post + self.params.update({"body": body}) + app.network.request(self.endpoint, **self.params) + if self.endpoint == "edit_post": + app.refresh() + app.goto_post(self.params["post_id"]) - if body and not re.search("^>>[0-9]+$", body): - self.params.update({"body": body}) - app.network.request(self.endpoint, **self.params) - if self.endpoint == "edit_post": - app.refresh() - app.goto_post(self.params["post_id"]) + elif app.mode == "thread": + app.refresh() + app.goto_post(app.thread["reply_count"]) - elif app.mode == "thread": - app.refresh() - app.goto_post(app.thread["reply_count"]) - - else: - app.last_pos = None - app.index() else: - app.temp_footer_message("EMPTY POST DISCARDED") + app.last_pos = None + app.index() def keypress(self, size, key):