Files
mattermost-mobile/app/utils/reviews.ts
Daniel Espino García 5fae120826 Add support for review app (#6772)
* Add app review

* Use overlay instead of modal

* Add fixes for ios

* i18n-extract

* Add to milliseconds function

* Address review feedback

* Add try to queryGlobalValue

* added app review illustration

* add feedback illustration

* Add animations and feedback bot message

* Restrict reviews to build environment variable

* Fix bug with "dont ask anymore"

* Add check for only supported servers

* Add missing change

* Use for await

Co-authored-by: Daniel Espino <danielespino@MacBook-Pro-de-Daniel.local>
Co-authored-by: Matthew Birtch <mattbirtch@gmail.com>
2022-11-24 18:52:15 +01:00

58 lines
1.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import InAppReview from 'react-native-in-app-review';
import {storeFirstLaunch} from '@actions/app/global';
import LocalConfig from '@assets/config.json';
import {General, Launch} from '@constants';
import {getDontAskForReview, getFirstLaunch, getLastAskedForReview} from '@queries/app/global';
import {areAllServersSupported} from '@queries/app/servers';
import {showReviewOverlay} from '@screens/navigation';
export const tryRunAppReview = async (launchType: string, coldStart?: boolean) => {
if (!LocalConfig.ShowReview) {
return;
}
if (!coldStart) {
return;
}
if (launchType !== Launch.Normal) {
return;
}
if (!InAppReview.isAvailable()) {
return;
}
const supported = await areAllServersSupported();
if (!supported) {
return;
}
const dontAsk = await getDontAskForReview();
if (dontAsk) {
return;
}
const lastReviewed = await getLastAskedForReview();
if (lastReviewed) {
if (Date.now() - lastReviewed > General.TIME_TO_NEXT_REVIEW) {
showReviewOverlay(true);
}
return;
}
const firstLaunch = await getFirstLaunch();
if (!firstLaunch) {
storeFirstLaunch();
return;
}
if ((Date.now() - firstLaunch) > General.TIME_TO_FIRST_REVIEW) {
showReviewOverlay(false);
}
};