src/utils/skynet-ops.js
// Handles a user's like/unlike action.
Handles a user's like/unlike action.
Handles a user ' s like / unlike action .
async function handleLikeProposal(proposalsLiked, likedHowabout, header, creatorPublicKey, mySkyInstance, dispatch) {
    try {
        let res = [];
        console.debug(`Handling Like Action: currentLikes=${JSON.stringify(proposalsLiked)}`);
        const firstTimeLike = proposalsLiked.findIndex((k) => k.skylink === likedHowabout.skylink) < 0;
        if (firstTimeLike) {
            console.debug(`Saving like to SkyDB and MySky.`);
            const likedContent = {skylink: likedHowabout.skylink};
            proposalsLiked.push(likedContent);
            const resLikes = await writeJsonToMySky(mySkyInstance, MYSKY_LIKES_FILE_PATH, proposalsLiked);
            dispatch({type: SET_MYSKY_USER_PROPOSALS_LIKED, payload: resLikes.data});
            const modifiedLikes = likedHowabout.likes <= 0 ? 1 : likedHowabout.likes + 1
            res = await storeHowAbout(likedHowabout.skylink, null, modifiedLikes, header, creatorPublicKey, dispatch);
        } else {
            console.debug(`Removing like from SkyDB and MySky.`);
            const filtered = proposalsLiked.filter(h => h.skylink !== likedHowabout.skylink);
            await writeJsonToMySky(mySkyInstance, MYSKY_LIKES_FILE_PATH, filtered);
            dispatch({type: ActionTypes.SET_MYSKY_USER_PROPOSALS_LIKED, payload: filtered});
            const modifiedLikes = likedHowabout.likes <= 0 ? 0 : likedHowabout.likes - 1;
            res = await storeHowAbout(likedHowabout.skylink,null, modifiedLikes, header, creatorPublicKey, dispatch);
        }
        dispatch({type: ActionTypes.SET_PROPOSAL_RECORDS, payload: res.data});
        await recordInteraction(likedHowabout.skylink, 'updatedLikesAction'); 
    } catch (e) {
        console.error(`Error liking proposal: ${e.message}`);
    }
}
async function handleLikeProposal ( proposalsLiked , likedHowabout , header , creatorPublicKey , mySkyInstance , dispatch ) { try { let res = [ ] ; console . debug ( ` ${ JSON . stringify ( proposalsLiked ) } ` ) ; const firstTimeLike = proposalsLiked . findIndex ( ( k ) => k . skylink === likedHowabout . skylink ) < 0 ; if ( firstTimeLike ) { console . debug ( ` ` ) ; const likedContent = { skylink : likedHowabout . skylink } ; proposalsLiked . push ( likedContent ) ; const resLikes = await writeJsonToMySky ( mySkyInstance , MYSKY_LIKES_FILE_PATH , proposalsLiked ) ; dispatch ( { type : SET_MYSKY_USER_PROPOSALS_LIKED , payload : resLikes . data } ) ; const modifiedLikes = likedHowabout . likes <= 0 ? 1 : likedHowabout . likes + 1 res = await storeHowAbout ( likedHowabout . skylink , null , modifiedLikes , header , creatorPublicKey , dispatch ) ; } else { console . debug ( ` ` ) ; const filtered = proposalsLiked . filter ( h => h . skylink !== likedHowabout . skylink ) ; await writeJsonToMySky ( mySkyInstance , MYSKY_LIKES_FILE_PATH , filtered ) ; dispatch ( { type : ActionTypes . SET_MYSKY_USER_PROPOSALS_LIKED , payload : filtered } ) ; const modifiedLikes = likedHowabout . likes <= 0 ? 0 : likedHowabout . likes - 1 ; res = await storeHowAbout ( likedHowabout . skylink , null , modifiedLikes , header , creatorPublicKey , dispatch ) ; } dispatch ( { type : ActionTypes . SET_PROPOSAL_RECORDS , payload : res . data } ) ; await recordInteraction ( likedHowabout . skylink , 'updatedLikesAction' ) ; } catch ( e ) { console . error ( ` ${ e . message } ` ) ; } }
Handles a user's like/unlike action.
Handles a user ' s like / unlike action .
// Determine if the user has liked the first time or unlike a previous one. // Save user's like to MySky and increase like counter on skapp's SkyDB. // User // Skapp // Remove user's like from MySky and decrease like counter on skapp's SkyDB. // User // Skapp // Tell contentRecord that we updated the likes // TODO move to centralized const file.