-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcallLogs.js
35 lines (29 loc) · 1.01 KB
/
callLogs.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
import { NativeModules } from 'react-native';
const {CallLogs: NativeCallLogs} = NativeModules;
class CallLogs {
static async load(limit, filter) {
if (!filter) {
return NativeCallLogs.load(limit);
}
const {minTimestamp, maxTimestamp, types, phoneNumbers} = filter;
const phoneNumbersArray = Array.isArray(phoneNumbers) ?
phoneNumbers :
typeof phoneNumbers === 'string' ? [phoneNumbers] : [];
const typesArray = Array.isArray(types) ?
types.map(x => x.toString()) :
(typeof types === 'string' || typeof types === 'object') ? [types.toString()] : [];
return NativeCallLogs.loadWithFilter(
limit,
{
minTimestamp: minTimestamp ? minTimestamp.toString() : undefined,
maxTimestamp: maxTimestamp ? maxTimestamp.toString() : undefined,
types: JSON.stringify(typesArray),
phoneNumbers: JSON.stringify(phoneNumbersArray),
}
);
}
static async loadAll() {
return NativeCallLogs.loadAll();
}
}
module.exports = CallLogs;