2024-05-31 09:54:39 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2024-09-12 14:57:53 +00:00
|
|
|
// For pretty printing during debug
|
|
|
|
// If `go generate` is run, it'll generate the necessary function and data for pretty printing
|
|
|
|
//go:generate stringer -type NoteTarget
|
|
|
|
|
2024-06-06 11:54:50 +00:00
|
|
|
// What feed a note is targeting (public, home, followers or dm)
|
2024-05-31 09:54:39 +00:00
|
|
|
type NoteTarget uint8
|
|
|
|
|
|
|
|
const (
|
2024-06-06 11:54:50 +00:00
|
|
|
// The note is intended for the public
|
2024-09-18 08:54:04 +00:00
|
|
|
NOTE_TARGET_PUBLIC NoteTarget = 0
|
2024-06-06 11:54:50 +00:00
|
|
|
// The note is intended only for the home screen
|
|
|
|
// not really any idea what the difference is compared to public
|
|
|
|
// Maybe home notes don't show up on the server feed but still for everyone's home feed if it reaches them via follow or boost
|
2024-09-18 08:54:04 +00:00
|
|
|
NOTE_TARGET_HOME NoteTarget = 1 << iota
|
2024-06-06 11:54:50 +00:00
|
|
|
// The note is intended only for followers
|
2024-05-31 09:54:39 +00:00
|
|
|
NOTE_TARGET_FOLLOWERS
|
2024-06-06 11:54:50 +00:00
|
|
|
// The note is intended only for a DM to one or more targets
|
2024-05-31 09:54:39 +00:00
|
|
|
NOTE_TARGET_DM
|
|
|
|
)
|
|
|
|
|
2024-06-06 11:54:50 +00:00
|
|
|
// Converts the NoteTarget value into a type the DB can use
|
2024-05-31 09:54:39 +00:00
|
|
|
func (n *NoteTarget) Value() (driver.Value, error) {
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
2024-06-06 11:54:50 +00:00
|
|
|
// Converts the raw value from the DB into a NoteTarget
|
2024-05-31 09:54:39 +00:00
|
|
|
func (n *NoteTarget) Scan(value any) error {
|
|
|
|
vBig, ok := value.(int64)
|
|
|
|
if !ok {
|
|
|
|
return errors.New("not an int64")
|
|
|
|
}
|
|
|
|
*n = NoteTarget(vBig)
|
|
|
|
return nil
|
|
|
|
}
|