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

Extended post model

This commit is contained in:
マリウス 2022-12-30 02:05:48 -05:00
parent df93850326
commit 6ed8922303
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 35 additions and 7 deletions

View File

@ -1,6 +1,8 @@
package post
import (
"time"
"github.com/mrusme/gobbs/models/author"
"github.com/mrusme/gobbs/models/reply"
)
@ -15,6 +17,9 @@ type Post struct {
Pinned bool
Closed bool
CreatedAt time.Time
LastCommentedAt time.Time
Author author.Author
Replies []reply.Reply

View File

@ -4,7 +4,9 @@ import (
"context"
"net/http"
"strconv"
"time"
"github.com/araddon/dateparse"
"github.com/mrusme/gobbs/models/author"
"github.com/mrusme/gobbs/models/post"
"github.com/mrusme/gobbs/system/adapter"
@ -85,6 +87,15 @@ func (sys *System) ListPosts() ([]post.Post, error) {
}
}
createdAt, err := dateparse.ParseAny(i.CreatedAt)
if err != nil {
createdAt = time.Now() // TODO: Errrr
}
lastCommentedAt, err := dateparse.ParseAny(i.LastPostedAt)
if err != nil {
lastCommentedAt = time.Now() // TODO: Errrrr
}
models = append(models, post.Post{
ID: strconv.Itoa(i.ID),
@ -95,6 +106,9 @@ func (sys *System) ListPosts() ([]post.Post, error) {
Pinned: i.Pinned,
Closed: i.Closed,
CreatedAt: createdAt,
LastCommentedAt: lastCommentedAt,
Author: author.Author{
ID: strconv.Itoa(i.Posters[0].UserID),
Name: userName,

View File

@ -3,7 +3,9 @@ package lemmy
import (
"context"
"strconv"
"time"
"github.com/araddon/dateparse"
"github.com/mrusme/gobbs/models/author"
"github.com/mrusme/gobbs/models/post"
"github.com/mrusme/gobbs/system/adapter"
@ -70,31 +72,38 @@ func (sys *System) ListPosts() ([]post.Post, error) {
var models []post.Post
for _, i := range resp.Posts {
t := "post"
body := i.Post.Body.ValueOr("")
if i.Post.URL.IsValid() {
t = "url"
body = i.Post.URL.ValueOr("")
}
var userName string = ""
presp, err := sys.client.PersonDetails(context.Background(), types.GetPersonDetails{
PersonID: types.NewOptional(i.Post.CreatorID),
})
if err == nil {
userName = presp.PersonView.Person.Name
createdAt, err := dateparse.ParseAny(i.Post.Published)
if err != nil {
createdAt = time.Now() // TODO: Errrr
}
lastCommentedAt, err := dateparse.ParseAny(i.Counts.NewestCommentTime)
if err != nil {
lastCommentedAt = time.Now() // TODO: Errrrr
}
models = append(models, post.Post{
ID: strconv.Itoa(i.Post.ID),
Subject: i.Post.Name,
Body: body,
Type: t,
Pinned: i.Post.Stickied,
Closed: i.Post.Locked,
CreatedAt: createdAt,
LastCommentedAt: lastCommentedAt,
Author: author.Author{
ID: strconv.Itoa(i.Post.CreatorID),
Name: userName,
Name: i.Creator.Name,
},
})
}