plebbit / seedit

A GUI for plebbit similar to old.reddit
https://seedit.eth.limo/#/
GNU General Public License v2.0
11 stars 2 forks source link

UI bug on voting #300

Closed windowshater closed 7 months ago

windowshater commented 7 months ago

I'm testing plebbit-js to make upvotes without using the UI and I realized that seedit it is not checking if the user already upvoted a specific post: Screenshot_20240311_231229 Screenshot_20240311_233226

If I try to upvote it the challenge will appear but even if I answer it, since I already voted, the votes counter will not increase, which is fine to avoid vote spamming. Here is the code that I'm using to vote:

import Plebbit from "@plebbit/plebbit-js";
import fs from "fs";
import readlineSync from "readline-sync";
async function test() {
    const options = {
        ipfsHttpClientsOptions: ["http://localhost:5001/api/v0"],
    };
    const plebbit = await Plebbit(options);
    plebbit.on("error", console.log);
    const signer = await plebbit.createSigner({
        privateKey: "...",
        type: "ed25519",
    });
    const vote = await plebbit.createVote({
        signer: signer,
        vote: 1,
        subplebbitAddress: "plebtoken.eth",
        commentCid: "QmbU2XsxFNd6pdfb6eCgz7iei3njQafzd8qHddNHo5kLXd",
    });
    try {
        console.log("getting challenge");
        vote.on("challenge", async (challengeMessage, _vote) => {
            console.log(_vote);
            console.log(challengeMessage);
            const challengeAnswers = await askUserForChallengeAnswers(
                challengeMessage.challenges[0].challenge
            );
            console.log(challengeAnswers);
            await vote.publishChallengeAnswers(challengeAnswers);
        });
        vote.on("challengeverification", console.log);
        await vote.publish();
    } catch (e) {
        console.log(e);
    }
}
async function askUserForChallengeAnswers(challenge) {
    return new Promise(async (resolve) => {
        const timestamp = new Date().toISOString().replace(/[:.]/g, "_");
        const imagePath = `image_${timestamp}.txt`;
        const imageData = challenge.split(";base64,").pop();
        const imageBuffer = Buffer.from(imageData, "base64");
        fs.writeFileSync(imagePath, imageBuffer, "utf-8");
        const userInput = readlineSync.question(
            "Type the letters you see in the image: "
        );
        resolve([userInput]);
    });
}

test();
estebanabaroa commented 7 months ago

plebbit.createVote({vote: 1}) does not increment the vote by 1, rather it sets the vote to 1. setting the vote to 1 multiple times does nothing.

an author's vote can be undefined, 0, 1 or -1. it can never be 2.

windowshater commented 7 months ago

I see. But the seedit UI still not checking if I already upvoted or downvoted a specific post without using seedit.

estebanabaroa commented 7 months ago

I see. But the seedit UI still not checking if I already upvoted or downvoted a specific post without using seedit.

correct, the plebbit protocol at the moment has no way to fetch who upvoted a comment or not. the sub owner has this data themselves in their sub database, but does not share it because it would be too resource intensive. It only shares the current total upvotes and downvotes, not each individual vote.

so there's no way to sync the upvotes of an author between 2 devices, because there's no way to fetch votes. there's also no way to audit which authors voted on a post if you're not the sub owner.

we might add some auditing tools at some point, but it will be very slow to fetch, and wont update in real time, because it's just too much resources to share each votes. the current plebbit design makes some compromises to be able to fetch stuff fast and be infinitely scalable.

tldr if you vote once from a client using the same author, it wont show that you voted on another client. and if you vote again, it will do nothing, because you already voted and the sub owner db keeps track of that.