Further improve imports

pull/1204/head
Maxim Shishmarev 5 years ago
parent b31b6bb912
commit 7dd9469074

@ -1,6 +1,6 @@
import { EnvelopePlus } from './types';
import { StringUtils } from '../session/utils';
import { toNumber } from 'lodash';
import _ from 'lodash';
export async function removeFromCache(envelope: EnvelopePlus) {
const { id } = envelope;
@ -33,7 +33,7 @@ export async function addToCache(
export async function getAllFromCache() {
window.log.info('getAllFromCache');
const { textsecure, Lodash: _ } = window;
const { textsecure } = window;
const count = await textsecure.storage.unprocessed.getCount();
@ -50,7 +50,7 @@ export async function getAllFromCache() {
return Promise.all(
_.map(items, async (item: any) => {
const attempts = toNumber(item.attempts || 0) + 1;
const attempts = _.toNumber(item.attempts || 0) + 1;
try {
if (attempts >= 3) {

@ -17,6 +17,7 @@ import { PubKey } from '../session/types';
import { handleSyncMessage } from './syncMessages';
import { onError } from './errors';
import ByteBuffer from 'bytebuffer';
export async function handleContentMessage(envelope: EnvelopePlus) {
const plaintext = await decrypt(envelope, envelope.content);
@ -113,7 +114,7 @@ async function decryptPreKeyWhisperMessage(
if (e.message === 'Unknown identity key') {
// create an error that the UI will pick up and ask the
// user if they want to re-negotiate
const buffer = window.dcodeIO.ByteBuffer.wrap(ciphertext);
const buffer = ByteBuffer.wrap(ciphertext);
throw new window.textsecure.IncomingIdentityKeyError(
address.toString(),
buffer.toArrayBuffer(),
@ -312,7 +313,7 @@ async function decrypt(
if (error && error.message === 'Unknown identity key') {
// create an error that the UI will pick up and ask the
// user if they want to re-negotiate
const buffer = window.dcodeIO.ByteBuffer.wrap(ciphertext);
const buffer = ByteBuffer.wrap(ciphertext);
errorToThrow = new textsecure.IncomingIdentityKeyError(
address.toString(),
buffer.toArrayBuffer(),

@ -4,6 +4,7 @@ import { EnvelopePlus } from './types';
import { MediumGroupResponseKeysMessage } from '../session/messages/outgoing';
import { getMessageQueue } from '../session';
import { PubKey } from '../session/types';
import _ from 'lodash';
async function handleSenderKeyRequest(
envelope: EnvelopePlus,
@ -59,14 +60,7 @@ async function handleSenderKey(envelope: EnvelopePlus, groupUpdate: any) {
}
async function handleNewGroup(envelope: EnvelopePlus, groupUpdate: any) {
const {
SenderKeyAPI,
StringView,
Whisper,
log,
textsecure,
Lodash: _,
} = window;
const { SenderKeyAPI, StringView, Whisper, log, textsecure } = window;
const senderIdentity = envelope.source;

@ -11,6 +11,8 @@ import { StringUtils } from '../session/utils';
import { MultiDeviceProtocol, SessionProtocol } from '../session/protocols';
import { PubKey } from '../session/types';
import ByteBuffer from 'bytebuffer';
async function unpairingRequestIsLegit(source: string, ourPubKey: string) {
const { textsecure, storage, lokiFileServerAPI } = window;
@ -204,7 +206,7 @@ async function handleAuthorisationForSelf(
}
function parseContacts(arrbuf: ArrayBuffer): Array<any> {
const buffer = new window.dcodeIO.ByteBuffer();
const buffer = new ByteBuffer();
buffer.append(arrbuf);
buffer.offset = 0;
buffer.limit = arrbuf.byteLength;
@ -270,9 +272,14 @@ export async function handleContacts(
window.log.info('contact sync');
// const { blob } = contacts;
if (!contacts.data) {
window.log.error('Contacts without data');
return;
}
const attachmentPointer = {
contacts,
data: window.dcodeIO.ByteBuffer.wrap(contacts.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer
data: ByteBuffer.wrap(contacts.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer
};
const contactDetails = parseContacts(attachmentPointer.data);

@ -3,6 +3,7 @@ import { SignalService } from '../protobuf';
import { removeFromCache } from './cache';
import { getEnvelopeId } from './common';
import _ from 'lodash';
import ByteBuffer from 'bytebuffer';
import { handleEndSession } from './sessionHandling';
import { handleMediumGroupUpdate } from './mediumGroups';
@ -131,7 +132,7 @@ async function handleSentMessage(
function handleAttachment(attachment: any) {
return {
...attachment,
data: window.dcodeIO.ByteBuffer.wrap(attachment.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer
data: ByteBuffer.wrap(attachment.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer
};
}

@ -2,6 +2,8 @@ import fetch from 'node-fetch';
import https from 'https';
import { Snode } from './snodePool';
import ByteBuffer from 'bytebuffer';
import { StringUtils } from '../utils';
const BAD_PATH = 'bad_path';
@ -43,7 +45,7 @@ async function encryptForRelay(
const reqObj = {
...destination,
ciphertext: dcodeIO.ByteBuffer.wrap(payload).toString('base64'),
ciphertext: ByteBuffer.wrap(payload).toString('base64'),
ephemeral_key: StringView.arrayBufferToHex(ctx.ephemeralKey),
};
@ -51,13 +53,11 @@ async function encryptForRelay(
}
async function makeGuardPayload(guardCtx: any) {
const ciphertextBase64 = window.dcodeIO.ByteBuffer.wrap(
guardCtx.ciphertext
).toString('base64');
const ciphertextBase64 = StringUtils.decode(guardCtx.ciphertext, 'base64');
const guardPayloadObj = {
ciphertext: ciphertextBase64,
ephemeral_key: window.StringView.arrayBufferToHex(guardCtx.ephemeralKey),
ephemeral_key: StringUtils.decode(guardCtx.ephemeralKey, 'hex'),
};
return guardPayloadObj;
}

@ -10,6 +10,7 @@ import {
} from './serviceNodeAPI';
import semver from 'semver';
import _ from 'lodash';
export type SnodeEdKey = string;
@ -34,7 +35,7 @@ const nodesForPubkey: { [key: string]: Array<SnodeEdKey> } = {};
async function tryGetSnodeListFromLokidSeednode(
seedNodes = window.seedNodeList
): Promise<Array<Snode>> {
const { log, Lodash: _ } = window;
const { log } = window;
if (!seedNodes.length) {
log.info(
@ -130,7 +131,7 @@ export async function markUnreachableForPubkey(
}
export function markNodeUnreachable(snode: Snode): void {
const { Lodash: _, log } = window;
const { log } = window;
randomSnodePool = _.without(randomSnodePool, snode);
log.warn(
@ -139,8 +140,6 @@ export function markNodeUnreachable(snode: Snode): void {
}
export async function getRandomSnodeAddress(): Promise<Snode> {
const { Lodash: _ } = window;
// resolve random snode
if (randomSnodePool.length === 0) {
// allow exceptions to pass through upwards without the unhandled promise rejection
@ -154,7 +153,8 @@ export async function getRandomSnodeAddress(): Promise<Snode> {
}
}
return _.sample(randomSnodePool);
// We know the pool can't be empty at this point
return _.sample(randomSnodePool) as Snode;
}
function compareSnodes(lhs: any, rhs: any): boolean {
@ -284,7 +284,7 @@ async function getSnodeListFromLokidSeednode(
}
async function refreshRandomPoolDetail(seedNodes: Array<any>): Promise<void> {
const { log, Lodash: _ } = window;
const { log } = window;
// are we running any _getAllVerionsForRandomSnodePool
if (stopGetAllVersionPromiseControl !== false) {
@ -303,6 +303,7 @@ async function refreshRandomPoolDetail(seedNodes: Array<any>): Promise<void> {
port: snode.storage_port,
pubkey_x25519: snode.pubkey_x25519,
pubkey_ed25519: snode.pubkey_ed25519,
version: '',
}));
log.info(
'LokiSnodeAPI::refreshRandomPool - Refreshed random snode pool with',

@ -62,9 +62,9 @@ export class SwarmPolling {
public removePubkey(pubkey: PubKey) {
if (this.pubkeys.indexOf(pubkey) !== -1) {
window.Lodash.remove(this.pubkeys, pubkey);
_.remove(this.pubkeys, pubkey);
} else if (this.groupPubkeys.indexOf(pubkey) !== -1) {
window.Lodash.remove(this.groupPubkeys, pubkey);
_.remove(this.groupPubkeys, pubkey);
}
}

Loading…
Cancel
Save