Roll back change to ping more often again, ping our offline contacts every 2 mins to check if they have come back online

pull/203/head
Beaudan 7 years ago
parent 29bca71d5a
commit dc67aaf9cc

@ -2,6 +2,8 @@
const EventEmitter = require('events');
const offlinePingTime = 2 * 60 * 1000; // 2 minutes
class LokiP2pAPI extends EventEmitter {
constructor(ourKey) {
super();
@ -85,6 +87,11 @@ class LokiP2pAPI extends EventEmitter {
return;
}
clearTimeout(this.contactP2pDetails[pubKey].pingTimer);
this.contactP2pDetails[pubKey].pingTimer = setTimeout(
this.pingContact.bind(this),
offlinePingTime,
pubKey
);
this.contactP2pDetails[pubKey].isOnline = false;
}

@ -218,6 +218,9 @@ MessageReceiver.prototype.extend({
const promise = Promise.resolve(request.body.toArrayBuffer()) // textsecure.crypto
.then(plaintext => {
const envelope = textsecure.protobuf.Envelope.decode(plaintext);
if (isP2p) {
lokiP2pAPI.setContactOnline(envelope.source);
}
// After this point, decoding errors are not the server's
// fault, and we should handle them gracefully and tell the
// user they received an invalid message
@ -945,9 +948,7 @@ MessageReceiver.prototype.extend({
return this.removeFromCache(envelope);
},
handleDataMessage(envelope, msg) {
if (envelope.isP2p) {
lokiP2pAPI.setContactOnline(envelope.source);
} else {
if (!envelope.isP2p) {
const timestamp = envelope.timestamp.toNumber();
const now = Date.now();
const ageInSeconds = (now - timestamp) / 1000;

Loading…
Cancel
Save