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.
master
magical 2022-08-08 01:38:20 +00:00
parent 92bdd7b660
commit 315a249ef6
1 changed files with 23 additions and 18 deletions

View File

@ -1982,6 +1982,18 @@ class ExternalEditor(urwid.Terminal):
def exterminate(self, *_, anon_confirmed=False): 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"] \ if app.prefs["confirm_anon"] \
and not anon_confirmed \ and not anon_confirmed \
and app.network.user["user_name"] == "anonymous": and app.network.user["user_name"] == "anonymous":
@ -2020,27 +2032,20 @@ class ExternalEditor(urwid.Terminal):
log_in(True) log_in(True)
app.loop.start() app.loop.start()
app.close_editor() # ok; do the post
with open(self.path) as _: self.params.update({"body": body})
body = _.read().strip() app.network.request(self.endpoint, **self.params)
os.remove(self.path) if self.endpoint == "edit_post":
app.refresh()
app.goto_post(self.params["post_id"])
if body and not re.search("^>>[0-9]+$", body): elif app.mode == "thread":
self.params.update({"body": body}) app.refresh()
app.network.request(self.endpoint, **self.params) app.goto_post(app.thread["reply_count"])
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"])
else:
app.last_pos = None
app.index()
else: else:
app.temp_footer_message("EMPTY POST DISCARDED") app.last_pos = None
app.index()
def keypress(self, size, key): def keypress(self, size, key):