forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseNotificationList.ts
More file actions
49 lines (44 loc) · 1.63 KB
/
useNotificationList.ts
File metadata and controls
49 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Notifications } from '../entity/notification';
import { Tab } from '../entity/tab';
import { StorageParams } from '../storage/storage-params';
import { isDomainEquals } from '../utils/common';
import { todayLocalDate } from '../utils/date';
import { log } from '../utils/logger';
import { Settings } from './settings';
export type LimitExceed = {
IsLimitExceeded: boolean;
LimitTime: number | null;
};
export function useNotificationList() {
async function isNeedToShowNotification(url: string, tab: Tab): Promise<boolean> {
const notificationList = (await Settings.getInstance().getSetting(
StorageParams.NOTIFICATION_LIST,
)) as Notifications[];
const array = Object.values(notificationList);
const item = array?.find(x => isDomainEquals(x.domain, url));
if (item != undefined) {
const date = tab.days.find(x => x.date == todayLocalDate());
if (date != undefined) {
if (date.summary != 0 && (date.summary == item.time || date.summary % item.time == 0)) {
log(
`Time for notification: website ${url} time ${item.time} summary time ${date.summary}`,
);
return true;
}
}
}
return false;
}
async function isDomainInNotificationsLimit(url: string): Promise<boolean> {
const notificationList = (await Settings.getInstance().getSetting(
StorageParams.NOTIFICATION_LIST,
)) as Notifications[];
const array = Object.values(notificationList);
const item = array?.find(x => isDomainEquals(x.domain, url));
return item != undefined;
}
return {
isNeedToShowNotification,
isDomainInNotificationsLimit,
};
}