aboutsummaryrefslogtreecommitdiff
path: root/src/utils/common.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@thetaggid.com>2021-01-20 15:52:37 -0500
committerGitHub <noreply@github.com>2021-01-20 15:52:37 -0500
commit7b45e8d238f392183f3c1742f22495a2f9c6fb7f (patch)
treebab6621bf916e9efa0ce863cf49b649bd6ba6548 /src/utils/common.ts
parenta64a0c53f108f8ea9c9ac0ba67c34ff82007271e (diff)
parent623bc69013c8fd173e49fb059eaba23c9219e0eb (diff)
Merge pull request #192 from ashmgarv/tma515-new-no-icon
[TMA - 515] New notifications icon and reordering of bottom navigation stack
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r--src/utils/common.ts22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts
index 6314cc13..8efe1f6a 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -1,6 +1,8 @@
+import {NotificationType} from './../types/types';
import moment from 'moment';
-import {AsyncStorage, Linking} from 'react-native';
+import {Linking} from 'react-native';
import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants';
+import AsyncStorage from '@react-native-community/async-storage';
export const getToggleButtonText: (
buttonType: string,
@@ -72,3 +74,21 @@ export const checkImageUploadStatus = (statusMap: object) => {
}
return true;
};
+
+export const haveUnreadNotifications = async (
+ notifications: NotificationType[],
+): Promise<boolean> => {
+ for (const n of notifications) {
+ const notificationDate = moment(n.timestamp);
+ const prevLastViewed = await AsyncStorage.getItem('notificationLastViewed');
+ const lastViewed: moment.Moment | undefined =
+ prevLastViewed == null ? moment.unix(0) : moment(prevLastViewed);
+ const dateAge = getDateAge(notificationDate);
+ if (dateAge === 'unknown') {
+ continue;
+ }
+ const unread = lastViewed ? lastViewed.diff(notificationDate) < 0 : false;
+ if (unread) return true;
+ }
+ return false;
+};