src/utils/skynet-ops.js
// Saves a user's how about to skydb.
Saves a user's how about to skydb.
Saves a user ' s how about to skydb .
async function storeHowAbout(howAboutSkylink, commentsSkylink, likes, header, creatorPublicKey, dispatch) {
    try {
        const howAboutJson = {
            skylink: howAboutSkylink,
            commentsSkylink: commentsSkylink,
            likes: likes,
            metadata: {
                header: header ?? "NOT_PROVIDED",
                creator: creatorPublicKey ?? generateDynamicName(),
                creationDate: new Date().toUTCString()
            }
        };
        console.debug(`Storing howabout to SkyDB:
            howabout=${JSON.stringify(howAboutJson)}
            howaboutSkylink=${JSON.stringify(howAboutSkylink)}
            likes=${likes}`);
        const {data} = await readJsonFromSkyDB(SKAPP_DATA_KEY);
        const index = data.howabouts.findIndex(h => h.skylink === howAboutSkylink);
        if (index >= 0) {
            const old = data.howabouts[index];
            howAboutJson.metadata.creationDate = old.metadata.creationDate;
            howAboutJson.metadata.creator = old.metadata.creator;
            howAboutJson.commentsSkylink = commentsSkylink ? commentsSkylink : old.commentsSkylink;
            if (likes === null) {
                howAboutJson.likes = old.likes;
            }
            data.howabouts[index] = howAboutJson;
        } else {
            data.howabouts.push(howAboutJson);
        }
        const res = await writeJsonToSkyDB(SKAPP_DATA_KEY, data);
        console.debug(`Stored proposals into SkyDB:\n\t${JSON.stringify(res)}`);
        return res;
    } catch (e) {
        console.error(`Error saving skapp member to SkyDB: ${e.message}`);
    }
}
async function storeHowAbout ( howAboutSkylink , commentsSkylink , likes , header , creatorPublicKey , dispatch ) { try { const howAboutJson = { skylink : howAboutSkylink , commentsSkylink : commentsSkylink , likes : likes , metadata : { header : header ?? "NOT_PROVIDED" , creator : creatorPublicKey ?? generateDynamicName ( ) , creationDate : new Date ( ) . toUTCString ( ) } } ; console . debug ( ` ${ JSON . stringify ( howAboutJson ) } ${ JSON . stringify ( howAboutSkylink ) } ${ likes } ` ) ; const { data } = await readJsonFromSkyDB ( SKAPP_DATA_KEY ) ; const index = data . howabouts . findIndex ( h => h . skylink === howAboutSkylink ) ; if ( index >= 0 ) { const old = data . howabouts [ index ] ; howAboutJson . metadata . creationDate = old . metadata . creationDate ; howAboutJson . metadata . creator = old . metadata . creator ; howAboutJson . commentsSkylink = commentsSkylink ? commentsSkylink : old . commentsSkylink ; if ( likes === null ) { howAboutJson . likes = old . likes ; } data . howabouts [ index ] = howAboutJson ; } else { data . howabouts . push ( howAboutJson ) ; } const res = await writeJsonToSkyDB ( SKAPP_DATA_KEY , data ) ; console . debug ( ` \n \t ${ JSON . stringify ( res ) } ` ) ; return res ; } catch ( e ) { console . error ( ` ${ e . message } ` ) ; } }
Saves a user's how about to skydb.
Saves a user ' s how about to skydb .
// FIX: proposals records must be updated first: