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

[r/boards] initialize ranking #3226

Open
10 tasks
salmad3 opened this issue Nov 28, 2024 · 2 comments
Open
10 tasks

[r/boards] initialize ranking #3226

salmad3 opened this issue Nov 28, 2024 · 2 comments

Comments

@salmad3
Copy link
Member

salmad3 commented Nov 28, 2024

Context:

A simple ranking system is essential for the initial version of r/boards. This system will apply to posts (threads and comments) within boards to allow users to vote on content to determine its visibility and importance. The ranking mechanism should integrate with the existing Permissions interface and focus on core functionality for the MVP.

Acceptance Criteria:

  • The boards realm homepage includes a README controlled by the AdminDAO (without automatic listing of new or top) boards.

    Like other implementations, administration can use an interim solution (e.g., manual). The listing is also manual to start.

  • Includes a Vote struct to represent user votes:

    Example
     type Vote struct {
         UserID    Address
         Direction int     // 1 for upvote, -1 for downvote
         Timestamp time.Time
         TokensDonated uint64 // Only for public boards
     }
  • A Votes field in the Post struct stores vote information:

    Example
    type Post struct {
        // ... existing fields
        Votes []Vote
    }
    <details>
  • Leverages a simple CalculateScore function:

    • For private boards: Total upvotes minus downvotes
    • For public boards: Total tokens donated for upvotes minus total tokens donated for downvotes
  • Provides a VoteOn method for Post that:

    • Checks if the user has permission to vote using bp.HasPermission()
    • Adds or updates the user's vote
    • Recalculates the score

    Example
    func (p *Post) VoteOn(bp *BoardsRealm, user User, direction int, tokensDonated uint64) error {
        if !bp.HasPermission(user, "vote", []interface{}{p.ID}) {
            return errors.New("user does not have permission to vote on this post")
        }
    
        var vote *Vote
        for i, v := range p.Votes {
            if v.UserID == user.Address {
                vote = &p.Votes[i]
                break
            }
        }
        if vote == nil {
            vote = &Vote{
                UserID:    user.Address,
                Timestamp: time.Now(),
            }
            p.Votes = append(p.Votes, *vote)
        }
    
        vote.Direction = direction
        vote.TokensDonated += tokensDonated
    
        p.recalculateScore()
    
        return nil
    }
    
    func (p *Post) recalculateScore() {
        var score int64
        for _, vote := range p.Votes {
            if vote.Direction > 0 {
                score += int64(vote.TokensDonated)
            } else {
                score -= int64(vote.TokensDonated)
            }
        }
        p.Score = score
    }
  • Implements different voting mechanisms for private and public boards:

    • Private boards: Each member can vote only once per post
    • Public boards: Users can vote multiple times by donating GNOT (minimum 0.01 GNOT)
  • For public boards, a mechanism is available to lock donated tokens in the board's treasury

  • Includes a GetTopPosts function that returns a sorted list of posts based on calculated scores

  • Unit tests to verify the basic ranking system's behavior

  • Implements a simple API endpoint to retrieve top posts for a given board

Notes:

  • Hacker News is a good reference for this.
  • Time decay factor for post scores is not included in this initial implementation to reduce complexity
  • Advanced features like complex scoring mechanisms, custom ranking (such as via moderation groups or other methods) or a ranking algorithm are postponed for future versions
  • Search functionality will be implemented off-chain for the MVP
@jefft0
Copy link
Contributor

jefft0 commented Nov 28, 2024

Hello @salmad3 . You mention Hacker News as a reference. There is usually a consensus view on what is accurate technical discussion. But for a general message board, I don't think there should be a "one size fits all" single ranking system. It would be better to have separate moderation groups with their own perspective, and a user can choose which moderation group to subscribe to.

@salmad3
Copy link
Member Author

salmad3 commented Nov 28, 2024

Thanks @jefft0. That’s a good point. This idea was also brought up at some point, but we were thinking to start with a simpler method.

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

No branches or pull requests

2 participants