Improvement to drafts (and posting, actually) I need to do

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Improvement to drafts (and posting, actually) I need to do
« on March 17th, 2012, 02:37 PM »
Something I've noticed about drafts that I didn't quite notice before is a slightly complex chain of events that needs cleaning up.

If you type something, then preview it, it does autosave the draft, and it does actually remember that draft - so if you go from quick reply-with-draft through to preview, it won't create a second draft (as it shouldn't), but you won't be able to delete that draft there and then, you'll have to wait until the post is edited and resaved automatically. (Confirmed here just now, I was able to start a post, let it autosave, preview, then noted the behaviour)

I suspect something similar occurs to PMs, too.

I still need to fix the case of editing a draft when the board no longer exists that the draft originally came from.[1]


Also: IMO, the tabindex structure on posting is a touch off, it needs to go from subject to body, not via the selectboxes. I don't think it should take 4 tabs to get from subject to body.
 1. If you have a draft for a reply, but the topic no longer exists, that's fine, it will just take you to editing as if you were creating a new topic. But if the board no longer exists, it gets very upset and dumps you at the no_board error.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Improvement to drafts (and posting, actually) I need to do
« Reply #1, on March 17th, 2012, 04:50 PM »
Hmm, there are plenty of little issues with it, but it's okay. Drafts, and the way they're implemented (also in PMs!), are one of the selling points of Wedge.
One thing I noticed, and would like to suggest, is that if Remove Draft is clicked, either reset the timeout counter, or just disable it, because it's unlikely the author really plans to post the message (may be testing something). At some point I clicked Removed Draft, and the button showed up again two seconds later... ;)

Ah, bugger, button icons are broken in IE9... :-/

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,079

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Improvement to drafts (and posting, actually) I need to do
« Reply #5, on March 18th, 2012, 01:04 PM »
So, gotta fix that PM bug.

Also, I'm thinking I should tweak the quick reply version, I'm not sure I like the way it runs the entire set of buttons into a single line (whereas the full reply screen pushes the last saved/remove button to the next line)

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Improvement to drafts (and posting, actually) I need to do
« Reply #7, on March 22nd, 2012, 01:02 PM »
Possible bug...? If yes, it's minor.

Yesterday, I tapped Quick Reply (it's collapsed by default) to answer a post.
Right after it opened the (empty) QR box, the first draft was saved.

This could mean two bugs: drafts are still saved on empty contents, and the draft timer is started even if the QR box is closed.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Improvement to drafts (and posting, actually) I need to do
« Reply #8, on March 22nd, 2012, 01:05 PM »
Let me explain how it works under the hood, that might explain the behaviour you're seeing.

There is a timer started straight away, x second intervals (where the x is the admin setting, default 30). Nothing should happen, however, unless a keydown event is sent to the editor object, which sets a flag in the drafts object to indicate that next time the timer hits its interval, to make a save. The save is sent off, on return it clears that flag.

Theoretically, then, it should never be saving until there is something to save... with a variable amount of time between you typing and the first save (0-x seconds) but ~x seconds thereafter assuming constant typing.

Nao

  • Dadman with a boy
  • Posts: 16,079

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: Improvement to drafts (and posting, actually) I need to do
« Reply #13, on March 22nd, 2012, 02:30 PM »
Yep, but there's no point in using it, we need to fix that...

- Make sure that drafts don't get saved if the same text is already in the database,
- Ensure they really don't get saved if no activity is found...
- Ensure they don't get saved *if the post is empty* (even if there's activity like keydown, Wedge still saves an empty draft for EVERY topic I'm simply reading with my iPod...!)
- Make sure that iOS generally won't screw up with drafts.
- Ensure all drafts are removed for a specific post once it's sent.

Looking at my latest drafts:

- this is found as a draft, completely the same post. Not even a partial one... Same for the Werner Herzog post.

- the current post is updated in real time, with no extra drafts being created for it, so that one is okay.

- an empty draft for a New Revs post (I never post there from my iPod), but no empty drafts for my other recent Opera posts.

- that empty draft says, "This draft is a reply to a topic that is currently locked by a moderator. Editing this draft will attempt to create a new topic." --> yeah, but I'm the admin... I can post it there if I want! Does the feature at least check against that...?

- about 1350 drafts are the same post -- a Logo Madness draft that is just a quote of another post, possibly a tab I opened somewhere with a plan to post a reply, and then 12 hours later I found the tab and just closed it. It saved a new copy of the draft every single time... :-/
Re: Improvement to drafts (and posting, actually) I need to do
« Reply #14, on March 22nd, 2012, 04:32 PM »
Okay, I've made a few changes to the draft code... Hopefully it will help, if only a bit.

- needsUpdate is set to false right after it's tested against. This is to ensure that drafts don't get saved multiple times if for some reason the function is executed again before the server has answered. (e.g. server is temporarily down...?)
- if 'message' is empty, return without doing anything. I don't think there's any good reason to save an empty draft. Really.

Will commit soon. Pete, this is your code, so feel free to revert at any time without explanations. I'm not even sure I'm doing it correctly :P