1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-11-03 04:27:16 -05:00

Refactored CreateReply

This commit is contained in:
マリウス 2023-01-05 17:40:18 -05:00
parent f3b8fceb2e
commit cf26b198ee
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 21 additions and 26 deletions

View File

@ -9,6 +9,7 @@ import (
type Reply struct {
ID string
InReplyTo string
Index int
Body string

View File

@ -265,6 +265,7 @@ func (sys *System) LoadPost(p *post.Post) error {
p.Replies = append(p.Replies, reply.Reply{
ID: strconv.Itoa(i.ID),
InReplyTo: p.ID,
Index: idx,
Body: cookedMd,
@ -313,17 +314,14 @@ func (sys *System) CreateReply(r *reply.Reply) error {
return err
}
var inReplyTo int = -1
if r.InReplyTo != "" {
inReplyTo, err = strconv.Atoi(r.InReplyTo)
if err != nil {
return err
}
inReplyTo, err := strconv.Atoi(r.InReplyTo)
if err != nil {
return err
}
var ap api.CreatePostModel
if inReplyTo == -1 {
if r.Index == -1 {
// Looks like we're replying directly to a post
ap = api.CreatePostModel{
Raw: r.Body,
@ -335,7 +333,7 @@ func (sys *System) CreateReply(r *reply.Reply) error {
ap = api.CreatePostModel{
Raw: r.Body,
TopicID: inReplyTo,
ReplyToPostNumber: ID,
ReplyToPostNumber: r.Index,
CreatedAt: time.Now().Format(time.RFC3339Nano),
}
}

View File

@ -1,8 +1,6 @@
package postcreate
import (
"strconv"
tea "github.com/charmbracelet/bubbletea"
"github.com/mrusme/gobbs/models/post"
"github.com/mrusme/gobbs/models/reply"
@ -12,27 +10,25 @@ import (
func handleSubmit(mi interface{}) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
var irtID string = ""
var irtIRT string = ""
var irtSysIDX int = 0
var r reply.Reply
if m.replyToIdx == 0 {
pst := m.replyToIface.(post.Post)
irtID = pst.ID
irtSysIDX = pst.SysIDX
// No numbers were typed before hitting `r` so we're replying to the actual
// Post
x := m.replyToIface.(post.Post)
r = reply.Reply{
ID: x.ID,
InReplyTo: "",
Index: -1,
SysIDX: x.SysIDX,
}
} else {
rply := m.replyToIface.(reply.Reply)
irtID = strconv.Itoa(m.replyToIdx + 1)
irtIRT = rply.InReplyTo // TODO: THis is empty? Why?
irtSysIDX = rply.SysIDX
// Numbers were typed before hitting `r`, so we're taking the actual reply
// here
r = m.replyToIface.(reply.Reply)
}
r := reply.Reply{
ID: irtID,
InReplyTo: irtIRT,
Body: m.textarea.Value(),
SysIDX: irtSysIDX,
}
r.Body = m.textarea.Value()
err := m.a.CreateReply(&r)
if err != nil {