Add locking mechanism around sendNotification
Workaround for multiple messages being sent
This commit is contained in:
parent
49430114fe
commit
66d688291c
|
@ -7,12 +7,21 @@ import Telegram from "../utils/telegram";
|
||||||
import { TG_API, TG_USERID } from "../config";
|
import { TG_API, TG_USERID } from "../config";
|
||||||
|
|
||||||
function sendNotification(close) {
|
function sendNotification(close) {
|
||||||
|
if (window.sendingAccidentAlert)
|
||||||
|
return;
|
||||||
|
window.sending = 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 => bot.sendLocation( TG_USERID,
|
position => {
|
||||||
position.coords.latitude, position.coords.longitude),
|
bot.sendLocation( TG_USERID,
|
||||||
() => bot.sendMessage(TG_USERID, "Error retrieving location")
|
position.coords.latitude, position.coords.longitude);
|
||||||
|
window.sendingAccidentAlert = false;
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
bot.sendMessage(TG_USERID, "Error retrieving location");
|
||||||
|
window.sendingAccidentAlert = false;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
setTimeout(close, 2000);
|
setTimeout(close, 2000);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue