...

Source file src/codeberg.org/tslocum/sriracha/model/model_subscription.go

Documentation: codeberg.org/tslocum/sriracha/model

     1  package model
     2  
     3  import (
     4  	"fmt"
     5  
     6  	. "codeberg.org/tslocum/sriracha/util"
     7  )
     8  
     9  type SubscriptionType int
    10  
    11  const (
    12  	SubscriptionAll     SubscriptionType = 0  // Subscribe to all new posts.
    13  	SubscriptionThreads SubscriptionType = -1 // Subscribe to new threads.
    14  )
    15  
    16  type Subscription struct {
    17  	ID      int
    18  	IP      string // For anti-spam protection. Cleared after 24 hours.
    19  	Confirm int64  // Timestamp when confirmation request was zent, or zero once confirmed.
    20  	Email   string // Email address.
    21  	Board   int    // Only set when Target is a SubscriptionType.
    22  	Target  int    // When greater than zero, Target is a post ID. Otherwise, Target is a SubscriptionType.
    23  }
    24  
    25  func (s *Subscription) Validate() error {
    26  	email := ParseEmail(s.Email)
    27  	if email == "" {
    28  		return fmt.Errorf("invalid email address")
    29  	} else if s.Board < 0 {
    30  		return fmt.Errorf("invalid board %d", s.Board)
    31  	} else if s.Target < int(SubscriptionThreads) {
    32  		return fmt.Errorf("invalid subscription target %d", s.Target)
    33  	}
    34  	return nil
    35  }
    36  

View as plain text