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";
|
||||
|
||||
function sendNotification(close) {
|
||||
if (window.sendingAccidentAlert)
|
||||
return;
|
||||
window.sending = true;
|
||||
const bot = new Telegram(TG_API);
|
||||
bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below.");
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
position => bot.sendLocation( TG_USERID,
|
||||
position.coords.latitude, position.coords.longitude),
|
||||
() => bot.sendMessage(TG_USERID, "Error retrieving location")
|
||||
position => {
|
||||
bot.sendLocation( TG_USERID,
|
||||
position.coords.latitude, position.coords.longitude);
|
||||
window.sendingAccidentAlert = false;
|
||||
},
|
||||
() => {
|
||||
bot.sendMessage(TG_USERID, "Error retrieving location");
|
||||
window.sendingAccidentAlert = false;
|
||||
}
|
||||
);
|
||||
setTimeout(close, 2000);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue