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] thread flagging #3481

Closed
5 tasks done
salmad3 opened this issue Jan 10, 2025 · 1 comment
Closed
5 tasks done

[r/boards] thread flagging #3481

salmad3 opened this issue Jan 10, 2025 · 1 comment

Comments

@salmad3
Copy link
Member

salmad3 commented Jan 10, 2025

Context

Flagging is a critical moderation function for identifying and managing inappropriate, spam, or otherwise undesirable content at the thread level. Threads are typically top-level posts within a board. Building on the broader flagging system, we now want to introduce thread-specific flagging that:

  • Allows authorized users (moderators, admins, owners) to flag entire threads.
  • Hides or restricts flagged threads once they reach a configurable threshold.
  • Integrates smoothly with the permissions system (HasPermission or WithPermission).

Acceptance Criteria

  • Struct Updates

    • Extend the Thread struct (or Post with ParentID == 0) to include a Flags field of type []Flag, plus a Hidden boolean.

      Example
      type Thread struct {
          ThreadID   string
          Title      string
          Author     Address
          Content    string
          Timestamp  time.Time
          Flags      []Flag // appended for thread-level flags
          Hidden     bool
          // ... other potential fields
      }
      
      type Flag struct {
          User   Address
          Reason string
          Date   time.Time
      }
  • Flagging Function

    • Add a FlagThread(threadID string, reason string) function that:
      1. Checks if the caller has permission to flag threads (e.g., "flag:thread").

      2. Locates the thread by threadID.

      3. Appends a new Flag to the thread.Flags.

      4. If len(thread.Flags) >= ThreadFlagThreshold, set thread.Hidden = true.

      5. Returns an error if the thread is already hidden or if the caller lacks permission.

        Example
        func (br *BoardsRealm) FlagThread(caller Address, threadID string, reason string) error {
            if !br.HasPermission(caller, "flag:thread", []interface{}{threadID}) {
                return errors.New("caller does not have permission to flag threads")
            }
        
            thread := br.GetThreadByID(threadID)
            if thread == nil {
                return errors.New("thread not found")
            }
            if thread.Hidden {
               return errors.New("thread is already hidden")
            }
        
            newFlag := Flag{
                User:   caller,
                Reason: reason,
                Date:   time.Now(),
            }
            thread.Flags = append(thread.Flags, newFlag)
        
            if len(thread.Flags) >= br.Config.ThreadFlagThreshold {
                thread.Hidden = true
            }
        
            br.UpdateThread(thread)
            return nil
        }
  • Permissions

    • Must verify the correct permission key (e.g., "flag:thread").
    • By default, only moderators or admins can flag threads in the MVP.
  • Configuration

    • A ThreadFlagThreshold in BoardsRealmConfig, defaulting to 1 or a small integer.
    • Possibly overridden by a board-specific or AdminDAO-based setting later.
  • Tests

    • Confirm that a user with "flag:thread" can successfully flag a thread.
    • Ensure unauthorized users fail to flag.
    • Validate that a hidden thread cannot be flagged again.
    • Test repeated flags from the same user, invalid threadID, etc.

Notes

  • Initially, ThreadFlagThreshold might be set globally.
  • Future expansions:
    • Differing thresholds per board.
    • More detailed reason codes (e.g. “spam,” “abuse,” “off-topic”).
    • Automatic triggers for freezing a board if multiple threads get flagged quickly.
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

1 participant