diff --git a/app/actions/remote/user.ts b/app/actions/remote/user.ts index 5a6817ed17..1a30111d3c 100644 --- a/app/actions/remote/user.ts +++ b/app/actions/remote/user.ts @@ -464,7 +464,7 @@ export const setStatus = async (serverUrl: string, status: UserStatus) => { } }; -export const setCustomStatus = async (serverUrl: string, user: UserModel, customStatus: UserCustomStatus) => { +export const updateCustomStatus = async (serverUrl: string, user: UserModel, customStatus: UserCustomStatus) => { let client: Client; try { client = NetworkManager.getClient(serverUrl); @@ -481,12 +481,11 @@ export const setCustomStatus = async (serverUrl: string, user: UserModel, custom try { await client.updateCustomStatus(customStatus); + return {data: true}; } catch (error) { user.props.customStatus = oldCustomStatus; return {error}; } - - return {data: true}; }; export const removeRecentCustomStatus = async (serverUrl: string, customStatus: UserCustomStatus) => { diff --git a/app/client/rest/users.ts b/app/client/rest/users.ts index 6c0eb1fa2e..6efbb23836 100644 --- a/app/client/rest/users.ts +++ b/app/client/rest/users.ts @@ -384,24 +384,24 @@ const ClientUsers = (superclass: any) => class extends superclass { ); }; - updateCustomStatus = (customStatus: UserCustomStatus) => { + updateCustomStatus = async (customStatus: UserCustomStatus) => { return this.doFetch( `${this.getUserRoute('me')}/status/custom`, - {method: 'put', body: JSON.stringify(customStatus)}, + {method: 'put', body: customStatus}, ); }; - unsetCustomStatus = () => { + unsetCustomStatus = async () => { return this.doFetch( `${this.getUserRoute('me')}/status/custom`, {method: 'delete'}, ); }; - removeRecentCustomStatus = (customStatus: UserCustomStatus) => { + removeRecentCustomStatus = async (customStatus: UserCustomStatus) => { return this.doFetch( `${this.getUserRoute('me')}/status/custom/recent/delete`, - {method: 'post', body: JSON.stringify(customStatus)}, + {method: 'post', body: customStatus}, ); }; }; diff --git a/app/screens/home/account/components/custom_status/index.tsx b/app/screens/home/account/components/custom_status/index.tsx index b1fb1b3f72..8d98954e43 100644 --- a/app/screens/home/account/components/custom_status/index.tsx +++ b/app/screens/home/account/components/custom_status/index.tsx @@ -10,7 +10,7 @@ import {Screens} from '@constants'; import {useServerUrl} from '@context/server_url'; import {useTheme} from '@context/theme'; import {showModal} from '@screens/navigation'; -import {isCustomStatusExpirySupported as checkCustomStatusExpiry, isMinimumServerVersion} from '@utils/helpers'; +import {isCustomStatusExpirySupported as checkCustomStatusExpiry, isMinimumServerVersion, safeParseJSON} from '@utils/helpers'; import {getUserCustomStatus, isCustomStatusExpired as checkCustomStatusIsExpired, updateUserCustomStatus} from '@utils/user'; import CustomLabel from './custom_label'; @@ -30,16 +30,14 @@ const CustomStatus = ({config, currentUser, database}: CustomStatusProps) => { const intl = useIntl(); const serverUrl = useServerUrl(); - const cst = getUserCustomStatus(currentUser); - const hasCST = cst && Object.keys(cst!).length > 0; - + const customStatus = safeParseJSON(getUserCustomStatus(currentUser) as string) as UserCustomStatus; + const hasCST = customStatus && Object.keys(customStatus!).length > 0; const [showStatus, setShowStatus] = useState(hasCST ?? false); const [showRetryMessage, setShowRetryMessage] = useState(false); const isCustomStatusEnabled = config.EnableCustomUserStatuses === 'true' && isMinimumServerVersion(config.Version, 5, 36); const isCustomStatusExpirySupported = checkCustomStatusExpiry(config); const isCustomStatusExpired = checkCustomStatusIsExpired(currentUser); - const customStatus = getUserCustomStatus(currentUser); if (!isCustomStatusEnabled) { return null;