-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
blockedNumbers.js
101 lines (84 loc) · 2.77 KB
/
blockedNumbers.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2016-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* global storage, _ */
// eslint-disable-next-line func-names
(function () {
const BLOCKED_NUMBERS_ID = 'blocked';
const BLOCKED_UUIDS_ID = 'blocked-uuids';
const BLOCKED_GROUPS_ID = 'blocked-groups';
function getArray(key) {
const result = storage.get(key, []);
if (!Array.isArray(result)) {
window.log.error(
`Expected storage key ${JSON.stringify(
key
)} to contain an array or nothing`
);
return [];
}
return result;
}
storage.getBlockedNumbers = () => getArray(BLOCKED_NUMBERS_ID);
storage.isBlocked = number => {
const numbers = storage.getBlockedNumbers();
return _.include(numbers, number);
};
storage.addBlockedNumber = number => {
const numbers = storage.getBlockedNumbers();
if (_.include(numbers, number)) {
return;
}
window.log.info('adding', number, 'to blocked list');
storage.put(BLOCKED_NUMBERS_ID, numbers.concat(number));
};
storage.removeBlockedNumber = number => {
const numbers = storage.getBlockedNumbers();
if (!_.include(numbers, number)) {
return;
}
window.log.info('removing', number, 'from blocked list');
storage.put(BLOCKED_NUMBERS_ID, _.without(numbers, number));
};
storage.getBlockedUuids = () => getArray(BLOCKED_UUIDS_ID);
storage.isUuidBlocked = uuid => {
const uuids = storage.getBlockedUuids();
return _.include(uuids, uuid);
};
storage.addBlockedUuid = uuid => {
const uuids = storage.getBlockedUuids();
if (_.include(uuids, uuid)) {
return;
}
window.log.info('adding', uuid, 'to blocked list');
storage.put(BLOCKED_UUIDS_ID, uuids.concat(uuid));
};
storage.removeBlockedUuid = uuid => {
const numbers = storage.getBlockedUuids();
if (!_.include(numbers, uuid)) {
return;
}
window.log.info('removing', uuid, 'from blocked list');
storage.put(BLOCKED_UUIDS_ID, _.without(numbers, uuid));
};
storage.getBlockedGroups = () => getArray(BLOCKED_GROUPS_ID);
storage.isGroupBlocked = groupId => {
const groupIds = storage.getBlockedGroups();
return _.include(groupIds, groupId);
};
storage.addBlockedGroup = groupId => {
const groupIds = storage.getBlockedGroups();
if (_.include(groupIds, groupId)) {
return;
}
window.log.info(`adding group(${groupId}) to blocked list`);
storage.put(BLOCKED_GROUPS_ID, groupIds.concat(groupId));
};
storage.removeBlockedGroup = groupId => {
const groupIds = storage.getBlockedGroups();
if (!_.include(groupIds, groupId)) {
return;
}
window.log.info(`removing group(${groupId} from blocked list`);
storage.put(BLOCKED_GROUPS_ID, _.without(groupIds, groupId));
};
})();