Fix - Custom status

This commit is contained in:
Avinash Lingaloo
2021-10-03 23:57:28 +04:00
parent 72e30794a7
commit a875d1d057
3 changed files with 10 additions and 13 deletions

View File

@@ -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) => {

View File

@@ -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},
);
};
};

View File

@@ -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<boolean>(hasCST ?? false);
const [showRetryMessage, setShowRetryMessage] = useState<boolean>(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;