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

No unvote button #89

Open
hjek opened this issue Dec 22, 2017 · 14 comments
Open

No unvote button #89

hjek opened this issue Dec 22, 2017 · 14 comments

Comments

@hjek
Copy link
Contributor

hjek commented Dec 22, 2017

There's no unvote button after voting for an item. HN has this now, but I can't remember seeing it there before. (I'll keep an eye out to see approximately how long they let you unvote for.)

@hjek
Copy link
Contributor Author

hjek commented Dec 24, 2017

More info on how unvoting works, in particular for down votes.

@matthewwiese
Copy link
Member

I'm interested in giving this feature a shot.

From what I can tell this chunk of code:

(= votejs* "
function byId(id) {
  return document.getElementById(id);
}

function vote(node) {
  var v = node.id.split(/_/);   // {'up', '123'}
  var item = v[1];

  // adjust score
  var score = byId('score_' + item);
  var newscore = parseInt(score.innerHTML) + (v[0] == 'up' ? 1 : -1);
  score.innerHTML = newscore + (newscore == 1 ? ' point' : ' points');

  // hide arrows
  byId('up_'   + item).style.visibility = 'hidden';
  try { byId('down_' + item).style.visibility = 'hidden'; }
  catch(err) {} // ignore

  // ping server
  var ping = new Image();
  ping.src = node.href;

  return false; // cancel browser nav
} ")

Seems to be the Javascript vote logic. Would a rudimentary unvote look something like this?

  // enable unvote
  byId('unvote_' + item).style.visibility = 'visible';
  // readjust score
  etc...

I'm still getting used to the codebase so anybody with more insight into this please do chime in! 😄

@akkartik
Copy link
Member

akkartik commented Mar 5, 2018

Sadly, Javascript is not one of my strengths. (Though I'm learning it for $DAY_JOB..)

Most of the code above is for just cosmetic rendering, if I recall correctly. The key is the ping variable which performs a request to the server. So we need to provide a URL to the 'unvote' link that the Arc server can handle and perform an unvote for.

@matthewwiese
Copy link
Member

I'm beginning to get a better idea I think...

There are various functions like votelink, vote-url, canvote, and logvote that I need to dig deeper into to better understand -- perhaps a repurposing of canvote into a canunvote, among other things.

A lot more difficult than simply fiddling with some Javascript... 😅

@hjek
Copy link
Contributor Author

hjek commented Mar 6, 2018 via email

@akkartik
Copy link
Member

akkartik commented Mar 6, 2018

In the backend votes aren't just counted. Instead, each item contains a list of profiles who voted on it, and each profile has a list of (recent) items they voted on. I imagine (though I haven't actually checked) that you just have to rem the appropriate item from both. If it doesn't exist the rem will just do nothing.

@hjek
Copy link
Contributor Author

hjek commented Mar 6, 2018 via email

@akkartik
Copy link
Member

akkartik commented Mar 6, 2018

Ah, you're right.

Looking at vote-for, I see that we "always" increment score, but also sometimes increment sockvotes. Then (realscore i) is defined as (- i!score i!sockvotes).

So perhaps an unvote function would need to replicate the logic in vote-for. Decrement score, and sometimes decrement sockvotes.

It's going to be ugly at the start to have all this duplicated code. But once it's working and tested we can think about how to factor out common code.

@rocketnia
Copy link
Member

Seems to me if the list of users who voted on something is already stored, the information about whether their vote was considered a sockpuppet vote could be stored alongside it. Then you can decrement sockvotes if the entry you're removing has that note attached to it.

@hjek
Copy link
Contributor Author

hjek commented Sep 19, 2018

I have taken a shot at unvoting here. I haven't really tested it yet, but it would be nice if anyone would try it out and tell me everything that's wrong with it 🪲

(I haven't added any JavaScript to make it behave smoothly in the browser yet. Also, it may be worth noting that HN has dropped the JS code to update the score.)

Seems to me if the list of users who voted on something is already stored, the information about whether their vote was considered a sockpuppet vote could be stored alongside it.

I haven't yet touched the format the votes are stored in anywhere. It might be a good idea to remember which votes are sockpupptes, but how? A vote doesn't have an id. And there's not even a vote template. Votes are just scattered information throughout profiles, items and global variables.

And there's no way of deriving karma/score from the votes, because karma/score is just state.

So perhaps an unvote function would need to replicate the logic in vote-for. Decrement score, and sometimes decrement sockvotes.

That's what I've done.

@hjek
Copy link
Contributor Author

hjek commented Sep 19, 2018

Also, HN's JavaScript code is up for grabs when adding this unvoting stuff. As dang writes:

Re HN's Javascript: you can use/adapt it however you like!

@hjek
Copy link
Contributor Author

hjek commented Sep 20, 2018

A lot more difficult than simply fiddling with some Javascript... sweat_smile

@matthewwiese, if you're still interested in doing the JavaScript fiddling part, I think now's the time.

@hjek
Copy link
Contributor Author

hjek commented Sep 29, 2018

Unvoting is working decently now in the Knark fork.

I think I prefer focusing on actually making the new features, so if someone else feels like porting this to Anarki, that would be great.

@matthewwiese
Copy link
Member

@hjek Apologies for not seeing your reply sooner! Unfortunately, I don't have the time atm to devote to this, despite what I imagine to be a relatively easy fix.

@kennethrapp kennethrapp added this to Requested in Arc Forum Updates Aug 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants