From 12b321d7e85b7bf7859da8083415f3ac2b959eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 10 Aug 2014 00:23:29 +0200 Subject: [PATCH] Fix race condition in combination with nodePush If a nodePush notification comes in *after* PHP fetched the new messages from database, but before the server reply is received it may delay the arrival of the new message up to a minute (where the automated timer kicks in) --- file/js/be.bastelstu.Chat.litcoffee | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index b7d13d6..724bba3 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -68,6 +68,7 @@ exposed by a function if necessary. fish: null loading = false + loadingAwaiting = false autocomplete = offset: 0 @@ -602,12 +603,18 @@ Fetch new messages from the server and pass them to `handleMessages`. The userli showError WCF.Language.get 'chat.error.onMessageLoad' complete: -> loading = false + + if loadingAwaiting + loadingAwaiting = false + do getMessages Prevent loading messages in parallel. beforeSend: -> - return false if loading - + if loading + loadingAwaiting = true + return false + loading = true Insert the given messages into the chat stream.