mirror of
https://github.com/discourse/discourse.git
synced 2025-03-01 16:59:22 +00:00
DEV: long poll for 20 extra minutes when user stops interacting
We have no way of detecting if a browser window is behind another window or off screen on a virtual desktop. In some cases we may want events to be delivered quicker to the browser. Specifically a user may still have a window in view but is not interacting. This gives users 20 minutes of extra "long polling time" prior to shifting to short polling.
This commit is contained in:
parent
257f59f366
commit
bed3f7f69a
@ -2,6 +2,8 @@
|
|||||||
import userPresent from "discourse/lib/user-presence";
|
import userPresent from "discourse/lib/user-presence";
|
||||||
import { handleLogoff } from "discourse/lib/ajax";
|
import { handleLogoff } from "discourse/lib/ajax";
|
||||||
|
|
||||||
|
const LONG_POLL_AFTER_UNSEEN_TIME = 1200000; // 20 minutes
|
||||||
|
|
||||||
function ajax(opts) {
|
function ajax(opts) {
|
||||||
if (opts.complete) {
|
if (opts.complete) {
|
||||||
const oldComplete = opts.complete;
|
const oldComplete = opts.complete;
|
||||||
@ -31,7 +33,8 @@ export default {
|
|||||||
siteSettings = container.lookup("site-settings:main");
|
siteSettings = container.lookup("site-settings:main");
|
||||||
|
|
||||||
messageBus.alwaysLongPoll = Discourse.Environment === "development";
|
messageBus.alwaysLongPoll = Discourse.Environment === "development";
|
||||||
messageBus.shouldLongPollCallback = userPresent;
|
messageBus.shouldLongPollCallback = () =>
|
||||||
|
userPresent(LONG_POLL_AFTER_UNSEEN_TIME);
|
||||||
|
|
||||||
// we do not want to start anything till document is complete
|
// we do not want to start anything till document is complete
|
||||||
messageBus.stop();
|
messageBus.stop();
|
||||||
|
@ -10,10 +10,11 @@ const MAX_UNSEEN_TIME = 60000;
|
|||||||
|
|
||||||
let seenUserTime = Date.now();
|
let seenUserTime = Date.now();
|
||||||
|
|
||||||
export default function() {
|
export default function(maxUnseenTime) {
|
||||||
|
maxUnseenTime = maxUnseenTime === undefined ? MAX_UNSEEN_TIME : maxUnseenTime;
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
if (seenUserTime + MAX_UNSEEN_TIME < now) {
|
if (seenUserTime + maxUnseenTime < now) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user