From db7540b111f8b9f983adcfc73fd897e5d83c2fef Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Wed, 8 Mar 2017 04:13:16 -0500
Subject: Add sync logic for DMs/GMs when network reconnects (#5676)

---
 webapp/actions/websocket_actions.jsx | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'webapp/actions/websocket_actions.jsx')

diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx
index 913a89221..e36d11fde 100644
--- a/webapp/actions/websocket_actions.jsx
+++ b/webapp/actions/websocket_actions.jsx
@@ -89,6 +89,26 @@ export function reconnect(includeWebSocket = true) {
     ErrorStore.emitChange();
 }
 
+let intervalId = '';
+const SYNC_INTERVAL_MILLISECONDS = 1000 * 60 * 15; // 15 minutes
+
+export function startPeriodicSync() {
+    clearInterval(intervalId);
+
+    intervalId = setInterval(
+        () => {
+            if (UserStore.getCurrentUser() != null) {
+                reconnect(false);
+            }
+        },
+        SYNC_INTERVAL_MILLISECONDS
+    );
+}
+
+export function stopPeriodicSync() {
+    clearInterval(intervalId);
+}
+
 function handleFirstConnect() {
     ErrorStore.clearLastError();
     ErrorStore.emitChange();
-- 
cgit v1.2.3-1-g7c22

