Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit db29dbf

Browse files
committed
improve JSDoc
1 parent ea91a7e commit db29dbf

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

lib/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,4 @@ export const TOKEN_TYPES = {
533533

534534
export const LABEL_LEGACY_MESSAGE = '11';
535535
export const QUERY_LEGACY_MESSAGES_MAX_PAGESIZE = 150;
536-
export const UPDATE_MESSAGE_SUCESS_CODE = 1000;
536+
export const UPDATE_BODY_SUCESS_CODE = 1000;

lib/legacyMessages/helpers.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
import { encryptMessage, decryptMessageLegacy } from 'pmcrypto';
22
// import { fromUnixTime } from 'date-fns';
33

4-
import { LABEL_LEGACY_MESSAGE, QUERY_LEGACY_MESSAGES_MAX_PAGESIZE, UPDATE_MESSAGE_SUCESS_CODE } from '../constants';
4+
import { LABEL_LEGACY_MESSAGE, QUERY_LEGACY_MESSAGES_MAX_PAGESIZE, UPDATE_BODY_SUCESS_CODE } from '../constants';
55
import { chunk } from '../helpers/array';
66
import { wait } from '../helpers/promise';
77
import { noop } from '../helpers/function';
88

99
const fromUnixTime = (Time = 0) => new Date(Time * 1000);
1010

1111
const LEGACY_MESSAGES_CHUNK_SIZE = 5; // how many messages we want to decrypt and encrypt simultaneously
12+
const RELAX_TIME = 5 * 1000; // 5s . Time to wait (for other operations) after a batch of legacy messages has been migrated
1213

1314
/**
1415
* Given a list of legacy message IDs, fetch, decrypt, re-encrypt and send them to API
1516
* @param {Array<String>} messageIDs List of IDs of legacy messages
1617
* @param {AbortController.signal} signal { aborted: true/false }
17-
* @param {Function} obj.getMessage
18-
* @param {Function} obj.updateBody
19-
* @param {Function} obj.getPrivateKeys
18+
* @param {Function} obj.getMessage Retrive message from database by ID
19+
* @param {Function} obj.updateBody Replace body of a message identified by ID
20+
* @param {Function} obj.getPrivateKeys Get privateKeys corresponding to an address ID
2021
* @param {Function} obj.onError
22+
*
23+
* @return {Object} { noneMigratedInBatch: false is some message from the batch is succesfully migrated. True otherwise }
24+
*
25+
* @dev The keys returned by getPrivateKeys must have the method toPublic()
2126
*/
2227
const clearSome = async (messageIDs = [], { signal, getMessage, updateBody, getPrivateKeys, onError = noop }) => {
2328
if (!messageIDs.length) {
@@ -68,7 +73,7 @@ const clearSome = async (messageIDs = [], { signal, getMessage, updateBody, getP
6873
}
6974
// Send re-encrypted message to API
7075
const { Code } = await updateBody({ ID, Body: newBody });
71-
if (Code === UPDATE_MESSAGE_SUCESS_CODE) {
76+
if (Code === UPDATE_BODY_SUCESS_CODE) {
7277
noneMigratedInBatch = false;
7378
}
7479
return;
@@ -84,6 +89,15 @@ const clearSome = async (messageIDs = [], { signal, getMessage, updateBody, getP
8489

8590
/**
8691
* Fetch legacy messages, re-encrypt and send them to API
92+
* @param {AbortController.signal} signal { aborted: true/false }
93+
* @param {Number} page Legacy messages query parameter
94+
* @param {Function} obj.queryMessages Retrive legacy messages from database
95+
* @param {Function} obj.getMessage Retrive message from database by ID
96+
* @param {Function} obj.updateBody Replace body of a message identified by ID
97+
* @param {Function} obj.getPrivateKeys Get privateKeys corresponding to an address ID
98+
* @param {Function} obj.onError
99+
*
100+
* @dev The keys returned by getPrivateKeys must have the method toPublic()
87101
*/
88102
export const clearAll = async ({
89103
signal,
@@ -94,8 +108,6 @@ export const clearAll = async ({
94108
getPrivateKeys,
95109
onError
96110
}) => {
97-
const RELAX_TIME = 5 * 1000; // 5s
98-
99111
if (signal.aborted) {
100112
return;
101113
}

0 commit comments

Comments
 (0)