aboutsummaryrefslogtreecommitdiff
path: root/src/utils/users.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-03-29 15:01:52 -0400
committerGitHub <noreply@github.com>2021-03-29 15:01:52 -0400
commitad2ad5d232473d38426c2f0f8283ba015dadfd4c (patch)
treef375a074fa23ca70c304f93b5577ed830250394c /src/utils/users.ts
parent4de1ebd43437712e28a89bb624c5b12afad45cc6 (diff)
parentee80ddfb8a486fea31d845aba4e0b4847fe637e9 (diff)
Merge pull request #306 from TaggiD-Inc/tma-701-private-account-banner
[TMA 701] : Separated Private and Public Profiles
Diffstat (limited to 'src/utils/users.ts')
-rw-r--r--src/utils/users.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/utils/users.ts b/src/utils/users.ts
index d5e44b36..f9d6d6b7 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -174,3 +174,35 @@ export const defaultUserProfile = () => {
const defaultImage = require('../assets/images/avatar-placeholder.png');
return defaultImage;
};
+
+/**
+ * Used to determine whether the logged-in user is able to view userX's private
+ * information or not.
+ *
+ * @param state redux store's root state
+ * @param userXId target userX's id
+ * @param screenType current screen type
+ * @returns true if abel to view private info, false otherwise
+ */
+export const canViewProfile = (
+ state: RootState,
+ userXId: string | undefined,
+ screenType: ScreenType,
+) => {
+ // own profile
+ if (!userXId || state.user.user.userId === userXId) {
+ return true;
+ }
+ // not private
+ if (!(userXId && state.userX[screenType][userXId].profile.is_private)) {
+ return true;
+ }
+ // is friend
+ if (
+ userXId &&
+ state.userX[screenType][userXId].profile.friendship_status === 'friends'
+ ) {
+ return true;
+ }
+ return false;
+};