gotextlog

gotextlog
git clone https://git.ryansepassi.com/git/gotextlog.git
Log | Files | Refs | README

types.go (6113B)


      1 package textlog
      2 
      3 import (
      4 	"encoding/json"
      5 	"time"
      6 )
      7 
      8 type ThemeName string
      9 
     10 const (
     11 	ThemeAuto  ThemeName = "auto"
     12 	ThemeLight ThemeName = "light"
     13 	ThemeDark  ThemeName = "dark"
     14 )
     15 
     16 type Post struct {
     17 	ID         int           `json:"id"`
     18 	TopID      *int          `json:"top_id"`
     19 	Body       string        `json:"body"`
     20 	CreatedAt  time.Time     `json:"created_at"`
     21 	ParentID   *int          `json:"parent_id"`
     22 	ReplyCount int           `json:"reply_count"`
     23 	Tags       []string      `json:"tags"`
     24 	Mentions   []string      `json:"mentions"`
     25 	URL        string        `json:"url"`
     26 	APIURL     string        `json:"api_url"`
     27 	Author     UserReference `json:"author"`
     28 	Parent     *Post         `json:"parent,omitempty"`
     29 }
     30 
     31 type Reply struct {
     32 	Post
     33 	Depth int `json:"depth"`
     34 }
     35 
     36 type Profile struct {
     37 	Handle             string    `json:"handle"`
     38 	Bio                string    `json:"bio"`
     39 	CreatedAt          time.Time `json:"created_at"`
     40 	PostCount          int       `json:"post_count"`
     41 	RepliesCount       int       `json:"replies_count"`
     42 	FollowerCount      int       `json:"follower_count"`
     43 	FollowingUserCount int       `json:"following_user_count"`
     44 	FollowingTagCount  int       `json:"following_tag_count"`
     45 	FollowingCount     int       `json:"following_count"`
     46 	BlockedUserCount   *int      `json:"blocked_user_count,omitempty"`
     47 	BlockedTagCount    *int      `json:"blocked_tag_count,omitempty"`
     48 	URL                string    `json:"url"`
     49 	APIURL             string    `json:"api_url"`
     50 }
     51 
     52 type UserReference struct {
     53 	Handle string `json:"handle"`
     54 	URL    string `json:"url"`
     55 	APIURL string `json:"api_url"`
     56 }
     57 
     58 type TagReference struct {
     59 	Tag           string `json:"tag"`
     60 	PostCount     int    `json:"post_count"`
     61 	FollowerCount int    `json:"follower_count"`
     62 	URL           string `json:"url"`
     63 	APIURL        string `json:"api_url"`
     64 }
     65 
     66 type CurrentUser struct {
     67 	Handle        string `json:"handle"`
     68 	Email         string `json:"email"`
     69 	Bio           string `json:"bio"`
     70 	EmailVerified bool   `json:"email_verified"`
     71 	CanPost       bool   `json:"can_post"`
     72 }
     73 
     74 type Pagination struct {
     75 	NextCursor *string `json:"next_cursor"`
     76 }
     77 
     78 type Collection[T any] struct {
     79 	Data       []T        `json:"data"`
     80 	Pagination Pagination `json:"pagination"`
     81 }
     82 
     83 type ActivityType string
     84 
     85 const (
     86 	ActivityPost       ActivityType = "post"
     87 	ActivityReply      ActivityType = "reply"
     88 	ActivityMention    ActivityType = "mention"
     89 	ActivityUserFollow ActivityType = "user_follow"
     90 	ActivityTagFollow  ActivityType = "tag_follow"
     91 	ActivitySignup     ActivityType = "signup"
     92 )
     93 
     94 type Activity struct {
     95 	ID        string          `json:"id"`
     96 	Type      ActivityType    `json:"type"`
     97 	CreatedAt time.Time       `json:"created_at"`
     98 	Unread    bool            `json:"unread"`
     99 	Payload   json.RawMessage `json:"payload"`
    100 }
    101 
    102 func (a Activity) Post() (Post, bool) {
    103 	return decodePostCandidate(a.Payload)
    104 }
    105 
    106 type ActivityCollection struct {
    107 	Data       []Activity `json:"data"`
    108 	Pagination Pagination `json:"pagination"`
    109 	HasUnread  bool       `json:"has_unread"`
    110 }
    111 
    112 type ReplyCollection = Collection[Reply]
    113 
    114 type Envelope[T any] struct {
    115 	Data T `json:"data"`
    116 }
    117 
    118 type Session struct {
    119 	Token     string      `json:"token"`
    120 	ExpiresAt time.Time   `json:"expires_at"`
    121 	User      CurrentUser `json:"user"`
    122 }
    123 
    124 type KeyChallenge struct {
    125 	ChallengeID string    `json:"challenge_id"`
    126 	Message     []byte    `json:"message"`
    127 	ExpiresAt   time.Time `json:"expires_at"`
    128 	Registered  bool      `json:"registered"`
    129 }
    130 
    131 type ReportReason string
    132 
    133 const (
    134 	ReportHarassment    ReportReason = "harassment"
    135 	ReportSpam          ReportReason = "spam"
    136 	ReportImpersonation ReportReason = "impersonation"
    137 	ReportOther         ReportReason = "other"
    138 )
    139 
    140 type SentResult struct {
    141 	Sent bool `json:"sent"`
    142 }
    143 
    144 type RevokedResult struct {
    145 	Revoked bool `json:"revoked"`
    146 }
    147 
    148 type DeletedResult struct {
    149 	Deleted bool `json:"deleted"`
    150 }
    151 
    152 type FollowingResult struct {
    153 	Following bool `json:"following"`
    154 }
    155 
    156 type BlockedResult struct {
    157 	Blocked bool `json:"blocked"`
    158 }
    159 
    160 type ReportedResult struct {
    161 	Reported bool `json:"reported"`
    162 }
    163 
    164 type APIErrorBody struct {
    165 	Error APIErrorDetail `json:"error"`
    166 }
    167 
    168 type APIErrorDetail struct {
    169 	Code    string `json:"code"`
    170 	Message string `json:"message"`
    171 }
    172 
    173 type FeedKind string
    174 
    175 const (
    176 	FeedForYou FeedKind = "for-you"
    177 	FeedToMe   FeedKind = "to-me"
    178 	FeedHot    FeedKind = "hot"
    179 	FeedLatest FeedKind = "latest"
    180 )
    181 
    182 type ScreenKind string
    183 
    184 const (
    185 	ScreenFeed     ScreenKind = "feed"
    186 	ScreenSearch   ScreenKind = "search"
    187 	ScreenPost     ScreenKind = "post"
    188 	ScreenProfile  ScreenKind = "profile"
    189 	ScreenTag      ScreenKind = "tag"
    190 	ScreenLive     ScreenKind = "live"
    191 	ScreenCompose  ScreenKind = "compose"
    192 	ScreenLogin    ScreenKind = "login"
    193 	ScreenAccount  ScreenKind = "account"
    194 	ScreenSettings ScreenKind = "settings"
    195 	ScreenHelp     ScreenKind = "help"
    196 )
    197 
    198 // Screen contains the fields used by the corresponding discriminated union
    199 // member in the reference client. Kind determines which optional fields apply.
    200 type Screen struct {
    201 	Kind   ScreenKind `json:"kind"`
    202 	Feed   FeedKind   `json:"feed,omitempty"`
    203 	Query  string     `json:"query,omitempty"`
    204 	ID     int        `json:"id,omitempty"`
    205 	Handle string     `json:"handle,omitempty"`
    206 	Tag    string     `json:"tag,omitempty"`
    207 	Parent *Post      `json:"parent,omitempty"`
    208 	Edit   *Post      `json:"edit,omitempty"`
    209 }
    210 
    211 type Status struct {
    212 	Text  string `json:"text"`
    213 	Error bool   `json:"error,omitempty"`
    214 }
    215 
    216 type AppState struct {
    217 	Stack  []Screen `json:"stack"`
    218 	Status *Status  `json:"status,omitempty"`
    219 }
    220 
    221 type AppActionType string
    222 
    223 const (
    224 	ActionPush    AppActionType = "push"
    225 	ActionReplace AppActionType = "replace"
    226 	ActionBack    AppActionType = "back"
    227 	ActionStatus  AppActionType = "status"
    228 )
    229 
    230 // AppAction contains the fields used by the corresponding discriminated union
    231 // member in the reference client. Type determines which optional fields apply.
    232 type AppAction struct {
    233 	Type   AppActionType `json:"type"`
    234 	Screen *Screen       `json:"screen,omitempty"`
    235 	Text   *string       `json:"text,omitempty"`
    236 	Error  bool          `json:"error,omitempty"`
    237 }