Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI bug on voting #300

Closed
windowshater opened this issue Mar 12, 2024 · 3 comments
Closed

UI bug on voting #300

windowshater opened this issue Mar 12, 2024 · 3 comments

Comments

@windowshater
Copy link

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
Copy link
Member

estebanabaroa commented Mar 12, 2024

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
Copy link
Author

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

@estebanabaroa
Copy link
Member

estebanabaroa commented Mar 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants