need to make sure that get loop runs only once; closes #20

php
Marc Wäckerlin 9 years ago
parent 585fc5613c
commit fbcb2e2a7b
  1. 23
      ChangeLog
  2. 4
      html/safechat.css
  3. 22
      html/safechat.js

@ -1,3 +1,26 @@
2015-08-26 22:43 marc
* ax_init_standard_project.m4, bootstrap.sh, configure.ac,
html/index.html.in, html/safechat.css, html/safechat.js: profile
download implemented; closes #16
2015-08-26 21:30 marc
* html/chat.html, html/index.html.in, html/safechat.js: profile
download implemented; closes #15
2015-08-26 21:13 marc
* html/index.html.in, html/menu.svg, html/safechat.css,
html/safechat.js: profile download implemented; closes #15
2015-08-16 15:07 marc
* ChangeLog, ax_check_qt.m4, ax_init_standard_project.m4,
bootstrap.sh, configure.ac, html/index.html, html/index.html.in,
html/safechat.js, mac-create-app-bundle.sh: Fixes #13 by
introducing vibration where available
2015-07-16 10:54 marc
* ChangeLog, doc/doxyfile.in: try without searchbox

@ -121,8 +121,10 @@ td:last-child {
list-style-type: none;
border: 1px solid black;
}
#menu li, #menu li * {
#menu li {
padding: 0 1em 0 1em;
}
#menu li, #menu li * {
cursor: pointer;
text-align: left;
}

@ -119,6 +119,20 @@ function status(text, msg) {
});
}
var getLoopTimeout = null; ///< store get timeout to make sure only one is running
/// Set timeout for next get request
/** @param time timeout time in ms, defaults to 10000 */
function getLoop(time) {
if (!time) time = 10000;
getLoopStop();
getLoopTimeout = setTimeout(get, time);
}
/// Stop get loop if it is running
function getLoopStop() {
if (getLoopTimeout) clearTimeout(getLoopTimeout);
getLoopTimeout = null;
}
/// Alert user
/** Alert user, e.g. that a new message has arrived.
@param */
@ -139,6 +153,7 @@ function togglemenu() {
/// Download Profile Backup
function backup() {
getLoopStop();
status("<p>Starting backup download ...</p>");
var download = document.createElement('a');
download.href = 'data:attachment/text,'+encodeURI(JSON.stringify(localStorage));
@ -160,6 +175,7 @@ function backup() {
/// Upload Profile Backup
function restore(evt) {
getLoopStop();
status("<p>Starting backup restore ...</p>");
if (!window.FileReader)
return error("your browser dows not support file upload", true);
@ -404,7 +420,7 @@ function get() {
var res=JSON.parse(pk);
var key=openpgp.key.readArmored(res);
if (!res||key.err) {
setTimeout(get, 10000);
getLoop();
return error("key of receiver not found", true);
}
var message = openpgp.message.readArmored(e.msg);
@ -449,7 +465,7 @@ function get() {
}).fail(function(e) {
error("offline", true)
});
setTimeout(get, 10000); // repeat every 10 seconds
getLoop(); // repeat every 10 seconds
}
/// Send Message To Server
@ -535,7 +551,7 @@ function chat() {
$("#username").html(userid()+"@safechat.ch");
$.ajax({url: "chat.html", success: function(res) {
status(res);
setTimeout(get, 2000);
getLoop(2000);
}}).fail(function() {
error("offline")
});

Loading…
Cancel
Save