diff --git a/models/post/post.go b/models/post/post.go index d4a2065..271ed4b 100644 --- a/models/post/post.go +++ b/models/post/post.go @@ -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 diff --git a/system/discourse/discourse.go b/system/discourse/discourse.go index dceefdc..6e410f3 100644 --- a/system/discourse/discourse.go +++ b/system/discourse/discourse.go @@ -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, diff --git a/system/lemmy/lemmy.go b/system/lemmy/lemmy.go index 7c75a1c..6e378d1 100644 --- a/system/lemmy/lemmy.go +++ b/system/lemmy/lemmy.go @@ -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, }, }) }