forked from orkestral/venom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-location.js
66 lines (63 loc) · 1.59 KB
/
send-location.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
export async function sendLocation(
chatId,
latitude,
longitude,
location = null
) {
const chat = await WAPI.sendExist(chatId);
if (isNaN(Number(latitude)) || isNaN(Number(longitude))) {
return WAPI.scope(
chatId,
true,
null,
'latitude and longitude must be numbers'
);
}
if (!chat.erro) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id._serialized);
const inChat = await WAPI.getchatId(chat.id).catch(() => {});
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
}
const newid = await window.WAPI.getNewMessageId(
chat.id._serialized,
chatId
);
const message = {
type: 'location',
ack: 0,
from: fromwWid,
id: newid,
local: !0,
isNewMsg: !0,
self: 'out',
t: parseInt(new Date().getTime() / 1000),
to: chat.id,
lat: Number(latitude),
lng: Number(longitude),
loc: location
};
const result =
(await Promise.all(Store.addAndSendMsgToChat(chat, message)))[1] || '';
let m = {
latitude: latitude,
longitude: longitude,
title: location,
type: 'location'
},
obj;
if (result == 'success' || result == 'OK') {
obj = WAPI.scope(newMsgId, false, result, null);
Object.assign(obj, m);
return obj;
} else {
obj = WAPI.scope(newMsgId, true, result, null);
Object.assign(obj, m);
return obj;
}
} else {
return chat;
}
}