diff options
author | Ivan Chen <ivan@thetaggid.com> | 2021-01-20 15:52:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 15:52:37 -0500 |
commit | 7b45e8d238f392183f3c1742f22495a2f9c6fb7f (patch) | |
tree | bab6621bf916e9efa0ce863cf49b649bd6ba6548 /src/utils/common.ts | |
parent | a64a0c53f108f8ea9c9ac0ba67c34ff82007271e (diff) | |
parent | 623bc69013c8fd173e49fb059eaba23c9219e0eb (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.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; +}; |