Rename isOnline to isPing for clarity, and reduce the ttl for online broadcast messages to 1 min

pull/203/head
Beaudan 6 years ago
parent 1c4d9b40bb
commit b00a0cb699

@ -223,8 +223,8 @@
textsecure.storage.user.getNumber()
);
window.lokiP2pAPI.on('pingContact', pubKey => {
const forceP2p = true;
window.libloki.api.sendOnlineBroadcastMessage(pubKey, forceP2p);
const isPing = true;
window.libloki.api.sendOnlineBroadcastMessage(pubKey, isPing);
});
// These make key operations available to IPC handlers created in preload.js

@ -63,11 +63,11 @@ class LokiMessageAPI {
this.messageServerPort = messageServerPort ? `:${messageServerPort}` : '';
}
async sendMessage(pubKey, data, messageTimeStamp, ttl, forceP2p = false) {
async sendMessage(pubKey, data, messageTimeStamp, ttl, isPing = false) {
const data64 = dcodeIO.ByteBuffer.wrap(data).toString('base64');
const timestamp = Math.floor(Date.now() / 1000);
const p2pDetails = lokiP2pAPI.getContactP2pDetails(pubKey);
if (p2pDetails && (forceP2p || p2pDetails.isOnline)) {
if (p2pDetails && (isPing || p2pDetails.isOnline)) {
try {
const port = p2pDetails.port ? `:${p2pDetails.port}` : '';
const url = `${p2pDetails.address}${port}/store`;

@ -16,7 +16,7 @@ class LokiP2pAPI extends EventEmitter {
});
}
updateContactP2pDetails(pubKey, address, port, isOnline = false) {
updateContactP2pDetails(pubKey, address, port, isPing = false) {
// Stagger the timers so the friends don't ping each other at the same time
const timerDuration =
pubKey < this.ourKey
@ -35,7 +35,7 @@ class LokiP2pAPI extends EventEmitter {
pingTimer: null,
};
if (isOnline) {
if (isPing) {
this.setContactOnline(pubKey);
return;
}

@ -23,7 +23,7 @@
);
}
async function sendOnlineBroadcastMessage(pubKey, forceP2p = false) {
async function sendOnlineBroadcastMessage(pubKey, isPing = false) {
const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress();
const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({
p2pAddress: `http://${myLokiAddress}`,
@ -41,7 +41,7 @@
log.info('Online broadcast message sent successfully');
}
};
const options = { messageType: 'onlineBroadcast', forceP2p };
const options = { messageType: 'onlineBroadcast', isPing };
// Send a empty message with information about how to contact us directly
const outgoingMessage = new textsecure.OutgoingMessage(
null, // server

@ -42,13 +42,13 @@ function OutgoingMessage(
this.failoverNumbers = [];
this.unidentifiedDeliveries = [];
const { numberInfo, senderCertificate, online, messageType, forceP2p } =
const { numberInfo, senderCertificate, online, messageType, isPing } =
options || {};
this.numberInfo = numberInfo;
this.senderCertificate = senderCertificate;
this.online = online;
this.messageType = messageType || 'outgoing';
this.forceP2p = forceP2p || false;
this.isPing = isPing || false;
}
OutgoingMessage.prototype = {
@ -192,7 +192,7 @@ OutgoingMessage.prototype = {
data,
timestamp,
ttl,
this.forceP2p
this.isPing
);
} catch (e) {
if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) {
@ -347,7 +347,7 @@ OutgoingMessage.prototype = {
if (this.messageType === 'friend-request') {
ttl = 4 * 24 * 60 * 60; // 4 days for friend request message
} else if (this.messageType === 'onlineBroadcast') {
ttl = 10 * 60; // 10 minutes for online broadcast message
ttl = 60; // 1 minute for online broadcast message
} else {
const hours = window.getMessageTTL() || 24; // 1 day default for any other message
ttl = hours * 60 * 60;

Loading…
Cancel
Save