aboutsummaryrefslogtreecommitdiff
path: root/src/utils/common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r--src/utils/common.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts
index 95e77f64..9d0de64b 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -101,6 +101,27 @@ export const haveUnreadNotifications = async (
return false;
};
+export const getUnreadNotifications = async (
+ notifications: NotificationType[],
+): Promise<NotificationType[]> => {
+ const outputNotifications = [];
+ 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) {
+ outputNotifications.push(n);
+ }
+ }
+ return outputNotifications;
+};
+
// https://stackoverflow.com/a/2450976
export const shuffle = (array: any[]) => {
var currentIndex = array.length,
@@ -197,3 +218,7 @@ export const validateImageLink = async (url: string | undefined) => {
return false;
});
};
+
+export const numberWithCommas = (digits: number) => {
+ return digits.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
+};