-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
locations.ts
82 lines (68 loc) 路 2.17 KB
/
locations.ts
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
/* eslint-disable camelcase */
const binding = require('../binding')
const debug = require('debug')('deltachat:node:locations')
interface NativeLocations {}
/**
* Wrapper around dc_location_t*
*/
export class Locations {
constructor(public dc_locations: NativeLocations) {
debug('Locations constructor')
if (dc_locations === null) {
throw new Error('dc_locations can not be null')
}
}
locationToJson(index: number) {
debug('locationToJson')
return {
accuracy: this.getAccuracy(index),
latitude: this.getLatitude(index),
longitude: this.getLongitude(index),
timestamp: this.getTimestamp(index),
contactId: this.getContactId(index),
msgId: this.getMsgId(index),
chatId: this.getChatId(index),
isIndependent: this.isIndependent(index),
marker: this.getMarker(index),
}
}
toJson(): ReturnType<Locations['locationToJson']>[] {
debug('toJson')
const locations = []
const count = this.getCount()
for (let index = 0; index < count; index++) {
locations.push(this.locationToJson(index))
}
return locations
}
getCount(): number {
return binding.dcn_array_get_cnt(this.dc_locations)
}
getAccuracy(index: number): number {
return binding.dcn_array_get_accuracy(this.dc_locations, index)
}
getLatitude(index: number): number {
return binding.dcn_array_get_latitude(this.dc_locations, index)
}
getLongitude(index: number): number {
return binding.dcn_array_get_longitude(this.dc_locations, index)
}
getTimestamp(index: number): number {
return binding.dcn_array_get_timestamp(this.dc_locations, index)
}
getMsgId(index: number): number {
return binding.dcn_array_get_msg_id(this.dc_locations, index)
}
getContactId(index: number): number {
return binding.dcn_array_get_contact_id(this.dc_locations, index)
}
getChatId(index: number): number {
return binding.dcn_array_get_chat_id(this.dc_locations, index)
}
isIndependent(index: number): boolean {
return binding.dcn_array_is_independent(this.dc_locations, index)
}
getMarker(index: number): string {
return binding.dcn_array_get_marker(this.dc_locations, index)
}
}