Review comments, moved swarmNodes database stuff to just be in data.js

This commit is contained in:
Beaudan 2019-01-30 16:36:30 +11:00
parent 80fa4f866e
commit e735b3ca41
4 changed files with 25 additions and 23 deletions

View file

@ -110,6 +110,7 @@ module.exports = {
removeAllSessions,
getSwarmNodesByPubkey,
saveSwarmNodesForPubKey,
getConversationCount,
saveConversation,
@ -674,6 +675,16 @@ async function getSwarmNodesByPubkey(pubkey) {
return channels.getSwarmNodesByPubkey(pubkey);
}
async function saveSwarmNodesForPubKey(pubKey, swarmNodes, { Conversation }) {
const conversation = await getConversationById(pubKey, { Conversation });
conversation.set({ swarmNodes });
await updateConversation(
conversation.id,
conversation.attributes,
{ Conversation }
);
}
async function getConversationCount() {
return channels.getConversationCount();
}

View file

@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-loop-func */
/* global log, dcodeIO, window, callWorker */
/* global log, dcodeIO, window, callWorker, Whisper */
const fetch = require('node-fetch');
const _ = require('lodash');
@ -105,7 +105,7 @@ class LokiMessageAPI {
throw HTTPError('sendMessage: error response', response.status, result);
};
let swarmNodes = await window.LokiSnodeAPI.getSwarmNodesByPubkey(pubKey);
let swarmNodes = await window.Signal.Data.getSwarmNodesByPubkey(pubKey);
while (successfulRequests < MINIMUM_SUCCESSFUL_REQUESTS) {
if (!canResolve) {
throw new window.textsecure.DNSResolutionError('Sending messages');
@ -123,7 +123,11 @@ class LokiMessageAPI {
new Error('Ran out of swarm nodes to query')
);
}
await window.LokiSnodeAPI.saveSwarmNodes(pubKey, swarmNodes);
await window.Signal.Data.saveSwarmNodesForPubkey(
pubKey,
swarmNodes,
{ Conversation: Whisper.Conversation }
);
}
const remainingRequests =
MINIMUM_SUCCESSFUL_REQUESTS - completedNodes.length;

View file

@ -106,23 +106,6 @@ class LokiSnodeAPI {
return this.ourSwarmNodes;
}
async getSwarmNodesByPubkey(pubKey) {
const swarmNodes = await window.Signal.Data.getSwarmNodesByPubkey(pubKey);
return swarmNodes;
}
async saveSwarmNodes(pubKey, swarmNodes) {
const conversation = window.ConversationController.get(pubKey);
conversation.set({ swarmNodes });
await window.Signal.Data.updateConversation(
conversation.id,
conversation.attributes,
{
Conversation: Whisper.Conversation,
}
);
}
async getFreshSwarmNodes(pubKey) {
if (!(pubKey in this.swarmsPendingReplenish)) {
this.swarmsPendingReplenish[pubKey] = new Promise(async resolve => {

View file

@ -12,9 +12,13 @@
const friendKeys = await window.Signal.Data.getPubKeysWithFriendStatus(
window.friends.friendRequestStatusEnum.friends
);
friendKeys.forEach(pubKey => {
sendOnlineBroadcastMessage(pubKey);
});
await Promise.all(friendKeys.map(async pubKey => {
try {
await sendOnlineBroadcastMessage(pubKey);
} catch(e) {
log.warn(`Failed to send online broadcast message to ${pubKey}`);
}
}));
}
async function sendOnlineBroadcastMessage(pubKey) {