mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-06-30 22:18:39 -04:00
Fix #50, implementation of nested replies
This commit is contained in:
parent
683f07fd79
commit
386adc8857
@ -22,4 +22,6 @@ type Reply struct {
|
|||||||
Replies []Reply
|
Replies []Reply
|
||||||
|
|
||||||
SysIDX int
|
SysIDX int
|
||||||
|
|
||||||
|
MetaPath []string
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mrusme/neonmodem/models/author"
|
"github.com/mrusme/neonmodem/models/author"
|
||||||
@ -281,11 +282,11 @@ func (sys *System) LoadPost(p *post.Post) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Replies = []reply.Reply{}
|
replies := []reply.Reply{}
|
||||||
for _, i := range resp.Comments {
|
for _, i := range resp.Comments {
|
||||||
createdAt := i.Comment.Published
|
createdAt := i.Comment.Published
|
||||||
|
|
||||||
p.Replies = append(p.Replies, reply.Reply{
|
replies = append(replies, reply.Reply{
|
||||||
ID: strconv.FormatInt(i.Comment.ID, 10),
|
ID: strconv.FormatInt(i.Comment.ID, 10),
|
||||||
|
|
||||||
InReplyTo: p.ID,
|
InReplyTo: p.ID,
|
||||||
@ -299,12 +300,40 @@ func (sys *System) LoadPost(p *post.Post) error {
|
|||||||
Name: i.Creator.Name,
|
Name: i.Creator.Name,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Replies: []reply.Reply{},
|
||||||
|
|
||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
|
|
||||||
|
MetaPath: strings.Split(i.Comment.Path, "."),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findRepliesFor(&replies, &p.Replies, 0)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findRepliesFor(prv *[]reply.Reply, nxt *[]reply.Reply, lvl int) {
|
||||||
|
if lvl >= 8 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(*prv); i++ {
|
||||||
|
if len((*prv)[i].MetaPath) == (lvl + 2) {
|
||||||
|
*nxt = append(*nxt, (*prv)[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nextLayer := []reply.Reply{}
|
||||||
|
findRepliesFor(prv, &nextLayer, lvl+1)
|
||||||
|
for j := 0; j < len(nextLayer); j++ {
|
||||||
|
for k := 0; k < len(*nxt); k++ {
|
||||||
|
if (*nxt)[k].ID == nextLayer[j].MetaPath[(lvl+1)] {
|
||||||
|
(*nxt)[k].Replies = append((*nxt)[k].Replies, nextLayer[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (sys *System) CreatePost(p *post.Post) error {
|
func (sys *System) CreatePost(p *post.Post) error {
|
||||||
communityID, err := strconv.ParseInt(p.Forum.ID, 10, 64)
|
communityID, err := strconv.ParseInt(p.Forum.ID, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user