mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-06-16 06:25:23 +00:00
Fixed post reply function
This commit is contained in:
parent
4a9ed09782
commit
9d8708e7be
|
@ -225,21 +225,39 @@ func (sys *System) CreatePost(p *post.Post) error {
|
|||
}
|
||||
|
||||
func (sys *System) CreateReply(r *reply.Reply) error {
|
||||
var err error
|
||||
|
||||
sys.logger.Debugf("%v", r)
|
||||
ID, err := strconv.Atoi(r.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
inReplyTo, err := strconv.Atoi(r.InReplyTo)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
var inReplyTo int = -1
|
||||
if r.InReplyTo != "" {
|
||||
inReplyTo, err = strconv.Atoi(r.InReplyTo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
ap := api.CreatePostModel{
|
||||
Raw: r.Body,
|
||||
TopicID: inReplyTo,
|
||||
ReplyToPostNumber: ID,
|
||||
CreatedAt: time.Now().Format(time.RFC3339Nano),
|
||||
var ap api.CreatePostModel
|
||||
|
||||
if inReplyTo == -1 {
|
||||
// Looks like we're replying directly to a post
|
||||
ap = api.CreatePostModel{
|
||||
Raw: r.Body,
|
||||
TopicID: ID,
|
||||
CreatedAt: time.Now().Format(time.RFC3339Nano),
|
||||
}
|
||||
} else {
|
||||
// Apparently it's a reply to a comment in a post
|
||||
ap = api.CreatePostModel{
|
||||
Raw: r.Body,
|
||||
TopicID: inReplyTo,
|
||||
ReplyToPostNumber: ID,
|
||||
CreatedAt: time.Now().Format(time.RFC3339Nano),
|
||||
}
|
||||
}
|
||||
|
||||
cp, err := sys.client.Posts.Create(context.Background(), &ap)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package postcreate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -112,8 +113,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
irtSysIDX = pst.SysIDX
|
||||
} else {
|
||||
rply := m.replyToIface.(reply.Reply)
|
||||
b, _ := json.Marshal(rply)
|
||||
m.ctx.Logger.Debug(string(b))
|
||||
irtID = strconv.Itoa(m.replyToIdx + 1)
|
||||
irtIRT = rply.InReplyTo
|
||||
irtIRT = rply.InReplyTo // TODO: THis is empty? Why?
|
||||
irtSysIDX = rply.SysIDX
|
||||
}
|
||||
|
||||
|
@ -124,6 +127,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
SysIDX: irtSysIDX,
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(r)
|
||||
m.ctx.Logger.Debug(string(b))
|
||||
|
||||
err := m.a.CreateReply(&r)
|
||||
if err != nil {
|
||||
m.ctx.Logger.Error(err)
|
||||
|
|
Loading…
Reference in New Issue
Block a user