2020-10-30 15:34:04 -05:00
|
|
|
// Copyright 2016-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-01 16:56:37 -04:00
|
|
|
/* global storage, _ */
|
2018-07-06 17:48:14 -07:00
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2020-11-18 07:15:42 -08:00
|
|
|
(function () {
|
2018-09-13 12:57:07 -07:00
|
|
|
const BLOCKED_NUMBERS_ID = 'blocked';
|
2020-03-05 13:14:58 -08:00
|
|
|
const BLOCKED_UUIDS_ID = 'blocked-uuids';
|
2018-09-13 12:57:07 -07:00
|
|
|
const BLOCKED_GROUPS_ID = 'blocked-groups';
|
|
|
|
|
2020-12-01 11:04:14 -06:00
|
|
|
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);
|
2018-07-06 17:48:14 -07:00
|
|
|
storage.isBlocked = number => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const numbers = storage.getBlockedNumbers();
|
2018-01-29 18:14:39 -08:00
|
|
|
|
2018-04-27 17:25:04 -04:00
|
|
|
return _.include(numbers, number);
|
|
|
|
};
|
2018-07-06 17:48:14 -07:00
|
|
|
storage.addBlockedNumber = number => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const numbers = storage.getBlockedNumbers();
|
2018-04-27 17:25:04 -04:00
|
|
|
if (_.include(numbers, number)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-29 18:14:39 -08:00
|
|
|
|
2018-07-21 12:00:08 -07:00
|
|
|
window.log.info('adding', number, 'to blocked list');
|
2018-09-13 12:57:07 -07:00
|
|
|
storage.put(BLOCKED_NUMBERS_ID, numbers.concat(number));
|
2018-04-27 17:25:04 -04:00
|
|
|
};
|
2018-07-06 17:48:14 -07:00
|
|
|
storage.removeBlockedNumber = number => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const numbers = storage.getBlockedNumbers();
|
2018-04-27 17:25:04 -04:00
|
|
|
if (!_.include(numbers, number)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-01-29 18:14:39 -08:00
|
|
|
|
2018-07-21 12:00:08 -07:00
|
|
|
window.log.info('removing', number, 'from blocked list');
|
2018-09-13 12:57:07 -07:00
|
|
|
storage.put(BLOCKED_NUMBERS_ID, _.without(numbers, number));
|
|
|
|
};
|
|
|
|
|
2020-12-01 11:04:14 -06:00
|
|
|
storage.getBlockedUuids = () => getArray(BLOCKED_UUIDS_ID);
|
2020-03-05 13:14:58 -08:00
|
|
|
storage.isUuidBlocked = uuid => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const uuids = storage.getBlockedUuids();
|
2020-03-05 13:14:58 -08:00
|
|
|
|
|
|
|
return _.include(uuids, uuid);
|
|
|
|
};
|
|
|
|
storage.addBlockedUuid = uuid => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const uuids = storage.getBlockedUuids();
|
2020-03-05 13:14:58 -08:00
|
|
|
if (_.include(uuids, uuid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.log.info('adding', uuid, 'to blocked list');
|
|
|
|
storage.put(BLOCKED_UUIDS_ID, uuids.concat(uuid));
|
|
|
|
};
|
|
|
|
storage.removeBlockedUuid = uuid => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const numbers = storage.getBlockedUuids();
|
2020-03-05 13:14:58 -08:00
|
|
|
if (!_.include(numbers, uuid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.log.info('removing', uuid, 'from blocked list');
|
2020-09-01 16:56:37 -04:00
|
|
|
storage.put(BLOCKED_UUIDS_ID, _.without(numbers, uuid));
|
2020-03-05 13:14:58 -08:00
|
|
|
};
|
|
|
|
|
2020-12-01 11:04:14 -06:00
|
|
|
storage.getBlockedGroups = () => getArray(BLOCKED_GROUPS_ID);
|
2018-09-13 12:57:07 -07:00
|
|
|
storage.isGroupBlocked = groupId => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const groupIds = storage.getBlockedGroups();
|
2018-09-13 12:57:07 -07:00
|
|
|
|
|
|
|
return _.include(groupIds, groupId);
|
|
|
|
};
|
|
|
|
storage.addBlockedGroup = groupId => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const groupIds = storage.getBlockedGroups();
|
2018-09-13 12:57:07 -07:00
|
|
|
if (_.include(groupIds, groupId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-08 19:25:05 -07:00
|
|
|
window.log.info(`adding group(${groupId}) to blocked list`);
|
2018-09-13 12:57:07 -07:00
|
|
|
storage.put(BLOCKED_GROUPS_ID, groupIds.concat(groupId));
|
|
|
|
};
|
|
|
|
storage.removeBlockedGroup = groupId => {
|
2020-12-01 11:04:14 -06:00
|
|
|
const groupIds = storage.getBlockedGroups();
|
2018-09-13 12:57:07 -07:00
|
|
|
if (!_.include(groupIds, groupId)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.log.info(`removing group(${groupId} from blocked list`);
|
|
|
|
storage.put(BLOCKED_GROUPS_ID, _.without(groupIds, groupId));
|
2018-04-27 17:25:04 -04:00
|
|
|
};
|
2016-09-06 17:12:45 -07:00
|
|
|
})();
|