Fix repeating notifications in Accident.js
This commit is contained in:
parent
d4a19060e8
commit
a1dc088a23
|
@ -9,18 +9,18 @@ import { TG_API, TG_USERID } from "../config";
|
||||||
function sendNotification(close) {
|
function sendNotification(close) {
|
||||||
if (window.sendingAccidentAlert)
|
if (window.sendingAccidentAlert)
|
||||||
return;
|
return;
|
||||||
window.sending = true;
|
window.sendingAccidentAlert = true;
|
||||||
const bot = new Telegram(TG_API);
|
const bot = new Telegram(TG_API);
|
||||||
bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below.");
|
bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below.");
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
position => {
|
position => {
|
||||||
|
window.sendingAccidentAlert = false;
|
||||||
bot.sendLocation( TG_USERID,
|
bot.sendLocation( TG_USERID,
|
||||||
position.coords.latitude, position.coords.longitude);
|
position.coords.latitude, position.coords.longitude);
|
||||||
window.sendingAccidentAlert = false;
|
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
bot.sendMessage(TG_USERID, "Error retrieving location");
|
|
||||||
window.sendingAccidentAlert = false;
|
window.sendingAccidentAlert = false;
|
||||||
|
bot.sendMessage(TG_USERID, "Error retrieving location");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
setTimeout(close, 2000);
|
setTimeout(close, 2000);
|
||||||
|
|
Loading…
Reference in New Issue