Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3514785
D5498.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D5498.diff
View Options
diff --git a/native/data/sqlite-context-provider.js b/native/data/sqlite-context-provider.js
--- a/native/data/sqlite-context-provider.js
+++ b/native/data/sqlite-context-provider.js
@@ -7,7 +7,6 @@
import { setMessageStoreMessages } from 'lib/actions/message-actions.js';
import { setThreadStoreActionType } from 'lib/actions/thread-actions';
-import { isStaff } from 'lib/shared/user-utils';
import { loginActionSources } from 'lib/types/account-types';
import { fetchNewCookieFromNativeCredentials } from 'lib/utils/action-utils';
import { getMessageForException } from 'lib/utils/errors';
@@ -15,6 +14,7 @@
import { commCoreModule } from '../native-modules';
import { useSelector } from '../redux/redux-utils';
+import { useStaffCanSee } from '../utils/staff-utils';
import { SQLiteContext } from './sqlite-context';
type Props = {
@@ -30,9 +30,7 @@
);
const cookie = useSelector(state => state.cookie);
const urlPrefix = useSelector(state => state.urlPrefix);
- const viewerID = useSelector(
- state => state.currentUserInfo && state.currentUserInfo.id,
- );
+ const staffCanSee = useStaffCanSee();
React.useEffect(() => {
if (storeLoaded || !rehydrateConcluded) {
@@ -55,7 +53,7 @@
});
setStoreLoaded(true);
} catch (setStoreException) {
- if (__DEV__ || (viewerID && isStaff(viewerID))) {
+ if (staffCanSee) {
Alert.alert(
`Error setting threadStore or messageStore: ${
getMessageForException(setStoreException) ??
@@ -72,7 +70,7 @@
);
setStoreLoaded(true);
} catch (fetchCookieException) {
- if (__DEV__ || (viewerID && isStaff(viewerID))) {
+ if (staffCanSee) {
Alert.alert(
`Error fetching new cookie from native credentials: ${
getMessageForException(fetchCookieException) ??
@@ -85,7 +83,14 @@
}
}
})();
- }, [storeLoaded, urlPrefix, rehydrateConcluded, cookie, dispatch, viewerID]);
+ }, [
+ cookie,
+ dispatch,
+ rehydrateConcluded,
+ staffCanSee,
+ storeLoaded,
+ urlPrefix,
+ ]);
const contextValue = React.useMemo(
() => ({
diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js
--- a/native/input/input-state-container.react.js
+++ b/native/input/input-state-container.react.js
@@ -37,7 +37,6 @@
createRealThreadFromPendingThread,
threadIsPending,
} from 'lib/shared/thread-utils';
-import { isStaff } from 'lib/shared/user-utils';
import type { CalendarQuery } from 'lib/types/entry-types';
import type {
UploadMultimediaResult,
@@ -89,6 +88,7 @@
import { displayActionResultModal } from '../navigation/action-result-modal';
import { useCalendarQuery } from '../navigation/nav-selectors';
import { useSelector } from '../redux/redux-utils';
+import { useStaffCanSee } from '../utils/staff-utils';
import {
InputStateContext,
type PendingMultimediaUploads,
@@ -117,6 +117,7 @@
+mediaReportsEnabled: boolean,
+calendarQuery: () => CalendarQuery,
+dispatch: Dispatch,
+ +staffCanSee: boolean,
+dispatchActionPromise: DispatchActionPromise,
+uploadMultimedia: (
multimedia: Object,
@@ -841,11 +842,11 @@
}
mediaProcessConfig(localMessageID: string, localID: string) {
- const { hasWiFi, viewerID } = this.props;
+ const { hasWiFi, staffCanSee } = this.props;
const onTranscodingProgress = (percent: number) => {
this.setProgress(localMessageID, localID, 'transcoding', percent);
};
- if (__DEV__ || (viewerID && isStaff(viewerID))) {
+ if (staffCanSee) {
return {
hasWiFi,
finalFileHeaderCheck: true,
@@ -1400,6 +1401,7 @@
const dispatchActionPromise = useDispatchActionPromise();
const dispatch = useDispatch();
const mediaReportsEnabled = useIsReportEnabled('mediaReports');
+ const staffCanSee = useStaffCanSee();
return (
<InputStateContainer
@@ -1417,6 +1419,7 @@
newThread={callNewThread}
dispatchActionPromise={dispatchActionPromise}
dispatch={dispatch}
+ staffCanSee={staffCanSee}
/>
);
},
diff --git a/native/profile/profile-screen.react.js b/native/profile/profile-screen.react.js
--- a/native/profile/profile-screen.react.js
+++ b/native/profile/profile-screen.react.js
@@ -6,7 +6,6 @@
import { logOutActionTypes, logOut } from 'lib/actions/user-actions';
import { preRequestUserStateSelector } from 'lib/selectors/account-selectors';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors';
-import { isStaff } from 'lib/shared/user-utils';
import type { LogOutResult } from 'lib/types/account-types';
import { type PreRequestUserState } from 'lib/types/session-types';
import { type CurrentUserInfo } from 'lib/types/user-types';
@@ -35,23 +34,9 @@
} from '../navigation/route-names';
import { useSelector } from '../redux/redux-utils';
import { type Colors, useColors, useStyles } from '../themes/colors';
+import { useStaffCanSee } from '../utils/staff-utils';
import type { ProfileNavigationProp } from './profile.react';
-type BaseProps = {
- +navigation: ProfileNavigationProp<'ProfileScreen'>,
- +route: NavigationRoute<'ProfileScreen'>,
-};
-type Props = {
- ...BaseProps,
- +currentUserInfo: ?CurrentUserInfo,
- +preRequestUserState: PreRequestUserState,
- +logOutLoading: boolean,
- +colors: Colors,
- +styles: typeof unboundStyles,
- +dispatchActionPromise: DispatchActionPromise,
- +logOut: (preRequestUserState: PreRequestUserState) => Promise<LogOutResult>,
-};
-
type ProfileRowProps = {
+content: string,
+onPress: () => void,
@@ -68,6 +53,22 @@
);
}
+type BaseProps = {
+ +navigation: ProfileNavigationProp<'ProfileScreen'>,
+ +route: NavigationRoute<'ProfileScreen'>,
+};
+type Props = {
+ ...BaseProps,
+ +currentUserInfo: ?CurrentUserInfo,
+ +preRequestUserState: PreRequestUserState,
+ +logOutLoading: boolean,
+ +colors: Colors,
+ +styles: typeof unboundStyles,
+ +dispatchActionPromise: DispatchActionPromise,
+ +logOut: (preRequestUserState: PreRequestUserState) => Promise<LogOutResult>,
+ +staffCanSee: boolean,
+};
+
class ProfileScreen extends React.PureComponent<Props> {
get username() {
return this.props.currentUserInfo && !this.props.currentUserInfo.anonymous
@@ -85,10 +86,8 @@
render() {
let appearancePreferences, developerTools, defaultNotifications;
- if (
- (this.props.currentUserInfo && isStaff(this.props.currentUserInfo.id)) ||
- __DEV__
- ) {
+ const { staffCanSee } = this.props;
+ if (staffCanSee) {
appearancePreferences = (
<ProfileRow content="Appearance" onPress={this.onPressAppearance} />
);
@@ -355,6 +354,7 @@
const styles = useStyles(unboundStyles);
const callLogOut = useServerCall(logOut);
const dispatchActionPromise = useDispatchActionPromise();
+ const staffCanSee = useStaffCanSee();
return (
<ProfileScreen
@@ -366,6 +366,7 @@
styles={styles}
logOut={callLogOut}
dispatchActionPromise={dispatchActionPromise}
+ staffCanSee={staffCanSee}
/>
);
},
diff --git a/native/utils/staff-utils.js b/native/utils/staff-utils.js
new file mode 100644
--- /dev/null
+++ b/native/utils/staff-utils.js
@@ -0,0 +1,19 @@
+// @flow
+
+import { useSelector } from 'react-redux';
+
+import { isStaff } from 'lib/shared/user-utils';
+
+const isStaffRelease = false;
+
+function useStaffCanSee(): boolean {
+ const isCurrentUserStaff = useSelector(
+ state =>
+ state.currentUserInfo &&
+ state.currentUserInfo.id &&
+ isStaff(state.currentUserInfo.id),
+ );
+ return __DEV__ || isStaffRelease || isCurrentUserStaff;
+}
+
+export { useStaffCanSee };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 6:34 AM (18 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693819
Default Alt Text
D5498.diff (7 KB)
Attached To
Mode
D5498: [native] Introduce `useStaffCanSee()`
Attached
Detach File
Event Timeline
Log In to Comment