]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/news.go
patch: v0.10.24
[rbdr/mobius] / hotline / news.go
index 7a5c30c784338fb82680d4ca2002f7542067f7c2..38db97af42dee4f11a8731e0cdb740674a01b79b 100644 (file)
@@ -5,15 +5,22 @@ import (
        "crypto/rand"
        "encoding/binary"
        "sort"
-       "time"
 )
 
+const defaultNewsDateFormat = "Jan02 15:04" // Jun23 20:49
+
+const defaultNewsTemplate = `From %s (%s):
+
+%s
+
+__________________________________________________________`
+
 type ThreadedNews struct {
        Categories map[string]NewsCategoryListData15 `yaml:"Categories"`
 }
 
 type NewsCategoryListData15 struct {
-       Type     []byte `yaml:"Type"` //Size 2 ; Bundle (2) or category (3)
+       Type     []byte `yaml:"Type"` // Size 2 ; Bundle (2) or category (3)
        Count    []byte // Article or SubCategory count Size 2
        NameSize byte
        Name     string                            `yaml:"Name"`     //
@@ -53,6 +60,7 @@ func (newscat *NewsCategoryListData15) GetNewsArtListData() NewsArtListData {
 
        nald := NewsArtListData{
                ID:          []byte{0, 0, 0, 0},
+               Count:       len(newsArts),
                Name:        []byte{},
                Description: []byte{},
                NewsArtList: newsArtsPayload,
@@ -65,11 +73,11 @@ func (newscat *NewsCategoryListData15) GetNewsArtListData() NewsArtListData {
 type NewsArtData struct {
        Title         string `yaml:"Title"`
        Poster        string `yaml:"Poster"`
-       Date          []byte `yaml:"Date"`             //size 8
-       PrevArt       []byte `yaml:"PrevArt"`          //size 4
-       NextArt       []byte `yaml:"NextArt"`          //size 4
-       ParentArt     []byte `yaml:"ParentArt"`        //size 4
-       FirstChildArt []byte `yaml:"FirstChildArtArt"` //size 4
+       Date          []byte `yaml:"Date"`             // size 8
+       PrevArt       []byte `yaml:"PrevArt"`          // size 4
+       NextArt       []byte `yaml:"NextArt"`          // size 4
+       ParentArt     []byte `yaml:"ParentArt"`        // size 4
+       FirstChildArt []byte `yaml:"FirstChildArtArt"` // size 4
        DataFlav      []byte `yaml:"DataFlav"`         // "text/plain"
        Data          string `yaml:"Data"`
 }
@@ -86,11 +94,12 @@ type NewsArtListData struct {
        Name        []byte `yaml:"Name"`
        Description []byte `yaml:"Description"` // not used?
        NewsArtList []byte // List of articles                  Optional (if article count > 0)
+       Count       int
 }
 
 func (nald *NewsArtListData) Payload() []byte {
        count := make([]byte, 4)
-       binary.BigEndian.PutUint32(count, uint32(len(nald.NewsArtList)))
+       binary.BigEndian.PutUint32(count, uint32(nald.Count))
 
        out := append(nald.ID, count...)
        out = append(out, []byte{uint8(len(nald.Name))}...)
@@ -203,27 +212,7 @@ func (newscat *NewsCategoryListData15) nameLen() []byte {
        return []byte{uint8(len(newscat.Name))}
 }
 
-//type NewsPath struct {
-//     Paths []string
-//}
-//
-//func (np *NewsPath) Payload() []byte {
-//     var out []byte
-//
-//     count := make([]byte, 2)
-//     binary.BigEndian.PutUint16(count, uint16(len(np.Paths)))
-//
-//     out = append(out, count...)
-//     for _, p := range np.Paths {
-//             pLen := byte(len(p))
-//             out = append(out, []byte{0, 0}...) // what is this?
-//             out = append(out, pLen)
-//             out = append(out, []byte(p)...)
-//     }
-//
-//     return out
-//}
-
+// TODO: re-implement as bufio.Scanner interface
 func ReadNewsPath(newsPath []byte) []string {
        if len(newsPath) == 0 {
                return []string{}
@@ -250,25 +239,3 @@ func (s *Server) GetNewsCatByPath(paths []string) map[string]NewsCategoryListDat
        }
        return cats
 }
-
-// News article date field contains this structure:
-// Year                                        2
-// Milliseconds        2 (seriously?)
-// Seconds                     4
-func NewsDate() []byte {
-       t := time.Now()
-       ms := []byte{0, 0}
-       seconds := []byte{0, 0, 0, 0}
-
-       year := []byte{0, 0}
-       binary.BigEndian.PutUint16(year, uint16(t.Year()))
-
-       yearStart := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local)
-
-       binary.BigEndian.PutUint32(seconds, uint32(t.Sub(yearStart).Seconds()))
-
-       date := append(year, ms...)
-       date = append(date, seconds...)
-
-       return date
-}