diff options
author | Ashm Walia <ashmwalia@outlook.com> | 2021-01-19 11:36:56 -0800 |
---|---|---|
committer | Ashm Walia <ashmwalia@outlook.com> | 2021-01-19 11:36:56 -0800 |
commit | c510ba308738fc88edb11772fe9db6ec4537427f (patch) | |
tree | 86ca27286d50c35ec9a4b6362c8b42408ac85160 /src/utils/common.ts | |
parent | bb885ff561e44e23f9fb27ba8aa18f4dce8c690e (diff) |
Done
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r-- | src/utils/common.ts | 22 |
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; +}; |