1
0
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:
マリウス 2022-12-30 01:44:44 -05:00
parent 90bd800283
commit 188d0db571
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 60 additions and 5 deletions

View File

@ -3,7 +3,9 @@ package discourse
import ( import (
"context" "context"
"net/http" "net/http"
"strconv"
"github.com/mrusme/gobbs/models/author"
"github.com/mrusme/gobbs/models/post" "github.com/mrusme/gobbs/models/post"
"github.com/mrusme/gobbs/system/adapter" "github.com/mrusme/gobbs/system/adapter"
"go.uber.org/zap" "go.uber.org/zap"
@ -75,9 +77,28 @@ func (sys *System) ListPosts() ([]post.Post, error) {
var models []post.Post var models []post.Post
for _, i := range (*items).TopicList.Topics { 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{ models = append(models, post.Post{
ID: string(i.ID), ID: strconv.Itoa(i.ID),
Subject: i.Title, Subject: i.Title,
Type: "post",
Pinned: i.Pinned,
Closed: i.Closed,
Author: author.Author{
ID: strconv.Itoa(i.Posters[0].UserID),
Name: userName,
},
}) })
} }

View File

@ -26,6 +26,14 @@ type LatestTopicsResponse struct {
} `json:"topic_list"` } `json:"topic_list"`
} }
type SingleTopicResponse struct {
PostStream struct {
Posts []PostModel `json:"posts"`
} `json:"post_stream"`
TopicModel
}
type TopicModel struct { type TopicModel struct {
ID int `json:"id"` ID int `json:"id"`
Title string `json:"title"` Title string `json:"title"`
@ -71,7 +79,7 @@ type TopicsService interface {
Show( Show(
ctx context.Context, ctx context.Context,
id string, id string,
) (*TopicModel, error) ) (*SingleTopicResponse, error)
ListLatest( ListLatest(
ctx context.Context, ctx context.Context,
) (*LatestTopicsResponse, error) ) (*LatestTopicsResponse, error)
@ -85,7 +93,7 @@ type TopicServiceHandler struct {
func (a *TopicServiceHandler) Show( func (a *TopicServiceHandler) Show(
ctx context.Context, ctx context.Context,
id string, id string,
) (*TopicModel, error) { ) (*SingleTopicResponse, error) {
uri := TopicsBaseURL + "/t/" + id + ".json" uri := TopicsBaseURL + "/t/" + id + ".json"
req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil) req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil)
@ -93,7 +101,7 @@ func (a *TopicServiceHandler) Show(
return nil, err return nil, err
} }
response := new(TopicModel) response := new(SingleTopicResponse)
if err = a.client.Do(ctx, req, response); err != nil { if err = a.client.Do(ctx, req, response); err != nil {
return nil, err return nil, err
} }

View File

@ -2,7 +2,9 @@ package lemmy
import ( import (
"context" "context"
"strconv"
"github.com/mrusme/gobbs/models/author"
"github.com/mrusme/gobbs/models/post" "github.com/mrusme/gobbs/models/post"
"github.com/mrusme/gobbs/system/adapter" "github.com/mrusme/gobbs/system/adapter"
"go.arsenm.dev/go-lemmy" "go.arsenm.dev/go-lemmy"
@ -67,9 +69,33 @@ func (sys *System) ListPosts() ([]post.Post, error) {
var models []post.Post var models []post.Post
for _, i := range resp.Posts { 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{ models = append(models, post.Post{
ID: string(i.Post.ID), ID: strconv.Itoa(i.Post.ID),
Subject: i.Post.Name, 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,
},
}) })
} }