cyclestreets / cyclescape

Cyclescape - cycle campaign group toolkit
https://www.cyclescape.org/
MIT License
33 stars 15 forks source link

Thread page should do AJAX checks for other postings coming in #906

Open mvl22 opened 4 years ago

mvl22 commented 4 years ago

If you are on a page, writing a post, and another message comes in, you don't know about it.

The page should do AJAX requests to check for new posts, and push them into the page, with a flash. The browser will probably auto scroll.

I imagine this could use a similar mechanism to the AJAX loading of a message just posted.

nikolai-b commented 4 years ago

So you'd like the thread page to poll for new messages? I'm a bit afraid this might spam us. I would prefer to use websockets but that is probably over-engineering. Is polling once every 30s enough, slowing to once every 2 mins or so after the page has been open for over 10 mins, with polling stopping if the user changes tab?

mvl22 commented 4 years ago

So you'd like the thread page to poll for new messages? I'm a bit afraid this might spam us. I would prefer to use websockets but that is probably over-engineering. Is polling once every 30s enough, slowing to once every 2 mins or so after the page has been open for over 10 mins,

Yes, that would easily be enough.

Websockets definitely feels like over-engineering, and in general I'm not a fan of that stuff. A simple AJAX call should be sufficient.

with polling stopping if the user changes tab?

But it should return if the user puts the tab active again.

I see there is a Page Visibility API which is well-supported: https://www.html5rocks.com/en/tutorials/pagevisibility/intro/ https://caniuse.com/#feat=pagevisibility

I think the logic is:

  1. Trigger the checking routine every 30s, slowing to once every 2 mins or so after the page has been open for over 10 mins.
  2. For the check, first ensure there is visibility.
  3. If so, make the AJAX call.