mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-12-04 14:46:37 -05:00
Extended discourse, lemmy implementations
This commit is contained in:
parent
90bd800283
commit
188d0db571
@ -3,7 +3,9 @@ package discourse
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/mrusme/gobbs/models/author"
|
||||
"github.com/mrusme/gobbs/models/post"
|
||||
"github.com/mrusme/gobbs/system/adapter"
|
||||
"go.uber.org/zap"
|
||||
@ -75,9 +77,28 @@ func (sys *System) ListPosts() ([]post.Post, error) {
|
||||
|
||||
var models []post.Post
|
||||
for _, i := range (*items).TopicList.Topics {
|
||||
var userName string = ""
|
||||
for _, u := range (*items).Users {
|
||||
if u.ID == i.Posters[0].UserID {
|
||||
userName = u.Name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
models = append(models, post.Post{
|
||||
ID: string(i.ID),
|
||||
ID: strconv.Itoa(i.ID),
|
||||
|
||||
Subject: i.Title,
|
||||
|
||||
Type: "post",
|
||||
|
||||
Pinned: i.Pinned,
|
||||
Closed: i.Closed,
|
||||
|
||||
Author: author.Author{
|
||||
ID: strconv.Itoa(i.Posters[0].UserID),
|
||||
Name: userName,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,14 @@ type LatestTopicsResponse struct {
|
||||
} `json:"topic_list"`
|
||||
}
|
||||
|
||||
type SingleTopicResponse struct {
|
||||
PostStream struct {
|
||||
Posts []PostModel `json:"posts"`
|
||||
} `json:"post_stream"`
|
||||
|
||||
TopicModel
|
||||
}
|
||||
|
||||
type TopicModel struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
@ -71,7 +79,7 @@ type TopicsService interface {
|
||||
Show(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
) (*TopicModel, error)
|
||||
) (*SingleTopicResponse, error)
|
||||
ListLatest(
|
||||
ctx context.Context,
|
||||
) (*LatestTopicsResponse, error)
|
||||
@ -85,7 +93,7 @@ type TopicServiceHandler struct {
|
||||
func (a *TopicServiceHandler) Show(
|
||||
ctx context.Context,
|
||||
id string,
|
||||
) (*TopicModel, error) {
|
||||
) (*SingleTopicResponse, error) {
|
||||
uri := TopicsBaseURL + "/t/" + id + ".json"
|
||||
|
||||
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
|
||||
@ -93,7 +101,7 @@ func (a *TopicServiceHandler) Show(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := new(TopicModel)
|
||||
response := new(SingleTopicResponse)
|
||||
if err = a.client.Do(ctx, req, response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package lemmy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/mrusme/gobbs/models/author"
|
||||
"github.com/mrusme/gobbs/models/post"
|
||||
"github.com/mrusme/gobbs/system/adapter"
|
||||
"go.arsenm.dev/go-lemmy"
|
||||
@ -67,9 +69,33 @@ func (sys *System) ListPosts() ([]post.Post, error) {
|
||||
|
||||
var models []post.Post
|
||||
for _, i := range resp.Posts {
|
||||
t := "post"
|
||||
if i.Post.URL.IsValid() {
|
||||
t = "url"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
models = append(models, post.Post{
|
||||
ID: string(i.Post.ID),
|
||||
ID: strconv.Itoa(i.Post.ID),
|
||||
|
||||
Subject: i.Post.Name,
|
||||
|
||||
Type: t,
|
||||
|
||||
Pinned: i.Post.Stickied,
|
||||
Closed: i.Post.Locked,
|
||||
|
||||
Author: author.Author{
|
||||
ID: strconv.Itoa(i.Post.CreatorID),
|
||||
Name: userName,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user