From 6e7b912ec61a6a791e0e8405ff6f6bd7e622a187 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Tue, 6 Jun 2017 17:24:08 -0400
Subject: PLT-4257 Add pop-up asking if user wants to reset status (#6526)

* Add pop-up asking if user wants to reset status

* Update test snapshot

* Update prop name for old uses of confirm modal

* Updating checkbox (#6586)

* Updating style for checkbox (#6596)
---
 webapp/actions/user_actions.jsx | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

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

diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx
index 606dccdb8..63c716d5d 100644
--- a/webapp/actions/user_actions.jsx
+++ b/webapp/actions/user_actions.jsx
@@ -26,6 +26,7 @@ const dispatch = store.dispatch;
 const getState = store.getState;
 
 import * as Selectors from 'mattermost-redux/selectors/entities/users';
+import {getBool} from 'mattermost-redux/selectors/entities/preferences';
 
 import {
     getProfiles,
@@ -43,12 +44,15 @@ import {
     createUser,
     login,
     loadMe as loadMeRedux,
-    updateUserRoles as updateUserRolesRedux
+    updateUserRoles as updateUserRolesRedux,
+    getStatus,
+    setStatus
 } from 'mattermost-redux/actions/users';
 
 import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/general';
 import {getTeamMembersByIds, getMyTeamMembers} from 'mattermost-redux/actions/teams';
 import {getChannelAndMyMember} from 'mattermost-redux/actions/channels';
+import {Preferences as PreferencesRedux} from 'mattermost-redux/constants';
 
 export function loadMe(callback) {
     loadMeRedux()(dispatch, getState).then(
@@ -831,3 +835,23 @@ export function loadMyTeamMembers() {
         }
     );
 }
+
+export function autoResetStatus() {
+    return async (doDispatch, doGetState) => {
+        const {currentUserId} = getState().entities.users;
+        const userStatus = await getStatus(currentUserId)(doDispatch, doGetState);
+
+        if (!userStatus.manual) {
+            return userStatus;
+        }
+
+        const autoReset = getBool(getState(), PreferencesRedux.CATEGORY_AUTO_RESET_MANUAL_STATUS, currentUserId, false);
+
+        if (autoReset) {
+            setStatus({user_id: currentUserId, status: 'online'})(doDispatch, doGetState);
+            return userStatus;
+        }
+
+        return userStatus;
+    };
+}
-- 
cgit v1.2.3-1-g7c22

