1package boards23import (4 "errors"5 "strings"6 "time"78 "gno.land/p/nt/ufmt/v0"9)1011// NewThread creates a new board thread.12func NewThread(b *Board, creator address, title, body string) (*Post, error) {13 if b == nil {14 return nil, errors.New("thread requires a parent board")15 }1617 if !creator.IsValid() {18 return nil, ufmt.Errorf("invalid thread creator address: %s", creator)19 }2021 title = strings.TrimSpace(title)22 if title == "" {23 return nil, errors.New("thread title is required")24 }2526 body = strings.TrimSpace(body)27 if body == "" {28 return nil, errors.New("thread body is required")29 }3031 id := b.ThreadsSequence.Next()32 return &Post{33 ID: id,34 ThreadID: id,35 Board: b,36 Title: title,37 Body: body,38 Replies: NewPostStorage(),39 Reposts: NewRepostStorage(),40 Flags: NewFlagStorage(),41 Creator: creator,42 CreatedAt: time.Now(),43 }, nil44}4546// MustNewThread creates a new thread or panics on error.47func MustNewThread(b *Board, creator address, title, body string) *Post {48 t, err := NewThread(b, creator, title, body)49 if err != nil {50 panic(err)51 }52 return t53}5455// NewRepost creates a new thread that is a repost of a thread from another board.56func NewRepost(thread *Post, dst *Board, creator address) (*Post, error) {57 if thread == nil {58 return nil, errors.New("thread to repost is required")59 }6061 if thread.Board == nil {62 return nil, errors.New("original thread has no board assigned")63 }6465 if dst == nil {66 return nil, errors.New("thread repost requires a destination board")67 }6869 if IsRepost(thread) {70 return nil, errors.New("reposting a thread that is a repost is not allowed")71 }7273 if !IsThread(thread) {74 return nil, errors.New("post must be a thread to be reposted to another board")75 }7677 if !creator.IsValid() {78 return nil, ufmt.Errorf("invalid thread repost creator address: %s", creator)79 }8081 id := dst.ThreadsSequence.Next()82 return &Post{83 ID: id,84 ThreadID: id,85 ParentID: thread.ID,86 OriginalBoardID: thread.Board.ID,87 Board: dst,88 Replies: NewPostStorage(),89 Reposts: NewRepostStorage(),90 Flags: NewFlagStorage(),91 Creator: creator,92 CreatedAt: time.Now(),93 }, nil94}9596// MustNewRepost creates a new thread that is a repost of a thread from another board or panics on error.97func MustNewRepost(thread *Post, dst *Board, creator address) *Post {98 r, err := NewRepost(thread, dst, creator)99 if err != nil {100 panic(err)101 }102 return r103}104Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.