1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-09-29 04:45:55 -04:00

Implemented (untested) CreatePost/CreateReply

This commit is contained in:
マリウス 2023-01-02 23:47:30 -05:00
parent 9d8708e7be
commit e004971d8a
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

View File

@ -194,9 +194,44 @@ func (sys *System) LoadPost(p *post.Post) error {
}
func (sys *System) CreatePost(p *post.Post) error {
communityID, err := strconv.Atoi(p.Forum.ID)
if err != nil {
return err
}
resp, err := sys.client.CreatePost(context.Background(), types.CreatePost{
Name: p.Subject,
CommunityID: communityID,
Body: types.NewOptional(p.Body),
NSFW: types.NewOptional(false),
})
if err != nil {
return err
}
p.ID = strconv.Itoa(resp.PostView.Post.ID)
return nil
}
func (sys *System) CreateReply(r *reply.Reply) error {
id, err := strconv.Atoi(r.ID)
if err != nil {
return err
}
inReplyTo, err := strconv.Atoi(r.InReplyTo)
if err != nil {
return err
}
resp, err := sys.client.CreateComment(context.Background(), types.CreateComment{
PostID: inReplyTo,
ParentID: types.NewOptional(id),
Content: r.Body,
})
if err != nil {
return err
}
r.ID = strconv.Itoa(resp.CommentView.Comment.ID)
return nil
}