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:
parent
df93850326
commit
6ed8922303
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user