mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-06-30 06:45:24 +00:00
Refactored CreateReply
This commit is contained in:
parent
f3b8fceb2e
commit
cf26b198ee
|
@ -9,6 +9,7 @@ import (
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
ID string
|
ID string
|
||||||
InReplyTo string
|
InReplyTo string
|
||||||
|
Index int
|
||||||
|
|
||||||
Body string
|
Body string
|
||||||
|
|
||||||
|
|
|
@ -265,6 +265,7 @@ func (sys *System) LoadPost(p *post.Post) error {
|
||||||
p.Replies = append(p.Replies, reply.Reply{
|
p.Replies = append(p.Replies, reply.Reply{
|
||||||
ID: strconv.Itoa(i.ID),
|
ID: strconv.Itoa(i.ID),
|
||||||
InReplyTo: p.ID,
|
InReplyTo: p.ID,
|
||||||
|
Index: idx,
|
||||||
|
|
||||||
Body: cookedMd,
|
Body: cookedMd,
|
||||||
|
|
||||||
|
@ -313,17 +314,14 @@ func (sys *System) CreateReply(r *reply.Reply) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var inReplyTo int = -1
|
inReplyTo, err := strconv.Atoi(r.InReplyTo)
|
||||||
if r.InReplyTo != "" {
|
if err != nil {
|
||||||
inReplyTo, err = strconv.Atoi(r.InReplyTo)
|
return err
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ap api.CreatePostModel
|
var ap api.CreatePostModel
|
||||||
|
|
||||||
if inReplyTo == -1 {
|
if r.Index == -1 {
|
||||||
// Looks like we're replying directly to a post
|
// Looks like we're replying directly to a post
|
||||||
ap = api.CreatePostModel{
|
ap = api.CreatePostModel{
|
||||||
Raw: r.Body,
|
Raw: r.Body,
|
||||||
|
@ -335,7 +333,7 @@ func (sys *System) CreateReply(r *reply.Reply) error {
|
||||||
ap = api.CreatePostModel{
|
ap = api.CreatePostModel{
|
||||||
Raw: r.Body,
|
Raw: r.Body,
|
||||||
TopicID: inReplyTo,
|
TopicID: inReplyTo,
|
||||||
ReplyToPostNumber: ID,
|
ReplyToPostNumber: r.Index,
|
||||||
CreatedAt: time.Now().Format(time.RFC3339Nano),
|
CreatedAt: time.Now().Format(time.RFC3339Nano),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package postcreate
|
package postcreate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/mrusme/gobbs/models/post"
|
"github.com/mrusme/gobbs/models/post"
|
||||||
"github.com/mrusme/gobbs/models/reply"
|
"github.com/mrusme/gobbs/models/reply"
|
||||||
|
@ -12,27 +10,25 @@ import (
|
||||||
func handleSubmit(mi interface{}) (bool, []tea.Cmd) {
|
func handleSubmit(mi interface{}) (bool, []tea.Cmd) {
|
||||||
var m *Model = mi.(*Model)
|
var m *Model = mi.(*Model)
|
||||||
var cmds []tea.Cmd
|
var cmds []tea.Cmd
|
||||||
var irtID string = ""
|
|
||||||
var irtIRT string = ""
|
|
||||||
var irtSysIDX int = 0
|
|
||||||
|
|
||||||
|
var r reply.Reply
|
||||||
if m.replyToIdx == 0 {
|
if m.replyToIdx == 0 {
|
||||||
pst := m.replyToIface.(post.Post)
|
// No numbers were typed before hitting `r` so we're replying to the actual
|
||||||
irtID = pst.ID
|
// Post
|
||||||
irtSysIDX = pst.SysIDX
|
x := m.replyToIface.(post.Post)
|
||||||
|
r = reply.Reply{
|
||||||
|
ID: x.ID,
|
||||||
|
InReplyTo: "",
|
||||||
|
Index: -1,
|
||||||
|
SysIDX: x.SysIDX,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rply := m.replyToIface.(reply.Reply)
|
// Numbers were typed before hitting `r`, so we're taking the actual reply
|
||||||
irtID = strconv.Itoa(m.replyToIdx + 1)
|
// here
|
||||||
irtIRT = rply.InReplyTo // TODO: THis is empty? Why?
|
r = m.replyToIface.(reply.Reply)
|
||||||
irtSysIDX = rply.SysIDX
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r := reply.Reply{
|
r.Body = m.textarea.Value()
|
||||||
ID: irtID,
|
|
||||||
InReplyTo: irtIRT,
|
|
||||||
Body: m.textarea.Value(),
|
|
||||||
SysIDX: irtSysIDX,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := m.a.CreateReply(&r)
|
err := m.a.CreateReply(&r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user