aboutsummaryrefslogtreecommitdiff
path: root/src/utils/common.ts
diff options
context:
space:
mode:
authorAshm Walia <ashmwalia@outlook.com>2021-01-19 11:36:56 -0800
committerAshm Walia <ashmwalia@outlook.com>2021-01-19 11:36:56 -0800
commitc510ba308738fc88edb11772fe9db6ec4537427f (patch)
tree86ca27286d50c35ec9a4b6362c8b42408ac85160 /src/utils/common.ts
parentbb885ff561e44e23f9fb27ba8aa18f4dce8c690e (diff)
Done
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;
+};