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

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

Loading…
Cancel
Save