From f29641ae13712f6a1f07ec408303b9e52f4350a5 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 10 Dec 2022 09:17:16 -0800 Subject: [PATCH] Initial Commit --- .gitignore | 1 + README.md | 29 +++ admin.go | 128 +++++++++++++ comment.go | 158 ++++++++++++++++ community.go | 173 +++++++++++++++++ go.mod | 8 + go.sum | 7 + lemmy.go | 169 +++++++++++++++++ person.go | 316 +++++++++++++++++++++++++++++++ post.go | 233 +++++++++++++++++++++++ privateMessage.go | 128 +++++++++++++ site.go | 53 ++++++ types/aggregates.go | 55 ++++++ types/comment.go | 105 +++++++++++ types/community.go | 131 +++++++++++++ types/optional.go | 103 ++++++++++ types/others.go | 169 +++++++++++++++++ types/person.go | 243 ++++++++++++++++++++++++ types/post.go | 146 +++++++++++++++ types/privateMessage.go | 71 +++++++ types/site.go | 244 ++++++++++++++++++++++++ types/source.go | 402 ++++++++++++++++++++++++++++++++++++++++ types/types.go | 27 +++ types/views.go | 254 +++++++++++++++++++++++++ 24 files changed, 3353 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 admin.go create mode 100644 comment.go create mode 100644 community.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 lemmy.go create mode 100644 person.go create mode 100644 post.go create mode 100644 privateMessage.go create mode 100644 site.go create mode 100644 types/aggregates.go create mode 100644 types/comment.go create mode 100644 types/community.go create mode 100644 types/optional.go create mode 100644 types/others.go create mode 100644 types/person.go create mode 100644 types/post.go create mode 100644 types/privateMessage.go create mode 100644 types/site.go create mode 100644 types/source.go create mode 100644 types/types.go create mode 100644 types/views.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32bcdf1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/test \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c2a9dba --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Go-Lemmy + +Go bindings to the [Lemmy](https://join-lemmy.org) API + +Example: + +```go +ctx := context.Background() + +c, err := lemmy.New("https://lemmy.ml") +if err != nil { + panic(err) +} + +err = c.Login(ctx, types.Login{ + UsernameOrEmail: "email@example.com", + Password: `TestPwd`, +}) +if err != nil { + panic(err) +} + +_, err = c.SaveUserSettings(ctx, types.SaveUserSettings{ + BotAccount: types.NewOptional(true), +}) +if err != nil { + panic(err) +} +``` \ No newline at end of file diff --git a/admin.go b/admin.go new file mode 100644 index 0000000..077bd69 --- /dev/null +++ b/admin.go @@ -0,0 +1,128 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) AddAdmin(ctx context.Context, d types.AddAdmin) (*types.AddAdminResponse, error) { + ar := &types.AddAdminResponse{} + res, err := c.req(ctx, http.MethodPost, "/admin/add", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ApproveRegistrationApplication(ctx context.Context, d types.ApproveRegistrationApplication) (*types.RegistrationApplicationResponse, error) { + ar := &types.RegistrationApplicationResponse{} + res, err := c.req(ctx, http.MethodPut, "/admin/registration_application/approve", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) UnreadRegistrationApplicationCount(ctx context.Context, d types.GetUnreadRegistrationApplicationCount) (*types.GetUnreadRegistrationApplicationCountResponse, error) { + ar := &types.GetUnreadRegistrationApplicationCountResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/admin/registration_application/count", nil, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ListRegistrationApplications(ctx context.Context, d types.ListRegistrationApplications) (*types.ListRegistrationApplicationsResponse, error) { + ar := &types.ListRegistrationApplicationsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/admin/registration_application/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PurgeComment(ctx context.Context, d types.PurgeComment) (*types.PurgeItemResponse, error) { + ar := &types.PurgeItemResponse{} + res, err := c.req(ctx, http.MethodPost, "/admin/purge/comment", nil, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PurgeCommunity(ctx context.Context, d types.PurgeCommunity) (*types.PurgeItemResponse, error) { + ar := &types.PurgeItemResponse{} + res, err := c.req(ctx, http.MethodPost, "/admin/purge/community", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PurgePerson(ctx context.Context, d types.PurgePerson) (*types.PurgeItemResponse, error) { + ar := &types.PurgeItemResponse{} + res, err := c.req(ctx, http.MethodPost, "/admin/purge/person", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PurgePost(ctx context.Context, d types.PurgePost) (*types.PurgeItemResponse, error) { + ar := &types.PurgeItemResponse{} + res, err := c.req(ctx, http.MethodPost, "/admin/purge/post", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/comment.go b/comment.go new file mode 100644 index 0000000..30f22c9 --- /dev/null +++ b/comment.go @@ -0,0 +1,158 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) Comments(ctx context.Context, d types.GetComments) (*types.GetCommentsResponse, error) { + ar := &types.GetCommentsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/comment/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) CreateComment(ctx context.Context, d types.CreateComment) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPost, "/comment", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) CreateCommentReport(ctx context.Context, d types.CreateCommentReport) (*types.CommentReportResponse, error) { + ar := &types.CommentReportResponse{} + res, err := c.req(ctx, http.MethodPost, "/comment/report", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) DeleteComment(ctx context.Context, d types.DeleteComment) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPost, "/comment/delete", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) RemoveComment(ctx context.Context, d types.RemoveComment) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPost, "/comment/remove", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) EditComment(ctx context.Context, d types.EditComment) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPut, "/comment", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) LikeComment(ctx context.Context, d types.CreateCommentLike) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPost, "/comment/like", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ListCommentReports(ctx context.Context, d types.ListCommentReports) (*types.ListCommentReportsResponse, error) { + ar := &types.ListCommentReportsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/comments/report/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) MarkCommentReplyRead(ctx context.Context, d types.MarkCommentReplyAsRead) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPost, "/comment/mark_as_read", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) SaveComment(ctx context.Context, d types.SaveComment) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPut, "/comment/save", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/community.go b/community.go new file mode 100644 index 0000000..743ff10 --- /dev/null +++ b/community.go @@ -0,0 +1,173 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) AddModToCommunity(ctx context.Context, d types.AddModToCommunity) (*types.AddModToCommunityResponse, error) { + ar := &types.AddModToCommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/mod", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) BanFromCommunity(ctx context.Context, d types.BanFromCommunity) (*types.BanFromCommunityResponse, error) { + ar := &types.BanFromCommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/ban_user", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) BlockCommunity(ctx context.Context, d types.BlockCommunity) (*types.BlockCommunityResponse, error) { + ar := &types.BlockCommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/block", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) CreateCommunity(ctx context.Context, d types.CreateCommunity) (*types.CommunityResponse, error) { + ar := &types.CommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) EditCommunity(ctx context.Context, d types.EditCommunity) (*types.CommunityResponse, error) { + ar := &types.CommunityResponse{} + res, err := c.req(ctx, http.MethodPut, "/community", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) FollowCommunity(ctx context.Context, d types.FollowCommunity) (*types.CommunityResponse, error) { + ar := &types.CommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/follow", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) DeleteCommunity(ctx context.Context, d types.DeleteCommunity) (*types.CommunityResponse, error) { + ar := &types.CommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/delete", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) RemoveCommunity(ctx context.Context, d types.RemoveCommunity) (*types.CommunityResponse, error) { + ar := &types.CommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/remove", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Community(ctx context.Context, d types.GetCommunity) (*types.GetCommunityResponse, error) { + ar := &types.GetCommunityResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/community", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Communities(ctx context.Context, d types.ListCommunities) (*types.ListCommunitiesResponse, error) { + ar := &types.ListCommunitiesResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/community/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) TransferCommunity(ctx context.Context, d types.TransferCommunity) (*types.GetCommunityResponse, error) { + ar := &types.GetCommunityResponse{} + res, err := c.req(ctx, http.MethodPost, "/community/transfer", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b8e3ac3 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module go.arsenm.dev/go-lemmy + +go 1.19 + +require ( + github.com/google/go-querystring v1.1.0 + github.com/mitchellh/mapstructure v1.5.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d76c958 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/lemmy.go b/lemmy.go new file mode 100644 index 0000000..c4fbd78 --- /dev/null +++ b/lemmy.go @@ -0,0 +1,169 @@ +package lemmy + +import ( + "bytes" + "context" + "encoding/json" + "io" + "net/http" + "net/url" + "reflect" + + "github.com/google/go-querystring/query" + "go.arsenm.dev/go-lemmy/types" +) + +type Client struct { + client *http.Client + baseURL *url.URL + token string +} + +func New(baseURL string) (*Client, error) { + return NewWithClient(baseURL, http.DefaultClient) +} + +func NewWithClient(baseURL string, client *http.Client) (*Client, error) { + u, err := url.Parse(baseURL) + if err != nil { + return nil, err + } + u = u.JoinPath("/api/v3") + + return &Client{baseURL: u, client: client}, nil +} + +func (c *Client) Login(ctx context.Context, l types.Login) error { + var lr types.LoginResponse + res, err := c.req(ctx, http.MethodPost, "/user/login", l, &lr) + if err != nil { + return err + } + + err = resError(res, lr.LemmyResponse) + if err != nil { + return err + } + + c.token = lr.JWT.MustValue() + + return nil +} + +func (c *Client) Token() string { + return c.token +} + +func (c *Client) SetToken(t string) { + c.token = t +} + +func (c *Client) req(ctx context.Context, method string, path string, data, resp any) (*http.Response, error) { + data = c.setAuth(data) + + var r io.Reader + if data != nil { + jsonData, err := json.Marshal(data) + if err != nil { + return nil, err + } + r = bytes.NewReader(jsonData) + } + + req, err := http.NewRequestWithContext( + ctx, + method, + c.baseURL.JoinPath(path).String(), + r, + ) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", "application/json") + + res, err := c.client.Do(req) + if err != nil { + return nil, err + } + defer res.Body.Close() + + err = json.NewDecoder(res.Body).Decode(resp) + if err == io.EOF { + return res, nil + } else if err != nil { + return nil, err + } + + return res, nil +} + +func (c *Client) getReq(ctx context.Context, method string, path string, data, resp any) (*http.Response, error) { + data = c.setAuth(data) + + getURL := c.baseURL.JoinPath(path) + vals, err := query.Values(data) + if err != nil { + return nil, err + } + getURL.RawQuery = vals.Encode() + + req, err := http.NewRequestWithContext( + ctx, + method, + getURL.String(), + nil, + ) + if err != nil { + return nil, err + } + + res, err := c.client.Do(req) + if err != nil { + return nil, err + } + defer res.Body.Close() + + err = json.NewDecoder(res.Body).Decode(resp) + if err == io.EOF { + return res, nil + } else if err != nil { + return nil, err + } + + return res, nil +} + +func resError(res *http.Response, lr types.LemmyResponse) error { + if lr.Error.IsValid() { + return types.LemmyError{ + Code: res.StatusCode, + ErrStr: lr.Error.MustValue(), + } + } else if res.StatusCode > 299 { + return types.HTTPError{ + Code: res.StatusCode, + } + } else { + return nil + } +} + +func (c *Client) setAuth(data any) any { + val := reflect.New(reflect.TypeOf(data)) + val.Elem().Set(reflect.ValueOf(data)) + + authField := val.Elem().FieldByName("Auth") + if !authField.IsValid() { + return data + } + + authType := authField.Kind() + if authType != reflect.String { + return data + } + + authField.SetString(c.token) + + return val.Elem().Interface() +} diff --git a/person.go b/person.go new file mode 100644 index 0000000..e60d5b1 --- /dev/null +++ b/person.go @@ -0,0 +1,316 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) BanPerson(ctx context.Context, d types.BanPerson) (*types.BanPersonResponse, error) { + ar := &types.BanPersonResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/ban", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) BlockPerson(ctx context.Context, d types.BlockPerson) (*types.BlockPersonResponse, error) { + ar := &types.BlockPersonResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/block", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ChangePassword(ctx context.Context, d types.ChangePassword) (*types.LoginResponse, error) { + ar := &types.LoginResponse{} + res, err := c.req(ctx, http.MethodPut, "/user/change_password", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + c.token = ar.JWT.MustValue() + + return ar, nil +} + +func (c *Client) DeleteAccount(ctx context.Context, d types.DeleteAccount) (*types.DeleteAccountResponse, error) { + ar := &types.DeleteAccountResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/delete_account", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) BannedPersons(ctx context.Context, d types.GetBannedPersons) (*types.BannedPersonsResponse, error) { + ar := &types.BannedPersonsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user/banned", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Captcha(ctx context.Context, d types.GetCaptcha) (*types.CaptchaResponse, error) { + ar := &types.CaptchaResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user/get_captcha", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PersonDetails(ctx context.Context, d types.GetPersonDetails) (*types.GetPersonDetailsResponse, error) { + ar := &types.GetPersonDetailsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PersonMentions(ctx context.Context, d types.GetPersonMentions) (*types.GetPersonMentionsResponse, error) { + ar := &types.GetPersonMentionsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user/mention", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Replies(ctx context.Context, d types.GetReplies) (*types.GetRepliesResponse, error) { + ar := &types.GetRepliesResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user/replies", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ReportCount(ctx context.Context, d types.GetReportCount) (*types.GetReportCountResponse, error) { + ar := &types.GetReportCountResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user/report_count", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) UnreadCount(ctx context.Context, d types.GetUnreadCount) (*types.GetUnreadCountResponse, error) { + ar := &types.GetUnreadCountResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/user/unread_count", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) LeaveAdmin(ctx context.Context, d types.LeaveAdmin) (*types.GetSiteResponse, error) { + ar := &types.GetSiteResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/leave_admin", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) MarkAllAsRead(ctx context.Context, d types.MarkAllAsRead) (*types.GetRepliesResponse, error) { + ar := &types.GetRepliesResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/mark_all_as_read", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) MarkCommentReplyAsRead(ctx context.Context, d types.MarkCommentReplyAsRead) (*types.CommentResponse, error) { + ar := &types.CommentResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/mark_as_read", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) MarkPersonMentionAsRead(ctx context.Context, d types.MarkPersonMentionAsRead) (*types.PersonMentionResponse, error) { + ar := &types.PersonMentionResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/mention/mark_as_read", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PasswordChange(ctx context.Context, d types.PasswordChange) (*types.LoginResponse, error) { + ar := &types.LoginResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/password_change", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + c.token = ar.JWT.MustValue() + + return ar, nil +} + +func (c *Client) PasswordReset(ctx context.Context, d types.PasswordReset) (*types.PasswordResetResponse, error) { + ar := &types.PasswordResetResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/password_reset", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Register(ctx context.Context, d types.Register) (*types.LoginResponse, error) { + ar := &types.LoginResponse{} + res, err := c.req(ctx, http.MethodPost, "/user/register", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + c.token = ar.JWT.MustValue() + + return ar, nil +} + +func (c *Client) SaveUserSettings(ctx context.Context, d types.SaveUserSettings) (*types.LoginResponse, error) { + ar := &types.LoginResponse{} + res, err := c.req(ctx, http.MethodPut, "/user/save_user_settings", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + c.token = ar.JWT.MustValue() + + return ar, nil +} + +func (c *Client) VerifyEmail(ctx context.Context, d types.VerifyEmail) (*types.VerifyEmailResponse, error) { + ar := &types.VerifyEmailResponse{} + res, err := c.req(ctx, http.MethodPut, "/user/verify_email", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/post.go b/post.go new file mode 100644 index 0000000..7bbccb0 --- /dev/null +++ b/post.go @@ -0,0 +1,233 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) CreatePost(ctx context.Context, d types.CreatePost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) EditPost(ctx context.Context, d types.EditPost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPut, "/post", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Post(ctx context.Context, d types.GetPost) (*types.GetPostResponse, error) { + ar := &types.GetPostResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/post", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) CreatePostReport(ctx context.Context, d types.CreatePostReport) (*types.PostReportResponse, error) { + ar := &types.PostReportResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/report", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) DeletePost(ctx context.Context, d types.DeletePost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/delete", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) RemovePost(ctx context.Context, d types.RemovePost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/remove", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Posts(ctx context.Context, d types.GetPosts) (*types.GetPostsResponse, error) { + ar := &types.GetPostsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/post/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) SiteMetadata(ctx context.Context, d types.GetSiteMetadata) (*types.GetSiteMetadataResponse, error) { + ar := &types.GetSiteMetadataResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/post/site_metadata", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) LikePost(ctx context.Context, d types.CreatePostLike) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/like", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ListPostReports(ctx context.Context, d types.ListPostReports) (*types.ListPostReportsResponse, error) { + ar := &types.ListPostReportsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/post/report/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) LockPost(ctx context.Context, d types.LockPost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/lock", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) MarkPostAsRead(ctx context.Context, d types.MarkPostAsRead) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/mark_as_read", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ResolvePostReport(ctx context.Context, d types.ResolvePostReport) (*types.PostReportResponse, error) { + ar := &types.PostReportResponse{} + res, err := c.req(ctx, http.MethodPut, "/post/report/resolve", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) SavePost(ctx context.Context, d types.SavePost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPut, "/post/save", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) StickyPost(ctx context.Context, d types.StickyPost) (*types.PostResponse, error) { + ar := &types.PostResponse{} + res, err := c.req(ctx, http.MethodPost, "/post/sticky", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/privateMessage.go b/privateMessage.go new file mode 100644 index 0000000..9eb396e --- /dev/null +++ b/privateMessage.go @@ -0,0 +1,128 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) CreatePrivateMessage(ctx context.Context, d types.CreatePrivateMessage) (*types.PrivateMessageResponse, error) { + ar := &types.PrivateMessageResponse{} + res, err := c.req(ctx, http.MethodPost, "/private_message", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) CreatePrivateMessageReport(ctx context.Context, d types.CreatePrivateMessageReport) (*types.PrivateMessageReportResponse, error) { + ar := &types.PrivateMessageReportResponse{} + res, err := c.req(ctx, http.MethodPost, "/private_message/report", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) DeletePrivateMessage(ctx context.Context, d types.DeletePrivateMessage) (*types.PrivateMessageResponse, error) { + ar := &types.PrivateMessageResponse{} + res, err := c.req(ctx, http.MethodPost, "/private_message/delete", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) EditPrivateMessage(ctx context.Context, d types.EditPrivateMessage) (*types.PrivateMessageResponse, error) { + ar := &types.PrivateMessageResponse{} + res, err := c.req(ctx, http.MethodPut, "/private_message", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PrivateMessages(ctx context.Context, d types.GetPrivateMessages) (*types.PrivateMessagesResponse, error) { + ar := &types.PrivateMessagesResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/private_message/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) PrivateMessageReports(ctx context.Context, d types.ListPrivateMessageReports) (*types.ListPrivateMessageReportsResponse, error) { + ar := &types.ListPrivateMessageReportsResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/private_message/report/list", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) MarkPrivateMessageAsRead(ctx context.Context, d types.MarkPrivateMessageAsRead) (*types.PrivateMessageResponse, error) { + ar := &types.PrivateMessageResponse{} + res, err := c.req(ctx, http.MethodPost, "/private_message/mark_as_read", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) ResolvePrivateMessageReport(ctx context.Context, d types.ResolvePrivateMessageReport) (*types.PrivateMessageReportResponse, error) { + ar := &types.PrivateMessageReportResponse{} + res, err := c.req(ctx, http.MethodPut, "/private_message/report/resolve", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/site.go b/site.go new file mode 100644 index 0000000..e9d08a2 --- /dev/null +++ b/site.go @@ -0,0 +1,53 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) CreateSite(ctx context.Context, d types.CreateSite) (*types.SiteResponse, error) { + ar := &types.SiteResponse{} + res, err := c.req(ctx, http.MethodPost, "/site", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) EditSite(ctx context.Context, d types.EditSite) (*types.SiteResponse, error) { + ar := &types.SiteResponse{} + res, err := c.req(ctx, http.MethodPut, "/site", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} + +func (c *Client) Site(ctx context.Context, d types.GetSite) (*types.GetSiteResponse, error) { + ar := &types.GetSiteResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/site", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/types/aggregates.go b/types/aggregates.go new file mode 100644 index 0000000..318aa97 --- /dev/null +++ b/types/aggregates.go @@ -0,0 +1,55 @@ +package types + +type PersonAggregates struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + PostCount int `json:"post_count,omitempty" url:"post_count,omitempty"` + PostScore int `json:"post_score,omitempty" url:"post_score,omitempty"` + CommentCount int `json:"comment_count,omitempty" url:"comment_count,omitempty"` + CommentScore int `json:"comment_score,omitempty" url:"comment_score,omitempty"` +} + +type SiteAggregates struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + SiteID int `json:"site_id,omitempty" url:"site_id,omitempty"` + Users int `json:"users,omitempty" url:"users,omitempty"` + Posts int `json:"posts,omitempty" url:"posts,omitempty"` + Comments int `json:"comments,omitempty" url:"comments,omitempty"` + Communities int `json:"communities,omitempty" url:"communities,omitempty"` + UsersActiveDay int `json:"users_active_day,omitempty" url:"users_active_day,omitempty"` + UsersActiveWeek int `json:"users_active_week,omitempty" url:"users_active_week,omitempty"` + UsersActiveMonth int `json:"users_active_month,omitempty" url:"users_active_month,omitempty"` + UsersActiveHalfYear int `json:"users_active_half_year,omitempty" url:"users_active_half_year,omitempty"` +} + +type PostAggregates struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Comments int `json:"comments,omitempty" url:"comments,omitempty"` + Score int `json:"score,omitempty" url:"score,omitempty"` + Upvotes int `json:"upvotes,omitempty" url:"upvotes,omitempty"` + Downvotes int `json:"downvotes,omitempty" url:"downvotes,omitempty"` + NewestCommentTimeNecro string `json:"newest_comment_time_necro,omitempty" url:"newest_comment_time_necro,omitempty"` + NewestCommentTime string `json:"newest_comment_time,omitempty" url:"newest_comment_time,omitempty"` +} + +type CommunityAggregates struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Subscribers int `json:"subscribers,omitempty" url:"subscribers,omitempty"` + Posts int `json:"posts,omitempty" url:"posts,omitempty"` + Comments int `json:"comments,omitempty" url:"comments,omitempty"` + UsersActiveDay int `json:"users_active_day,omitempty" url:"users_active_day,omitempty"` + UsersActiveWeek int `json:"users_active_week,omitempty" url:"users_active_week,omitempty"` + UsersActiveMonth int `json:"users_active_month,omitempty" url:"users_active_month,omitempty"` + UsersActiveHalfYear int `json:"users_active_half_year,omitempty" url:"users_active_half_year,omitempty"` +} + +type CommentAggregates struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Score int `json:"score,omitempty" url:"score,omitempty"` + Upvotes int `json:"upvotes,omitempty" url:"upvotes,omitempty"` + Downvotes int `json:"downvotes,omitempty" url:"downvotes,omitempty"` + ChildCount int `json:"child_count,omitempty" url:"child_count,omitempty"` +} diff --git a/types/comment.go b/types/comment.go new file mode 100644 index 0000000..49241b6 --- /dev/null +++ b/types/comment.go @@ -0,0 +1,105 @@ +package types + +type CreateComment struct { + Content string `json:"content,omitempty" url:"content,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + ParentID Optional[int] `json:"parent_id,omitempty" url:"parent_id,omitempty"` + LanguageID Optional[int] `json:"language_id,omitempty" url:"language_id,omitempty"` + FormID Optional[string] `json:"form_id,omitempty" url:"form_id,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetComment struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type EditComment struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Content Optional[string] `json:"content,omitempty" url:"content,omitempty"` + Distinguished Optional[bool] `json:"distinguished,omitempty" url:"distinguished,omitempty"` + LanguageID Optional[int] `json:"language_id,omitempty" url:"language_id,omitempty"` + FormID Optional[string] `json:"form_id,omitempty" url:"form_id,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type DeleteComment struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type RemoveComment struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Removed bool `json:"removed,omitempty" url:"removed,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type SaveComment struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Save bool `json:"save,omitempty" url:"save,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type CommentResponse struct { + CommentView CommentView `json:"comment_view,omitempty" url:"comment_view,omitempty"` + RecipientIDs []int `json:"recipient_i_ds,omitempty" url:"recipient_i_ds,omitempty"` + FormID Optional[string] `json:"form_id,omitempty" url:"form_id,omitempty"` + LemmyResponse +} + +type CreateCommentLike struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Score int16 `json:"score,omitempty" url:"score,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetComments struct { + Type Optional[ListingType] `json:"type,omitempty" url:"type,omitempty"` + Sort Optional[CommentSortType] `json:"sort,omitempty" url:"sort,omitempty"` + MaxDepth Optional[int] `json:"max_depth,omitempty" url:"max_depth,omitempty"` + Page Optional[int] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int] `json:"limit,omitempty" url:"limit,omitempty"` + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + CommunityName Optional[string] `json:"community_name,omitempty" url:"community_name,omitempty"` + PostID Optional[int] `json:"post_id,omitempty" url:"post_id,omitempty"` + ParentID Optional[int] `json:"parent_id,omitempty" url:"parent_id,omitempty"` + SavedOnly Optional[bool] `json:"saved_only,omitempty" url:"saved_only,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetCommentsResponse struct { + Comments []CommentView `json:"comments,omitempty" url:"comments,omitempty"` + LemmyResponse +} + +type CreateCommentReport struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Reason string `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type CommentReportResponse struct { + CommentReportView CommentReportView `json:"comment_report_view,omitempty" url:"comment_report_view,omitempty"` + LemmyResponse +} + +type ResolveCommentReport struct { + ReportID int `json:"report_id,omitempty" url:"report_id,omitempty"` + Resolved bool `json:"resolved,omitempty" url:"resolved,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListCommentReports struct { + Page Optional[int] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int] `json:"limit,omitempty" url:"limit,omitempty"` + UnresolvedOnly Optional[bool] `json:"unresolved_only,omitempty" url:"unresolved_only,omitempty"` + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListCommentReportsResponse struct { + CommentReports []CommentReportView `json:"comment_reports,omitempty" url:"comment_reports,omitempty"` + LemmyResponse +} diff --git a/types/community.go b/types/community.go new file mode 100644 index 0000000..69a6771 --- /dev/null +++ b/types/community.go @@ -0,0 +1,131 @@ +package types + +type GetCommunity struct { + ID Optional[int] `json:"id,omitempty" url:"id,omitempty"` + Name Optional[string] `json:"name,omitempty" url:"name,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetCommunityResponse struct { + CommunityView CommunityView `json:"community_view,omitempty" url:"community_view,omitempty"` + Site Optional[Site] `json:"site,omitempty" url:"site,omitempty"` + Moderators []CommunityModeratorView `json:"moderators,omitempty" url:"moderators,omitempty"` + Online uint `json:"online,omitempty" url:"online,omitempty"` + DiscussionLanguages []int `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` + DefaultPostLanguage Optional[int] `json:"default_post_language,omitempty" url:"default_post_language,omitempty"` + LemmyResponse +} + +type CreateCommunity struct { + Name string `json:"name,omitempty" url:"name,omitempty"` + Title string `json:"title,omitempty" url:"title,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Icon Optional[string] `json:"icon,omitempty" url:"icon,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + NSFW Optional[bool] `json:"nsfw,omitempty" url:"nsfw,omitempty"` + PostingRestrictedToMods Optional[bool] `json:"posting_restricted_to_mods,omitempty" url:"posting_restricted_to_mods,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type CommunityResponse struct { + CommunityView CommunityView `json:"community_view,omitempty" url:"community_view,omitempty"` + LemmyResponse +} + +type ListCommunities struct { + Type Optional[ListingType] `json:"type,omitempty" url:"type,omitempty"` + Sort Optional[SortType] `json:"sort,omitempty" url:"sort,omitempty"` + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListCommunitiesResponse struct { + Communities []CommunityView `json:"communities,omitempty" url:"communities,omitempty"` + LemmyResponse +} + +type BanFromCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Ban bool `json:"ban,omitempty" url:"ban,omitempty"` + RemoveData Optional[bool] `json:"remove_data,omitempty" url:"remove_data,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Expires Optional[int64] `json:"expires,omitempty" url:"expires,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type BanFromCommunityResponse struct { + PersonView PersonViewSafe `json:"person_view,omitempty" url:"person_view,omitempty"` + Banned bool `json:"banned,omitempty" url:"banned,omitempty"` + LemmyResponse +} + +type AddModToCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Added bool `json:"added,omitempty" url:"added,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type AddModToCommunityResponse struct { + Moderators []CommunityModeratorView `json:"moderators,omitempty" url:"moderators,omitempty"` + LemmyResponse +} + +type EditCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Title Optional[string] `json:"title,omitempty" url:"title,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Icon Optional[string] `json:"icon,omitempty" url:"icon,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + NSFW Optional[bool] `json:"nsfw,omitempty" url:"nsfw,omitempty"` + PostingRestrictedToMods Optional[bool] `json:"posting_restricted_to_mods,omitempty" url:"posting_restricted_to_mods,omitempty"` + DiscussionLanguages Optional[[]int] `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type HideCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Hidden bool `json:"hidden,omitempty" url:"hidden,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type DeleteCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type RemoveCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Removed bool `json:"removed,omitempty" url:"removed,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Expires Optional[int64] `json:"expires,omitempty" url:"expires,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type FollowCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Follow bool `json:"follow,omitempty" url:"follow,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type BlockCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Block bool `json:"block,omitempty" url:"block,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type BlockCommunityResponse struct { + CommunityView CommunityView `json:"community_view,omitempty" url:"community_view,omitempty"` + Blocked bool `json:"blocked,omitempty" url:"blocked,omitempty"` + LemmyResponse +} + +type TransferCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} diff --git a/types/optional.go b/types/optional.go new file mode 100644 index 0000000..a87b941 --- /dev/null +++ b/types/optional.go @@ -0,0 +1,103 @@ +package types + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "net/url" +) + +var ErrOptionalEmpty = errors.New("optional value is empty") + +type Optional[T any] struct { + value *T +} + +func NewOptional[T any](v T) Optional[T] { + return Optional[T]{value: &v} +} + +func NewOptionalPtr[T any](v *T) Optional[T] { + return Optional[T]{value: v} +} + +func NewOptionalNil[T any]() Optional[T] { + return Optional[T]{} +} + +func (o Optional[T]) Set(v T) Optional[T] { + o.value = &v + return o +} + +func (o Optional[T]) SetPtr(v *T) Optional[T] { + o.value = v + return o +} + +func (o Optional[T]) SetNil() Optional[T] { + o.value = nil + return o +} + +func (o Optional[T]) IsValid() bool { + return o.value != nil +} + +func (o Optional[T]) MustValue() T { + if o.value == nil { + panic("optional value is nil") + } + return *o.value +} + +func (o Optional[T]) Value() (T, error) { + if o.value != nil { + return *o.value, ErrOptionalEmpty + } + return *new(T), nil +} + +func (o Optional[T]) ValueOr(fallback T) T { + if o.value != nil { + return *o.value + } + return fallback +} + +func (o Optional[T]) MarshalJSON() ([]byte, error) { + return json.Marshal(o.value) +} + +func (o *Optional[T]) UnmarshalJSON(b []byte) error { + if bytes.Equal(b, []byte("null")) { + o.value = nil + return nil + } + + o.value = new(T) + return json.Unmarshal(b, o.value) +} + +func (o Optional[T]) EncodeValues(key string, v *url.Values) error { + s := o.String() + if s != "" { + v.Set(key, s) + } + return nil +} + +func (o Optional[T]) String() string { + if o.value == nil { + return "" + } + return fmt.Sprint(*o.value) +} + +func (o Optional[T]) GoString() string { + if o.value == nil { + return "nil" + } + return fmt.Sprintf("%#v", *o.value) +} diff --git a/types/others.go b/types/others.go new file mode 100644 index 0000000..e54d0a7 --- /dev/null +++ b/types/others.go @@ -0,0 +1,169 @@ +package types + +/*type SiteMetadata struct { + Title Optional[string] `json:"title,omitempty" url:"title,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Image Optional[string] `json:"image,omitempty" url:"image,omitempty"` + HTML Optional[string] `json:"html,omitempty" url:"html,omitempty"` +}*/ + +type UserOperation int + +const ( + LoginOp UserOperation = iota + RegisterOp + GetCaptchaOp + CreateCommunityOp + CreatePostOp + ListCommunitiesOp + GetPostOp + GetCommunityOp + CreateCommentOp + EditCommentOp + DeleteCommentOp + RemoveCommentOp + SaveCommentOp + CreateCommentLikeOp + GetPostsOp + CreatePostLikeOp + EditPostOp + DeletePostOp + RemovePostOp + LockPostOp + StickyPostOp + MarkPostAsReadOp + SavePostOp + EditCommunityOp + DeleteCommunityOp + RemoveCommunityOp + FollowCommunityOp + GetPersonDetailsOp + GetRepliesOp + GetPersonMentionsOp + MarkPersonMentionAsReadOp + MarkCommentReplyAsReadOp + GetModlogOp + BanFromCommunityOp + AddModToCommunityOp + CreateSiteOp + EditSiteOp + GetSiteOp + AddAdminOp + GetUnreadRegistrationApplicationCountOp + ListRegistrationApplicationsOp + ApproveRegistrationApplicationOp + BanPersonOp + GetBannedPersonsOp + SearchOp + ResolveObjectOp + MarkAllAsReadOp + SaveUserSettingsOp + TransferCommunityOp + LeaveAdminOp + DeleteAccountOp + PasswordResetOp + PasswordChangeOp + CreatePrivateMessageOp + EditPrivateMessageOp + DeletePrivateMessageOp + MarkPrivateMessageAsReadOp + CreatePrivateMessageReportOp + ResolvePrivateMessageReportOp + ListPrivateMessageReportsOp + GetPrivateMessagesOp + UserJoinOp + GetCommentsOp + PostJoinOp + CommunityJoinOp + ChangePasswordOp + GetSiteMetadataOp + BlockCommunityOp + BlockPersonOp + PurgePersonOp + PurgeCommunityOp + PurgePostOp + PurgeCommentOp + CreateCommentReportOp + ResolveCommentReportOp + ListCommentReportsOp + CreatePostReportOp + ResolvePostReportOp + ListPostReportsOp + GetReportCountOp + GetUnreadCountOp + VerifyEmailOp +) + +type SortType string + +const ( + Active SortType = "Active" + Hot SortType = "Hot" + New SortType = "New" + Old SortType = "Old" + TopDay SortType = "TopDay" + TopWeek SortType = "TopWeek" + TopMonth SortType = "TopMonth" + TopYear SortType = "TopYear" + TopAll SortType = "TopAll" + MostComments SortType = "MostComments" + NewComments SortType = "NewComments" +) + +type CommentSortType string + +const ( + CommentSortHot CommentSortType = "Hot" + CommentSortTop CommentSortType = "Top" + CommentSortNew CommentSortType = "New" + CommentSortOld CommentSortType = "Old" +) + +type ListingType string + +const ( + ListingAll ListingType = "All" + ListingLocal ListingType = "Local" + ListingSubscribed ListingType = "Subscribed" + ListingCommunity ListingType = "Community" +) + +type SearchType string + +const ( + SearchAll SearchType = "All" + SearchComments SearchType = "Comments" + SearchPosts SearchType = "Posts" + SearchCommunities SearchType = "Communities" + SearchUsers SearchType = "Users" + SearchURL SearchType = "URL" +) + +type ModlogActionType string + +const ( + ModlogAll ModlogActionType = "All" + ModlogModRemovePost ModlogActionType = "ModRemovePost" + ModlogModLockPost ModlogActionType = "ModLockPost" + ModlogModStickyPost ModlogActionType = "ModStickyPost" + ModlogModRemoveComment ModlogActionType = "ModRemoveComment" + ModlogModRemoveCommunity ModlogActionType = "ModRemoveCommunity" + ModlogModBanFromCommunity ModlogActionType = "ModBanFromCommunity" + ModlogModAddCommunity ModlogActionType = "ModAddCommunity" + ModlogModTransferCommunity ModlogActionType = "ModTransferCommunity" + ModlogModAdd ModlogActionType = "ModAdd" + ModlogModBan ModlogActionType = "ModBan" + ModlogModHideCommunity ModlogActionType = "ModHideCommunity" + ModlogAdminPurgePerson ModlogActionType = "AdminPurgePerson" + ModlogAdminPurgeCommunity ModlogActionType = "AdminPurgeCommunity" + ModlogAdminPurgePost ModlogActionType = "AdminPurgePost" + ModlogAdminPurgeComment ModlogActionType = "AdminPurgeComment" +) + +type SubscribedType string + +const ( + Subscribed SubscribedType = "Subscribed" + NotSubscribed SubscribedType = "NotSubscribed" + Pending SubscribedType = "Pending" +) diff --git a/types/person.go b/types/person.go new file mode 100644 index 0000000..11e22e0 --- /dev/null +++ b/types/person.go @@ -0,0 +1,243 @@ +package types + +type Login struct { + Password string `json:"password,omitempty" url:"password,omitempty"` + UsernameOrEmail string `json:"username_or_email,omitempty" url:"username_or_email,omitempty"` +} + +type LoginResponse struct { + JWT Optional[string] `json:"jwt,omitempty" url:"jwt,omitempty"` + RegistrationCreated bool `json:"registration_created,omitempty" url:"registration_created,omitempty"` + VeriftEmailSent bool `json:"verify_email_sent,omitempty" url:"verify_email_sent,omitempty"` + LemmyResponse +} + +type Register struct { + Username string `json:"username,omitempty" url:"username,omitempty"` + Password string `json:"password,omitempty" url:"password,omitempty"` + PasswordVerify string `json:"password_verify,omitempty" url:"password_verify,omitempty"` + ShowNSFW bool `json:"show_nsfw,omitempty" url:"show_nsfw,omitempty"` + Email Optional[string] `json:"email,omitempty" url:"email,omitempty"` + CaptchaUuid Optional[string] `json:"captcha_uuid,omitempty" url:"captcha_uuid,omitempty"` + CaptchaAnswer Optional[string] `json:"captcha_answer,omitempty" url:"captcha_answer,omitempty"` + Honeypot Optional[string] `json:"honeypot,omitempty" url:"honeypot,omitempty"` + Answer Optional[string] `json:"answer,omitempty" url:"answer,omitempty"` +} + +type GetCaptcha struct{} + +type CaptchaResponse struct { + Png string `json:"png,omitempty" url:"png,omitempty"` + Wav string `json:"wav,omitempty" url:"wav,omitempty"` + Uuid string `json:"uuid,omitempty" url:"uuid,omitempty"` + LemmyResponse +} + +type SaveUserSettings struct { + ShowNSFW Optional[bool] `json:"show_nsfw,omitempty" url:"show_nsfw,omitempty"` + ShowScores Optional[bool] `json:"show_scores,omitempty" url:"show_scores,omitempty"` + Theme Optional[string] `json:"theme,omitempty" url:"theme,omitempty"` + DefaultSortType Optional[int16] `json:"default_sort_type,omitempty" url:"default_sort_type,omitempty"` + DefaultListingType Optional[int16] `json:"default_listing_type,omitempty" url:"default_listing_type,omitempty"` + InterfaceLanguage Optional[string] `json:"interface_language,omitempty" url:"interface_language,omitempty"` + Avatar Optional[string] `json:"avatar,omitempty" url:"avatar,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + DisplayName Optional[string] `json:"display_name,omitempty" url:"display_name,omitempty"` + Email Optional[string] `json:"email,omitempty" url:"email,omitempty"` + Bio Optional[string] `json:"bio,omitempty" url:"bio,omitempty"` + MatrixUserID Optional[string] `json:"matrix_user_id,omitempty" url:"matrix_user_id,omitempty"` + ShowAvatars Optional[bool] `json:"show_avatars,omitempty" url:"show_avatars,omitempty"` + SendNotificationsToEmail Optional[bool] `json:"send_notifications_to_email,omitempty" url:"send_notifications_to_email,omitempty"` + BotAccount Optional[bool] `json:"bot_account,omitempty" url:"bot_account,omitempty"` + ShowBotAccounts Optional[bool] `json:"show_bot_accounts,omitempty" url:"show_bot_accounts,omitempty"` + ShowReadPosts Optional[bool] `json:"show_read_posts,omitempty" url:"show_read_posts,omitempty"` + ShowNewPostNotifs Optional[bool] `json:"show_new_post_notifs,omitempty" url:"show_new_post_notifs,omitempty"` + DiscussionLanguages Optional[[]int] `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ChangePassword struct { + NewPassword string `json:"new_password,omitempty" url:"new_password,omitempty"` + NewPasswordVerify string `json:"new_password_verify,omitempty" url:"new_password_verify,omitempty"` + OldPassword string `json:"old_password,omitempty" url:"old_password,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetPersonDetails struct { + PersonID Optional[int] `json:"person_id,omitempty" url:"person_id,omitempty"` + Username Optional[string] `json:"username,omitempty" url:"username,omitempty"` + Sort Optional[SortType] `json:"sort,omitempty" url:"sort,omitempty"` + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + SavedOnly Optional[bool] `json:"saved_only,omitempty" url:"saved_only,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetPersonDetailsResponse struct { + PersonView PersonViewSafe `json:"person_view,omitempty" url:"person_view,omitempty"` + Comments []CommentView `json:"comments,omitempty" url:"comments,omitempty"` + Posts []PostView `json:"posts,omitempty" url:"posts,omitempty"` + Moderates []CommunityModeratorView `json:"moderates,omitempty" url:"moderates,omitempty"` + LemmyResponse +} + +type GetReplies struct { + Limit Optional[int] `json:"limit,omitempty" url:"limit,omitempty"` + Page Optional[int] `json:"page,omitempty" url:"page,omitempty"` + Sort Optional[CommentSortType] `json:"sort,omitempty" url:"sort,omitempty"` + UnreadOnly Optional[bool] `json:"unread_only,omitempty" url:"unread_only,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetRepliesResponse struct { + Replies []CommentReplyView `json:"replies,omitempty" url:"replies,omitempty"` + LemmyResponse +} + +type GetPersonMentionsResponse struct { + Mentions []PersonMentionView `json:"mentions,omitempty" url:"mentions,omitempty"` + LemmyResponse +} + +type MarkAllAsRead struct { + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type AddAdmin struct { + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Added bool `json:"added,omitempty" url:"added,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type AddAdminResponse struct { + Admins []PersonViewSafe `json:"admins,omitempty" url:"admins,omitempty"` + LemmyResponse +} + +type BanPerson struct { + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Ban bool `json:"ban,omitempty" url:"ban,omitempty"` + RemoveData Optional[bool] `json:"remove_data,omitempty" url:"remove_data,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Expires Optional[int64] `json:"expires,omitempty" url:"expires,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetBannedPersons struct { + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type BanPersonResponse struct { + PersonView PersonViewSafe `json:"person_view,omitempty" url:"person_view,omitempty"` + Banned bool `json:"banned,omitempty" url:"banned,omitempty"` + LemmyResponse +} + +type BlockPerson struct { + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Block bool `json:"block,omitempty" url:"block,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetPersonMentions struct { + Sort Optional[CommentSortType] `json:"sort,omitempty" url:"sort,omitempty"` + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + UnreadOnly Optional[bool] `json:"unread_only,omitempty" url:"unread_only,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type MarkPersonMentionAsRead struct { + PersonMentionID int `json:"person_mention_id,omitempty" url:"person_mention_id,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PersonMentionResponse struct { + PersonMentionView PersonMentionView `json:"person_mention_view,omitempty" url:"person_mention_view,omitempty"` + LemmyResponse +} + +type MarkCommentReplyAsRead struct { + CommentReplyID int `json:"comment_reply_id,omitempty" url:"comment_reply_id,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type CommentReplyResponse struct { + CommentReplyView CommentReplyView `json:"comment_reply_view,omitempty" url:"comment_reply_view,omitempty"` + LemmyResponse +} + +type DeleteAccount struct { + Password string `json:"password,omitempty" url:"password,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type DeleteAccountResponse struct { + LemmyResponse +} + +type PasswordReset struct { + Email string `json:"email,omitempty" url:"email,omitempty"` +} + +type PasswordResetResponse struct { + LemmyResponse +} + +type PasswordChangeAfterReset struct { + Token string `json:"token,omitempty" url:"token,omitempty"` + Password string `json:"password,omitempty" url:"password,omitempty"` + PasswordVerify string `json:"password_verify,omitempty" url:"password_verify,omitempty"` +} + +type GetReportCount struct { + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetReportCountResponse struct { + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + CommentReports int64 `json:"comment_reports,omitempty" url:"comment_reports,omitempty"` + PostReports int64 `json:"post_reports,omitempty" url:"post_reports,omitempty"` + PrivateMessageReports Optional[int64] `json:"private_message_reports,omitempty" url:"private_message_reports,omitempty"` + LemmyResponse +} + +type GetUnreadCount struct { + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetUnreadCountResponse struct { + Replies int64 `json:"replies,omitempty" url:"replies,omitempty"` + Mentions int64 `json:"mentions,omitempty" url:"mentions,omitempty"` + PrivateMessages int64 `json:"private_messages,omitempty" url:"private_messages,omitempty"` + LemmyResponse +} + +type VerifyEmail struct { + Token string `json:"token,omitempty" url:"token,omitempty"` +} + +type VerifyEmailResponse struct { + LemmyResponse +} + +type BlockPersonResponse struct { + Blocked bool `json:"blocked,omitempty" url:"blocked,omitempty"` + PersonView PersonViewSafe `json:"person_view,omitempty" url:"person_view,omitempty"` + LemmyResponse +} + +type BannedPersonsResponse struct { + Banned []PersonViewSafe `json:"banned,omitempty" url:"banned,omitempty"` + LemmyResponse +} + +type PasswordChange struct { + Password string `json:"password,omitempty" url:"password,omitempty"` + PasswordVerify string `json:"password_verify,omitempty" url:"password_verify,omitempty"` + Token string `json:"token,omitempty" url:"token,omitempty"` +} diff --git a/types/post.go b/types/post.go new file mode 100644 index 0000000..49003e7 --- /dev/null +++ b/types/post.go @@ -0,0 +1,146 @@ +package types + +type CreatePost struct { + Name string `json:"name,omitempty" url:"name,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + URL Optional[string] `json:"url,omitempty" url:"url,omitempty"` + Body Optional[string] `json:"body,omitempty" url:"body,omitempty"` + Honeypot Optional[string] `json:"honeypot,omitempty" url:"honeypot,omitempty"` + NSFW Optional[bool] `json:"nsfw,omitempty" url:"nsfw,omitempty"` + LanguageID Optional[int] `json:"language_id,omitempty" url:"language_id,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PostResponse struct { + PostView PostView `json:"post_view,omitempty" url:"post_view,omitempty"` + LemmyResponse +} + +type GetPost struct { + ID Optional[int] `json:"id,omitempty" url:"id,omitempty"` + CommentID Optional[int] `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetPostResponse struct { + PostView PostView `json:"post_view,omitempty" url:"post_view,omitempty"` + CommunityView CommunityView `json:"community_view,omitempty" url:"community_view,omitempty"` + Moderators []CommunityModeratorView `json:"moderators,omitempty" url:"moderators,omitempty"` + Online uint `json:"online,omitempty" url:"online,omitempty"` + LemmyResponse +} + +type GetPosts struct { + Type Optional[ListingType] `json:"type,omitempty" url:"type,omitempty"` + Sort Optional[SortType] `json:"sort,omitempty" url:"sort,omitempty"` + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + CommunityName Optional[string] `json:"community_name,omitempty" url:"community_name,omitempty"` + SavedOnly Optional[bool] `json:"saved_only,omitempty" url:"saved_only,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetPostsResponse struct { + Posts []PostView `json:"posts,omitempty" url:"posts,omitempty"` + LemmyResponse +} + +type CreatePostLike struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Score int16 `json:"score,omitempty" url:"score,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type EditPost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Name Optional[string] `json:"name,omitempty" url:"name,omitempty"` + URL Optional[string] `json:"url,omitempty" url:"url,omitempty"` + Body Optional[string] `json:"body,omitempty" url:"body,omitempty"` + NSFW Optional[bool] `json:"nsfw,omitempty" url:"nsfw,omitempty"` + LanguageID Optional[int] `json:"language_id,omitempty" url:"language_id,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type DeletePost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type RemovePost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Removed bool `json:"removed,omitempty" url:"removed,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type MarkPostAsRead struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type LockPost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Locked bool `json:"locked,omitempty" url:"locked,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type StickyPost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Stickied bool `json:"stickied,omitempty" url:"stickied,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type SavePost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Save bool `json:"save,omitempty" url:"save,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type CreatePostReport struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Reason string `json:"reason,omitempty" url:"reason,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PostReportResponse struct { + PostReportView PostReportView `json:"post_report_view,omitempty" url:"post_report_view,omitempty"` + LemmyResponse +} + +type ResolvePostReport struct { + ReportID int `json:"report_id,omitempty" url:"report_id,omitempty"` + Resolved bool `json:"resolved,omitempty" url:"resolved,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListPostReports struct { + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + UnresolvedOnly Optional[bool] `json:"unresolved_only,omitempty" url:"unresolved_only,omitempty"` + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListPostReportsResponse struct { + PostReports []PostReportView `json:"post_reports,omitempty" url:"post_reports,omitempty"` + LemmyResponse +} + +type GetSiteMetadata struct { + URL string `json:"url,omitempty" url:"url,omitempty"` +} + +type GetSiteMetadataResponse struct { + Metadata SiteMetadata `json:"metadata,omitempty" url:"metadata,omitempty"` + LemmyResponse +} + +type SiteMetadata struct { + Title Optional[string] `json:"title,omitempty" url:"title,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Image Optional[string] `json:"image,omitempty" url:"image,omitempty"` + EmbedVideoURL Optional[string] `json:"embed_video_url,omitempty" url:"embed_video_url,omitempty"` +} diff --git a/types/privateMessage.go b/types/privateMessage.go new file mode 100644 index 0000000..4d469ef --- /dev/null +++ b/types/privateMessage.go @@ -0,0 +1,71 @@ +package types + +type CreatePrivateMessage struct { + Content string `json:"content,omitempty" url:"content,omitempty"` + RecipientID int `json:"recipient_id,omitempty" url:"recipient_id,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type EditPrivateMessage struct { + PrivateMessageID int `json:"private_message_id,omitempty" url:"private_message_id,omitempty"` + Content string `json:"content,omitempty" url:"content,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type DeletePrivateMessage struct { + PrivateMessageID int `json:"private_message_id,omitempty" url:"private_message_id,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type MarkPrivateMessageAsRead struct { + PrivateMessageID int `json:"private_message_id,omitempty" url:"private_message_id,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetPrivateMessages struct { + UnreadOnly Optional[bool] `json:"unread_only,omitempty" url:"unread_only,omitempty"` + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PrivateMessagesResponse struct { + PrivateMessages []PrivateMessageView `json:"private_messages,omitempty" url:"private_messages,omitempty"` + LemmyResponse +} + +type PrivateMessageResponse struct { + PrivateMessageView PrivateMessageView `json:"private_message_view,omitempty" url:"private_message_view,omitempty"` + LemmyResponse +} + +type CreatePrivateMessageReport struct { + PrivateMessageID int `json:"private_message_id,omitempty" url:"private_message_id,omitempty"` + Reason string `json:"reason,omitempty" url:"reason,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PrivateMessageReportResponse struct { + PrivateMessageReportView PrivateMessageReportView `json:"private_message_report_view,omitempty" url:"private_message_report_view,omitempty"` + LemmyResponse +} + +type ResolvePrivateMessageReport struct { + ReportID int `json:"report_id,omitempty" url:"report_id,omitempty"` + Resolved bool `json:"resolved,omitempty" url:"resolved,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListPrivateMessageReports struct { + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + UnresolvedOnly Optional[bool] `json:"unresolved_only,omitempty" url:"unresolved_only,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListPrivateMessageReportsResponse struct { + PrivateMessageReports []PrivateMessageReportView `json:"private_message_reports,omitempty" url:"private_message_reports,omitempty"` + LemmyResponse +} diff --git a/types/site.go b/types/site.go new file mode 100644 index 0000000..9e56c21 --- /dev/null +++ b/types/site.go @@ -0,0 +1,244 @@ +package types + +type SearchResponse struct { + Type string `json:"type,omitempty" url:"type,omitempty"` + Comments []CommentView `json:"comments,omitempty" url:"comments,omitempty"` + Posts []PostView `json:"posts,omitempty" url:"posts,omitempty"` + Communities []CommunityView `json:"communities,omitempty" url:"communities,omitempty"` + Users []PersonViewSafe `json:"users,omitempty" url:"users,omitempty"` + LemmyResponse +} + +type ResolveObject struct { + Q string `json:"q,omitempty" url:"q,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ResolveObjectResponse struct { + Comment Optional[CommentView] `json:"comment,omitempty" url:"comment,omitempty"` + Post Optional[PostView] `json:"post,omitempty" url:"post,omitempty"` + Community Optional[CommunityView] `json:"community,omitempty" url:"community,omitempty"` + Person Optional[PersonViewSafe] `json:"person,omitempty" url:"person,omitempty"` + LemmyResponse +} + +type GetModlog struct { + ModPersonID Optional[int] `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + CommunityID Optional[int] `json:"community_id,omitempty" url:"community_id,omitempty"` + Page Optional[int64] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int64] `json:"limit,omitempty" url:"limit,omitempty"` + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` + Type Optional[ModlogActionType] `json:"type,omitempty" url:"type,omitempty"` + OtherPersonID Optional[int] `json:"other_person_id,omitempty" url:"other_person_id,omitempty"` +} + +type GetModlogResponse struct { + RemovedPosts []ModRemovePostView `json:"removed_posts,omitempty" url:"removed_posts,omitempty"` + LockedPosts []ModLockPostView `json:"locked_posts,omitempty" url:"locked_posts,omitempty"` + StickiedPosts []ModStickyPostView `json:"stickied_posts,omitempty" url:"stickied_posts,omitempty"` + RemovedComments []ModRemoveCommentView `json:"removed_comments,omitempty" url:"removed_comments,omitempty"` + RemovedCommunities []ModRemoveCommunityView `json:"removed_communities,omitempty" url:"removed_communities,omitempty"` + BannedFromCommunity []ModBanFromCommunityView `json:"banned_from_community,omitempty" url:"banned_from_community,omitempty"` + Banned []ModBanView `json:"banned,omitempty" url:"banned,omitempty"` + AddedToCommunity []ModAddCommunityView `json:"added_to_community,omitempty" url:"added_to_community,omitempty"` + TransferredToCommunity []ModTransferCommunityView `json:"transferred_to_community,omitempty" url:"transferred_to_community,omitempty"` + Added []ModAddView `json:"added,omitempty" url:"added,omitempty"` + AdminPurgedPersons []AdminPurgePersonView `json:"admin_purged_persons,omitempty" url:"admin_purged_persons,omitempty"` + AdminPurgedCommunities []AdminPurgeCommunityView `json:"admin_purged_communities,omitempty" url:"admin_purged_communities,omitempty"` + AdminPurgedPosts []AdminPurgePostView `json:"admin_purged_posts,omitempty" url:"admin_purged_posts,omitempty"` + AdminPurgedComments []AdminPurgeCommentView `json:"admin_purged_comments,omitempty" url:"admin_purged_comments,omitempty"` + HiddenCommunities []ModHideCommunityView `json:"hidden_communities,omitempty" url:"hidden_communities,omitempty"` + LemmyResponse +} + +type CreateSite struct { + Name string `json:"name,omitempty" url:"name,omitempty"` + Sidebar Optional[string] `json:"sidebar,omitempty" url:"sidebar,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Icon Optional[string] `json:"icon,omitempty" url:"icon,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + EnableDownvotes Optional[bool] `json:"enable_downvotes,omitempty" url:"enable_downvotes,omitempty"` + OpenRegistration Optional[bool] `json:"open_registration,omitempty" url:"open_registration,omitempty"` + EnableNSFW Optional[bool] `json:"enable_nsfw,omitempty" url:"enable_nsfw,omitempty"` + CommunityCreationAdminOnly Optional[bool] `json:"community_creation_admin_only,omitempty" url:"community_creation_admin_only,omitempty"` + RequireEmailVerification Optional[bool] `json:"require_email_verification,omitempty" url:"require_email_verification,omitempty"` + RequireApplication Optional[bool] `json:"require_application,omitempty" url:"require_application,omitempty"` + ApplicationQuestion Optional[string] `json:"application_question,omitempty" url:"application_question,omitempty"` + PrivateInstance Optional[bool] `json:"private_instance,omitempty" url:"private_instance,omitempty"` + DefaultTheme Optional[string] `json:"default_theme,omitempty" url:"default_theme,omitempty"` + DefaultPostListingType Optional[string] `json:"default_post_listing_type,omitempty" url:"default_post_listing_type,omitempty"` + LegalInformation Optional[string] `json:"legal_information,omitempty" url:"legal_information,omitempty"` + ApplicationEmailAdmins Optional[bool] `json:"application_email_admins,omitempty" url:"application_email_admins,omitempty"` + HideModlogModNames Optional[bool] `json:"hide_modlog_mod_names,omitempty" url:"hide_modlog_mod_names,omitempty"` + DiscussionLanguages Optional[[]int] `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` + SlurFilterRegex Optional[string] `json:"slur_filter_regex,omitempty" url:"slur_filter_regex,omitempty"` + ActorNameMaxLength Optional[int] `json:"actor_name_max_length,omitempty" url:"actor_name_max_length,omitempty"` + RateLimitMessage Optional[int] `json:"rate_limit_message,omitempty" url:"rate_limit_message,omitempty"` + RateLimitMessagePerSecond Optional[int] `json:"rate_limit_message_per_second,omitempty" url:"rate_limit_message_per_second,omitempty"` + RateLimitPost Optional[int] `json:"rate_limit_post,omitempty" url:"rate_limit_post,omitempty"` + RateLimitPostPerSecond Optional[int] `json:"rate_limit_post_per_second,omitempty" url:"rate_limit_post_per_second,omitempty"` + RateLimitRegister Optional[int] `json:"rate_limit_register,omitempty" url:"rate_limit_register,omitempty"` + RateLimitRegisterPerSecond Optional[int] `json:"rate_limit_register_per_second,omitempty" url:"rate_limit_register_per_second,omitempty"` + RateLimitImage Optional[int] `json:"rate_limit_image,omitempty" url:"rate_limit_image,omitempty"` + RateLimitImagePerSecond Optional[int] `json:"rate_limit_image_per_second,omitempty" url:"rate_limit_image_per_second,omitempty"` + RateLimitComment Optional[int] `json:"rate_limit_comment,omitempty" url:"rate_limit_comment,omitempty"` + RateLimitCommentPerSecond Optional[int] `json:"rate_limit_comment_per_second,omitempty" url:"rate_limit_comment_per_second,omitempty"` + RateLimitSearch Optional[int] `json:"rate_limit_search,omitempty" url:"rate_limit_search,omitempty"` + RateLimitSearchPerSecond Optional[int] `json:"rate_limit_search_per_second,omitempty" url:"rate_limit_search_per_second,omitempty"` + FederationEnabled Optional[bool] `json:"federation_enabled,omitempty" url:"federation_enabled,omitempty"` + FederationDebug Optional[bool] `json:"federation_debug,omitempty" url:"federation_debug,omitempty"` + FederationWorkerCount Optional[int] `json:"federation_worker_count,omitempty" url:"federation_worker_count,omitempty"` + CaptchaEnabled Optional[bool] `json:"captcha_enabled,omitempty" url:"captcha_enabled,omitempty"` + CaptchaDifficulty Optional[string] `json:"captcha_difficulty,omitempty" url:"captcha_difficulty,omitempty"` + AllowedInstances Optional[[]string] `json:"allowed_instances,omitempty" url:"allowed_instances,omitempty"` + BlockedInstances Optional[[]string] `json:"blocked_instances,omitempty" url:"blocked_instances,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type EditSite struct { + Name Optional[string] `json:"name,omitempty" url:"name,omitempty"` + Sidebar Optional[string] `json:"sidebar,omitempty" url:"sidebar,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Icon Optional[string] `json:"icon,omitempty" url:"icon,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + EnableDownvotes Optional[bool] `json:"enable_downvotes,omitempty" url:"enable_downvotes,omitempty"` + OpenRegistration Optional[bool] `json:"open_registration,omitempty" url:"open_registration,omitempty"` + EnableNSFW Optional[bool] `json:"enable_nsfw,omitempty" url:"enable_nsfw,omitempty"` + CommunityCreationAdminOnly Optional[bool] `json:"community_creation_admin_only,omitempty" url:"community_creation_admin_only,omitempty"` + RequireEmailVerification Optional[bool] `json:"require_email_verification,omitempty" url:"require_email_verification,omitempty"` + RequireApplication Optional[bool] `json:"require_application,omitempty" url:"require_application,omitempty"` + ApplicationQuestion Optional[string] `json:"application_question,omitempty" url:"application_question,omitempty"` + PrivateInstance Optional[bool] `json:"private_instance,omitempty" url:"private_instance,omitempty"` + DefaultTheme Optional[string] `json:"default_theme,omitempty" url:"default_theme,omitempty"` + DefaultPostListingType Optional[string] `json:"default_post_listing_type,omitempty" url:"default_post_listing_type,omitempty"` + LegalInformation Optional[string] `json:"legal_information,omitempty" url:"legal_information,omitempty"` + ApplicationEmailAdmins Optional[bool] `json:"application_email_admins,omitempty" url:"application_email_admins,omitempty"` + HideModlogModNames Optional[bool] `json:"hide_modlog_mod_names,omitempty" url:"hide_modlog_mod_names,omitempty"` + DiscussionLanguages Optional[[]int] `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` + SlurFilterRegex Optional[string] `json:"slur_filter_regex,omitempty" url:"slur_filter_regex,omitempty"` + ActorNameMaxLength Optional[int] `json:"actor_name_max_length,omitempty" url:"actor_name_max_length,omitempty"` + RateLimitMessage Optional[int] `json:"rate_limit_message,omitempty" url:"rate_limit_message,omitempty"` + RateLimitMessagePerSecond Optional[int] `json:"rate_limit_message_per_second,omitempty" url:"rate_limit_message_per_second,omitempty"` + RateLimitPost Optional[int] `json:"rate_limit_post,omitempty" url:"rate_limit_post,omitempty"` + RateLimitPostPerSecond Optional[int] `json:"rate_limit_post_per_second,omitempty" url:"rate_limit_post_per_second,omitempty"` + RateLimitRegister Optional[int] `json:"rate_limit_register,omitempty" url:"rate_limit_register,omitempty"` + RateLimitRegisterPerSecond Optional[int] `json:"rate_limit_register_per_second,omitempty" url:"rate_limit_register_per_second,omitempty"` + RateLimitImage Optional[int] `json:"rate_limit_image,omitempty" url:"rate_limit_image,omitempty"` + RateLimitImagePerSecond Optional[int] `json:"rate_limit_image_per_second,omitempty" url:"rate_limit_image_per_second,omitempty"` + RateLimitComment Optional[int] `json:"rate_limit_comment,omitempty" url:"rate_limit_comment,omitempty"` + RateLimitCommentPerSecond Optional[int] `json:"rate_limit_comment_per_second,omitempty" url:"rate_limit_comment_per_second,omitempty"` + RateLimitSearch Optional[int] `json:"rate_limit_search,omitempty" url:"rate_limit_search,omitempty"` + RateLimitSearchPerSecond Optional[int] `json:"rate_limit_search_per_second,omitempty" url:"rate_limit_search_per_second,omitempty"` + FederationEnabled Optional[bool] `json:"federation_enabled,omitempty" url:"federation_enabled,omitempty"` + FederationDebug Optional[bool] `json:"federation_debug,omitempty" url:"federation_debug,omitempty"` + FederationWorkerCount Optional[int] `json:"federation_worker_count,omitempty" url:"federation_worker_count,omitempty"` + CaptchaEnabled Optional[bool] `json:"captcha_enabled,omitempty" url:"captcha_enabled,omitempty"` + CaptchaDifficulty Optional[string] `json:"captcha_difficulty,omitempty" url:"captcha_difficulty,omitempty"` + AllowedInstances Optional[[]string] `json:"allowed_instances,omitempty" url:"allowed_instances,omitempty"` + BlockedInstances Optional[[]string] `json:"blocked_instances,omitempty" url:"blocked_instances,omitempty"` + Taglines Optional[[]string] `json:"taglines,omitempty" url:"taglines,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetSite struct { + Auth Optional[string] `json:"auth,omitempty" url:"auth,omitempty"` +} + +type SiteResponse struct { + SiteView SiteView `json:"site_view,omitempty" url:"site_view,omitempty"` + LemmyResponse +} + +type GetSiteResponse struct { + SiteView SiteView `json:"site_view,omitempty" url:"site_view,omitempty"` + Admins []PersonViewSafe `json:"admins,omitempty" url:"admins,omitempty"` + Online int `json:"online,omitempty" url:"online,omitempty"` + Version string `json:"version,omitempty" url:"version,omitempty"` + MyUser Optional[MyUserInfo] `json:"my_user,omitempty" url:"my_user,omitempty"` + FederatedInstances Optional[FederatedInstances] `json:"federated_instances,omitempty" url:"federated_instances,omitempty"` + AllLanguages []Language `json:"all_languages,omitempty" url:"all_languages,omitempty"` + DiscussionLanguages []int `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` + Taglines Optional[[]Tagline] `json:"taglines,omitempty" url:"taglines,omitempty"` + LemmyResponse +} + +type MyUserInfo struct { + LocalUserView LocalUserSettingsView `json:"local_user_view,omitempty" url:"local_user_view,omitempty"` + Follows []CommunityFollowerView `json:"follows,omitempty" url:"follows,omitempty"` + Moderates []CommunityModeratorView `json:"moderates,omitempty" url:"moderates,omitempty"` + CommunityBlocks []CommunityBlockView `json:"community_blocks,omitempty" url:"community_blocks,omitempty"` + PersonBlocks []PersonBlockView `json:"person_blocks,omitempty" url:"person_blocks,omitempty"` + DiscussionLanguages []Language `json:"discussion_languages,omitempty" url:"discussion_languages,omitempty"` +} + +type LeaveAdmin struct { + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type FederatedInstances struct { + Linked []string `json:"linked,omitempty" url:"linked,omitempty"` + Allowed Optional[[]string] `json:"allowed,omitempty" url:"allowed,omitempty"` + Blocked Optional[[]string] `json:"blocked,omitempty" url:"blocked,omitempty"` +} + +type PurgePerson struct { + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PurgeCommunity struct { + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PurgePost struct { + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PurgeComment struct { + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type PurgeItemResponse struct { + Success bool `json:"success,omitempty" url:"success,omitempty"` + LemmyResponse +} + +type ListRegistrationApplications struct { + UnreadOnly Optional[bool] `json:"unread_only,omitempty" url:"unread_only,omitempty"` + Page Optional[int] `json:"page,omitempty" url:"page,omitempty"` + Limit Optional[int] `json:"limit,omitempty" url:"limit,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type ListRegistrationApplicationsResponse struct { + RegistrationApplications []RegistrationApplicationView `json:"registration_applications,omitempty" url:"registration_applications,omitempty"` + LemmyResponse +} + +type ApproveRegistrationApplication struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Approve bool `json:"approve,omitempty" url:"approve,omitempty"` + DenyReason Optional[string] `json:"deny_reason,omitempty" url:"deny_reason,omitempty"` + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type RegistrationApplicationResponse struct { + RegistrationApplication RegistrationApplicationView `json:"registration_application,omitempty" url:"registration_application,omitempty"` + LemmyResponse +} + +type GetUnreadRegistrationApplicationCount struct { + Auth string `json:"auth,omitempty" url:"auth,omitempty"` +} + +type GetUnreadRegistrationApplicationCountResponse struct { + RegistrationApplications int `json:"registration_applications,omitempty" url:"registration_applications,omitempty"` + LemmyResponse +} diff --git a/types/source.go b/types/source.go new file mode 100644 index 0000000..06aca36 --- /dev/null +++ b/types/source.go @@ -0,0 +1,402 @@ +package types + +import "time" + +type LocalUserSettings struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + PersonID int `json:"person_id,omitempty" url:"person_id,omitempty"` + Email Optional[string] `json:"email,omitempty" url:"email,omitempty"` + ShowNSFW bool `json:"show_nsfw,omitempty" url:"show_nsfw,omitempty"` + Theme string `json:"theme,omitempty" url:"theme,omitempty"` + DefaultSortType int `json:"default_sort_type,omitempty" url:"default_sort_type,omitempty"` + DefaultListingType int `json:"default_listing_type,omitempty" url:"default_listing_type,omitempty"` + InterfaceLanguage string `json:"interface_language,omitempty" url:"interface_language,omitempty"` + ShowAvatars bool `json:"show_avatars,omitempty" url:"show_avatars,omitempty"` + SendNotifications bool `json:"send_notifications_to_email,omitempty" url:"send_notifications_to_email,omitempty"` + ValidatorTime string `json:"validator_time,omitempty" url:"validator_time,omitempty"` + ShowBotAccounts bool `json:"show_bot_accounts,omitempty" url:"show_bot_accounts,omitempty"` + ShowScores bool `json:"show_scores,omitempty" url:"show_scores,omitempty"` + ShowReadPosts bool `json:"show_read_posts,omitempty" url:"show_read_posts,omitempty"` + ShowNewPostNotifs bool `json:"show_new_post_notifs,omitempty" url:"show_new_post_notifs,omitempty"` + EmailVerified bool `json:"email_verified,omitempty" url:"email_verified,omitempty"` + AcceptedApplication bool `json:"accepted_application,omitempty" url:"accepted_application,omitempty"` +} + +type PersonSafe struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Name string `json:"name,omitempty" url:"name,omitempty"` + DisplayName Optional[string] `json:"display_name,omitempty" url:"display_name,omitempty"` + Avatar Optional[string] `json:"avatar,omitempty" url:"avatar,omitempty"` + Banned bool `json:"banned,omitempty" url:"banned,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` + ActorID string `json:"actor_id,omitempty" url:"actor_id,omitempty"` + Bio Optional[string] `json:"bio,omitempty" url:"bio,omitempty"` + Local bool `json:"local,omitempty" url:"local,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + InboxURL string `json:"inbox_url,omitempty" url:"inbox_url,omitempty"` + SharedInboxURL Optional[string] `json:"shared_inbox_url,omitempty" url:"shared_inbox_url,omitempty"` + MatrixUserID Optional[string] `json:"matrix_user_id,omitempty" url:"matrix_user_id,omitempty"` + Admin bool `json:"admin,omitempty" url:"admin,omitempty"` + BotAccount bool `json:"bot_account,omitempty" url:"bot_account,omitempty"` + BanExpires Optional[string] `json:"ban_expires,omitempty" url:"ban_expires,omitempty"` + InstanceID int `json:"instance_id,omitempty" url:"instance_id,omitempty"` +} + +type Site struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Name string `json:"name,omitempty" url:"name,omitempty"` + Sidebar Optional[string] `json:"sidebar,omitempty" url:"sidebar,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` + Icon Optional[string] `json:"icon,omitempty" url:"icon,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + ActorID string `json:"actor_id,omitempty" url:"actor_id,omitempty"` + LastRefreshedAt string `json:"last_refreshed_at,omitempty" url:"last_refreshed_at,omitempty"` + InboxURL string `json:"inbox_url,omitempty" url:"inbox_url,omitempty"` + PrivateKey Optional[string] `json:"private_key,omitempty" url:"private_key,omitempty"` + PublicKey string `json:"public_key,omitempty" url:"public_key,omitempty"` + InstanceID int `json:"instance_id,omitempty" url:"instance_id,omitempty"` +} + +type LocalSite struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + SiteID int `json:"site_id,omitempty" url:"site_id,omitempty"` + SiteSetup bool `json:"site_setup,omitempty" url:"site_setup,omitempty"` + EnableDownvotes bool `json:"enable_downvotes,omitempty" url:"enable_downvotes,omitempty"` + OpenRegistration bool `json:"open_registration,omitempty" url:"open_registration,omitempty"` + EnableNSFW bool `json:"enable_nsfw,omitempty" url:"enable_nsfw,omitempty"` + AdminOnlyCommunityCreation bool `json:"community_creation_admin_only,omitempty" url:"community_creation_admin_only,omitempty"` + RequireEmailVerification bool `json:"require_email_verification,omitempty" url:"require_email_verification,omitempty"` + RequireApplication bool `json:"require_application,omitempty" url:"require_application,omitempty"` + ApplicationQuestion Optional[string] `json:"application_question,omitempty" url:"application_question,omitempty"` + PrivateInstance bool `json:"private_instance,omitempty" url:"private_instance,omitempty"` + DefaultTheme string `json:"default_theme,omitempty" url:"default_theme,omitempty"` + DefaultPostListingType string `json:"default_post_listing_type,omitempty" url:"default_post_listing_type,omitempty"` + LegalInformation Optional[string] `json:"legal_information,omitempty" url:"legal_information,omitempty"` + HideModlogModNames bool `json:"hide_modlog_mod_names,omitempty" url:"hide_modlog_mod_names,omitempty"` + ApplicationEmailAdmins bool `json:"application_email_admins,omitempty" url:"application_email_admins,omitempty"` + SlurFilterRegex Optional[string] `json:"slur_filter_regex,omitempty" url:"slur_filter_regex,omitempty"` + ActorNameMaxLength int `json:"actor_name_max_length,omitempty" url:"actor_name_max_length,omitempty"` + FederationEnabled bool `json:"federation_enabled,omitempty" url:"federation_enabled,omitempty"` + FederationDebug bool `json:"federation_debug,omitempty" url:"federation_debug,omitempty"` + FederationStrictAllowlist bool `json:"federation_strict_allowlist,omitempty" url:"federation_strict_allowlist,omitempty"` + FederationRetryLimit int `json:"federation_http_fetch_retry_limit,omitempty" url:"federation_http_fetch_retry_limit,omitempty"` + FederationWorkerCount int `json:"federation_worker_count,omitempty" url:"federation_worker_count,omitempty"` + CaptchaEnabled bool `json:"captcha_enabled,omitempty" url:"captcha_enabled,omitempty"` + CaptchaDifficulty string `json:"captcha_difficulty,omitempty" url:"captcha_difficulty,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` +} + +type LocalSiteRateLimit struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + LocalSiteID int `json:"local_site_id,omitempty" url:"local_site_id,omitempty"` + Message int `json:"message,omitempty" url:"message,omitempty"` + MessagePerSecond int `json:"message_per_second,omitempty" url:"message_per_second,omitempty"` + Post int `json:"post,omitempty" url:"post,omitempty"` + PostPerSecond int `json:"post_per_second,omitempty" url:"post_per_second,omitempty"` + Register int `json:"register,omitempty" url:"register,omitempty"` + RegisterPerSecond int `json:"register_per_second,omitempty" url:"register_per_second,omitempty"` + Image int `json:"image,omitempty" url:"image,omitempty"` + ImagePerSecond int `json:"image_per_second,omitempty" url:"image_per_second,omitempty"` + Comment int `json:"comment,omitempty" url:"comment,omitempty"` + CommentPerSecond int `json:"comment_per_second,omitempty" url:"comment_per_second,omitempty"` + Search int `json:"search,omitempty" url:"search,omitempty"` + SearchPerSecond int `json:"search_per_second,omitempty" url:"search_per_second,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` +} + +type PrivateMessage struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CreatorID int `json:"creator_id,omitempty" url:"creator_id,omitempty"` + RecipientID int `json:"recipient_id,omitempty" url:"recipient_id,omitempty"` + Content string `json:"content,omitempty" url:"content,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` + ApID string `json:"ap_id,omitempty" url:"ap_id,omitempty"` + Local bool `json:"local,omitempty" url:"local,omitempty"` +} + +type PostReport struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CreatorID int `json:"creator_id,omitempty" url:"creator_id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + OriginalPostName string `json:"original_post_name,omitempty" url:"original_post_name,omitempty"` + OriginalPostURL Optional[string] `json:"original_post_url,omitempty" url:"original_post_url,omitempty"` + OriginalPostBody Optional[string] `json:"original_post_body,omitempty" url:"original_post_body,omitempty"` + Reason string `json:"reason,omitempty" url:"reason,omitempty"` + Resolved bool `json:"resolved,omitempty" url:"resolved,omitempty"` + ResolverID Optional[int] `json:"resolver_id,omitempty" url:"resolver_id,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` +} + +type Post struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Name string `json:"name,omitempty" url:"name,omitempty"` + URL Optional[string] `json:"url,omitempty" url:"url,omitempty"` + Body Optional[string] `json:"body,omitempty" url:"body,omitempty"` + CreatorID int `json:"creator_id,omitempty" url:"creator_id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Removed bool `json:"removed,omitempty" url:"removed,omitempty"` + Locked bool `json:"locked,omitempty" url:"locked,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + NSFW bool `json:"nsfw,omitempty" url:"nsfw,omitempty"` + Stickied bool `json:"stickied,omitempty" url:"stickied,omitempty"` + EmbedTitle Optional[string] `json:"embed_title,omitempty" url:"embed_title,omitempty"` + EmbedDescription Optional[string] `json:"embed_description,omitempty" url:"embed_description,omitempty"` + EmbedVideoURL Optional[string] `json:"embed_video_url,omitempty" url:"embed_video_url,omitempty"` + ThumbnailURL Optional[string] `json:"thumbnail_url,omitempty" url:"thumbnail_url,omitempty"` + ApID string `json:"ap_id,omitempty" url:"ap_id,omitempty"` + Local bool `json:"local,omitempty" url:"local,omitempty"` + LanguageID int `json:"language_id,omitempty" url:"language_id,omitempty"` +} + +type PasswordResetRequest struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + LocalUserID int `json:"local_user_id,omitempty" url:"local_user_id,omitempty"` + TokenEncrypted string `json:"token_encrypted,omitempty" url:"token_encrypted,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` +} + +type ModRemovePost struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Removed Optional[bool] `json:"removed,omitempty" url:"removed,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +type ModLockPost struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Locked Optional[bool] `json:"locked,omitempty" url:"locked,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModStickyPost represents a post stickied by a moderator. +type ModStickyPost struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Stickied Optional[bool] `json:"stickied,omitempty" url:"stickied,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModRemoveComment represents a comment removal by a moderator. +type ModRemoveComment struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Removed Optional[bool] `json:"removed,omitempty" url:"removed,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModRemoveCommunity represents a community removal by a moderator. +type ModRemoveCommunity struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Removed Optional[bool] `json:"removed,omitempty" url:"removed,omitempty"` + Expires Optional[string] `json:"expires,omitempty" url:"expires,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModBanFromCommunity represents a user being banned from a community by a moderator. +type ModBanFromCommunity struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + OtherPersonID int `json:"other_person_id,omitempty" url:"other_person_id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Banned Optional[bool] `json:"banned,omitempty" url:"banned,omitempty"` + Expires Optional[string] `json:"expires,omitempty" url:"expires,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModBan represents a user being banned by a moderator. +type ModBan struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + OtherPersonID int `json:"other_person_id,omitempty" url:"other_person_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Banned Optional[bool] `json:"banned,omitempty" url:"banned,omitempty"` + Expires Optional[string] `json:"expires,omitempty" url:"expires,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModAddCommunity represents a user being added as a moderator of a community. +type ModAddCommunity struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + OtherPersonID int `json:"other_person_id,omitempty" url:"other_person_id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Removed Optional[bool] `json:"removed,omitempty" url:"removed,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModTransferCommunity represents a community being transferred to another moderator. +type ModTransferCommunity struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + OtherPersonID int `json:"other_person_id,omitempty" url:"other_person_id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Removed Optional[bool] `json:"removed,omitempty" url:"removed,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +// ModAdd represents a user being added as a moderator. +type ModAdd struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + OtherPersonID int `json:"other_person_id,omitempty" url:"other_person_id,omitempty"` + Removed Optional[bool] `json:"removed,omitempty" url:"removed,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +type AdminPurgePerson struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + AdminPersonID int `json:"admin_person_id,omitempty" url:"admin_person_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +type AdminPurgeCommunity struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + AdminPersonID int `json:"admin_person_id,omitempty" url:"admin_person_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +type AdminPurgePost struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + AdminPersonID int `json:"admin_person_id,omitempty" url:"admin_person_id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +type AdminPurgeComment struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + AdminPersonID int `json:"admin_person_id,omitempty" url:"admin_person_id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + When string `json:"when_,omitempty" url:"when_,omitempty"` +} + +type CommunitySafe struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Name string `json:"name,omitempty" url:"name,omitempty"` + Title string `json:"title,omitempty" url:"title,omitempty"` + Description Optional[string] `json:"description,omitempty" url:"description,omitempty"` + Removed bool `json:"removed,omitempty" url:"removed,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + NSFW bool `json:"nsfw,omitempty" url:"nsfw,omitempty"` + ActorID string `json:"actor_id,omitempty" url:"actor_id,omitempty"` + Local bool `json:"local,omitempty" url:"local,omitempty"` + Icon Optional[string] `json:"icon,omitempty" url:"icon,omitempty"` + Banner Optional[string] `json:"banner,omitempty" url:"banner,omitempty"` + Hidden bool `json:"hidden,omitempty" url:"hidden,omitempty"` + PostingRestrictedToMods bool `json:"posting_restricted_to_mods,omitempty" url:"posting_restricted_to_mods,omitempty"` + InstanceID int `json:"instance_id,omitempty" url:"instance_id,omitempty"` +} + +type CommentReport struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CreatorID int `json:"creator_id,omitempty" url:"creator_id,omitempty"` + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + OriginalCommentText string `json:"original_comment_text,omitempty" url:"original_comment_text,omitempty"` + Reason string `json:"reason,omitempty" url:"reason,omitempty"` + Resolved bool `json:"resolved,omitempty" url:"resolved,omitempty"` + ResolverID Optional[int] `json:"resolver_id,omitempty" url:"resolver_id,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` +} + +type Comment struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CreatorID int `json:"creator_id,omitempty" url:"creator_id,omitempty"` + PostID int `json:"post_id,omitempty" url:"post_id,omitempty"` + Content string `json:"content,omitempty" url:"content,omitempty"` + Removed bool `json:"removed,omitempty" url:"removed,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` + Deleted bool `json:"deleted,omitempty" url:"deleted,omitempty"` + APID string `json:"ap_id,omitempty" url:"ap_id,omitempty"` + Local bool `json:"local,omitempty" url:"local,omitempty"` + Path string `json:"path,omitempty" url:"path,omitempty"` + Distinguished bool `json:"distinguished,omitempty" url:"distinguished,omitempty"` + LanguageID int `json:"language_id,omitempty" url:"language_id,omitempty"` +} + +type PersonMention struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + RecipientID int `json:"recipient_id,omitempty" url:"recipient_id,omitempty"` + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` +} + +type Language struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + Code string `json:"code,omitempty" url:"code,omitempty"` + Name string `json:"name,omitempty" url:"name,omitempty"` +} + +type PrivateMessageReport struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CreatorID int `json:"creator_id,omitempty" url:"creator_id,omitempty"` + PrivateMessageID int `json:"private_message_id,omitempty" url:"private_message_id,omitempty"` + OriginalPMText string `json:"original_pm_text,omitempty" url:"original_pm_text,omitempty"` + Reason string `json:"reason,omitempty" url:"reason,omitempty"` + Resolved bool `json:"resolved,omitempty" url:"resolved,omitempty"` + ResolverID Optional[int] `json:"resolver_id,omitempty" url:"resolver_id,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` +} + +type RegistrationApplication struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + LocalUserID int `json:"local_user_id,omitempty" url:"local_user_id,omitempty"` + Answer string `json:"answer,omitempty" url:"answer,omitempty"` + AdminID Optional[int] `json:"admin_id,omitempty" url:"admin_id,omitempty"` + DenyReason Optional[string] `json:"deny_reason,omitempty" url:"deny_reason,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` +} + +type ModHideCommunityView struct { + ModHideCommunity ModHideCommunity `json:"mod_hide_community,omitempty" url:"mod_hide_community,omitempty"` + Admin Optional[PersonSafe] `json:"admin,omitempty" url:"admin,omitempty"` + Community CommunitySafe `json:"community,omitempty" url:"community,omitempty"` +} + +type ModHideCommunity struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + CommunityID int `json:"community_id,omitempty" url:"community_id,omitempty"` + ModPersonID int `json:"mod_person_id,omitempty" url:"mod_person_id,omitempty"` + Reason Optional[string] `json:"reason,omitempty" url:"reason,omitempty"` + Hidden Optional[bool] `json:"hidden,omitempty" url:"hidden,omitempty"` + When time.Time `json:"when_,omitempty" url:"when_,omitempty"` +} + +type CommentReply struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + RecipientID int `json:"recipient_id,omitempty" url:"recipient_id,omitempty"` + CommentID int `json:"comment_id,omitempty" url:"comment_id,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` +} diff --git a/types/types.go b/types/types.go new file mode 100644 index 0000000..6590766 --- /dev/null +++ b/types/types.go @@ -0,0 +1,27 @@ +package types + +import ( + "fmt" + "net/http" +) + +type LemmyResponse struct { + Error Optional[string] `json:"error,omitempty" url:"error,omitempty"` +} + +type HTTPError struct { + Code int +} + +func (he HTTPError) Error() string { + return fmt.Sprintf("%d %s", he.Code, http.StatusText(he.Code)) +} + +type LemmyError struct { + ErrStr string + Code int +} + +func (le LemmyError) Error() string { + return fmt.Sprintf("%d %s: %s", le.Code, http.StatusText(le.Code), le.ErrStr) +} diff --git a/types/views.go b/types/views.go new file mode 100644 index 0000000..8fbc206 --- /dev/null +++ b/types/views.go @@ -0,0 +1,254 @@ +package types + +type PersonViewSafe struct { + Person PersonSafe `json:"person,omitempty" url:"person,omitempty"` + Counts PersonAggregates `json:"counts,omitempty" url:"counts,omitempty"` +} + +type PersonMentionView struct { + PersonMention PersonMention `json:"person_mention,omitempty" url:"person_mention,omitempty"` + Comment Comment `json:"comment,omitempty" url:"comment,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + Recipient PersonSafe `json:"recipient,omitempty" url:"recipient,omitempty"` + Counts CommentAggregates `json:"counts,omitempty" url:"counts,omitempty"` + CreatorBannedFromCommunity bool `json:"creator_banned_from_community,omitempty" url:"creator_banned_from_community,omitempty"` + Subscribed SubscribedType `json:"subscribed,omitempty" url:"subscribed,omitempty"` + Saved bool `json:"saved,omitempty" url:"saved,omitempty"` + CreatorBlocked bool `json:"creator_blocked,omitempty" url:"creator_blocked,omitempty"` + MyVote Optional[int] `json:"my_vote,omitempty" url:"my_vote,omitempty"` +} + +type LocalUserSettingsView struct { + LocalUserSettings LocalUserSettings `json:"local_user_settings,omitempty" url:"local_user_settings,omitempty"` + Person PersonSafe `json:"person,omitempty" url:"person,omitempty"` + Counts PersonAggregates `json:"counts,omitempty" url:"counts,omitempty"` +} + +type SiteView struct { + Site Site `json:"site,omitempty" url:"site,omitempty"` + LocalSite LocalSite `json:"local_site,omitempty" url:"local_site,omitempty"` + LocalSiteRateLimit LocalSiteRateLimit `json:"local_site_rate_limit,omitempty" url:"local_site_rate_limit,omitempty"` + Taglines Optional[[]Tagline] `json:"taglines,omitempty" url:"taglines,omitempty"` + Counts SiteAggregates `json:"counts,omitempty" url:"counts,omitempty"` +} + +type PrivateMessageView struct { + PrivateMessage PrivateMessage `json:"private_message,omitempty" url:"private_message,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Recipient PersonSafe `json:"recipient,omitempty" url:"recipient,omitempty"` +} + +type PostView struct { + Post Post `json:"post,omitempty" url:"post,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Community CommunitySafe `json:"community,omitempty" url:"community,omitempty"` + CreatorBannedFromCommunity bool `json:"creator_banned_from_community,omitempty" url:"creator_banned_from_community,omitempty"` + Counts PostAggregates `json:"counts,omitempty" url:"counts,omitempty"` + Subscribed bool `json:"subscribed,omitempty" url:"subscribed,omitempty"` + Saved bool `json:"saved,omitempty" url:"saved,omitempty"` + Read bool `json:"read,omitempty" url:"read,omitempty"` + CreatorBlocked bool `json:"creator_blocked,omitempty" url:"creator_blocked,omitempty"` + MyVote Optional[int] `json:"my_vote,omitempty" url:"my_vote,omitempty"` + UnreadComments int `json:"unread_comments,omitempty" url:"unread_comments,omitempty"` +} + +type PostReportView struct { + PostReport PostReport `json:"post_report,omitempty" url:"post_report,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + Community CommunitySafe `json:"community,omitempty" url:"community,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + PostCreator PersonSafe `json:"post_creator,omitempty" url:"post_creator,omitempty"` + CreatorBannedFromCommunity bool `json:"creator_banned_from_community,omitempty" url:"creator_banned_from_community,omitempty"` + MyVote Optional[int] `json:"my_vote,omitempty" url:"my_vote,omitempty"` + Counts PostAggregates `json:"counts,omitempty" url:"counts,omitempty"` + Resolver Optional[PersonSafe] `json:"resolver,omitempty" url:"resolver,omitempty"` +} + +type CommentView struct { + Comment Comment `json:"comment,omitempty" url:"comment,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + Community CommunitySafe `json:"community,omitempty" url:"community,omitempty"` + Counts CommentAggregates `json:"counts,omitempty" url:"counts,omitempty"` + CreatorBannedFromCommunity bool `json:"creator_banned_from_community,omitempty" url:"creator_banned_from_community,omitempty"` + Subscribed SubscribedType `json:"subscribed,omitempty" url:"subscribed,omitempty"` + Saved bool `json:"saved,omitempty" url:"saved,omitempty"` + CreatorBlocked bool `json:"creator_blocked,omitempty" url:"creator_blocked,omitempty"` + MyVote Optional[int] `json:"my_vote,omitempty" url:"my_vote,omitempty"` +} + +type CommentReportView struct { + CommentReport CommentReport `json:"comment_report,omitempty" url:"comment_report,omitempty"` + Comment Comment `json:"comment,omitempty" url:"comment,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + CommentCreator PersonSafe `json:"comment_creator,omitempty" url:"comment_creator,omitempty"` + Counts CommentAggregates `json:"counts,omitempty" url:"counts,omitempty"` + CreatorBannedFromCommunity bool `json:"creator_banned_from_community,omitempty" url:"creator_banned_from_community,omitempty"` + MyVote Optional[int] `json:"my_vote,omitempty" url:"my_vote,omitempty"` + Resolver Optional[PersonSafe] `json:"resolver,omitempty" url:"resolver,omitempty"` +} + +type ModAddCommunityView struct { + ModAddCommunity ModAddCommunity `json:"mod_add_community,omitempty" url:"mod_add_community,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + ModdedPerson PersonSafe `json:"modded_person,omitempty" url:"modded_person,omitempty"` +} + +type ModTransferCommunityView struct { + ModTransferCommunity ModTransferCommunity `json:"mod_transfer_community,omitempty" url:"mod_transfer_community,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + ModdedPerson PersonSafe `json:"modded_person,omitempty" url:"modded_person,omitempty"` +} + +type ModAddView struct { + ModAdd ModAdd `json:"mod_add,omitempty" url:"mod_add,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + ModdedPerson PersonSafe `json:"modded_person,omitempty" url:"modded_person,omitempty"` +} + +type ModBanFromCommunityView struct { + ModBanFromCommunity ModBanFromCommunity `json:"mod_ban_from_community,omitempty" url:"mod_ban_from_community,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + BannedPerson PersonSafe `json:"banned_person,omitempty" url:"banned_person,omitempty"` +} + +type ModBanView struct { + ModBan ModBan `json:"mod_ban,omitempty" url:"mod_ban,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + BannedPerson PersonSafe `json:"banned_person,omitempty" url:"banned_person,omitempty"` +} + +type ModLockPostView struct { + ModLockPost ModLockPost `json:"mod_lock_post,omitempty" url:"mod_lock_post,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type ModRemoveCommentView struct { + ModRemoveComment ModRemoveComment `json:"mod_remove_comment,omitempty" url:"mod_remove_comment,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + Comment Comment `json:"comment,omitempty" url:"comment,omitempty"` + Commenter PersonSafe `json:"commenter,omitempty" url:"commenter,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type ModRemoveCommunityView struct { + ModRemoveCommunity ModRemoveCommunity `json:"mod_remove_community,omitempty" url:"mod_remove_community,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type ModRemovePostView struct { + ModRemovePost ModRemovePost `json:"mod_remove_post,omitempty" url:"mod_remove_post,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type ModStickyPostView struct { + ModStickyPost ModStickyPost `json:"mod_sticky_post,omitempty" url:"mod_sticky_post,omitempty"` + Moderator Optional[PersonSafe] `json:"moderator,omitempty" url:"moderator,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type AdminPurgeCommunityView struct { + AdminPurgeCommunity AdminPurgeCommunity `json:"admin_purge_community,omitempty" url:"admin_purge_community,omitempty"` + Admin Optional[PersonSafe] `json:"admin,omitempty" url:"admin,omitempty"` +} + +type AdminPurgePersonView struct { + AdminPurgePerson AdminPurgePerson `json:"admin_purge_person,omitempty" url:"admin_purge_person,omitempty"` + Admin Optional[PersonSafe] `json:"admin,omitempty" url:"admin,omitempty"` +} + +type AdminPurgePostView struct { + AdminPurgePost AdminPurgePost `json:"admin_purge_post,omitempty" url:"admin_purge_post,omitempty"` + Admin Optional[PersonSafe] `json:"admin,omitempty" url:"admin,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type AdminPurgeCommentView struct { + AdminPurgeComment AdminPurgeComment `json:"admin_purge_comment,omitempty" url:"admin_purge_comment,omitempty"` + Admin Optional[PersonSafe] `json:"admin,omitempty" url:"admin,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` +} + +type CommunityFollowerView struct { + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + Follower PersonSafe `json:"follower,omitempty" url:"follower,omitempty"` +} + +type CommunityBlockView struct { + PersonSafe PersonSafe `json:"person_safe,omitempty" url:"person_safe,omitempty"` + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` +} + +type CommunityModeratorView struct { + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + Moderator PersonSafe `json:"moderator,omitempty" url:"moderator,omitempty"` +} + +type CommunityPersonBanView struct { + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + Person PersonSafe `json:"person,omitempty" url:"person,omitempty"` +} + +type PersonBlockView struct { + PersonSafe PersonSafe `json:"person_safe,omitempty" url:"person_safe,omitempty"` + Target PersonSafe `json:"target,omitempty" url:"target,omitempty"` +} + +type CommunityView struct { + CommunitySafe CommunitySafe `json:"community_safe,omitempty" url:"community_safe,omitempty"` + Subscribed SubscribedType `json:"subscribed,omitempty" url:"subscribed,omitempty"` + Blocked bool `json:"blocked,omitempty" url:"blocked,omitempty"` + Counts CommunityAggregates `json:"counts,omitempty" url:"counts,omitempty"` +} + +type RegistrationApplicationView struct { + RegistrationApplication RegistrationApplication `json:"registration_application,omitempty" url:"registration_application,omitempty"` + CreatorLocalUser LocalUserSettings `json:"creator_local_user,omitempty" url:"creator_local_user,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Admin Optional[PersonSafe] `json:"admin,omitempty" url:"admin,omitempty"` +} + +type PrivateMessageReportView struct { + PrivateMessageReport PrivateMessageReport `json:"private_message_report,omitempty" url:"private_message_report,omitempty"` + PrivateMessage PrivateMessage `json:"private_message,omitempty" url:"private_message,omitempty"` + PrivateMessageCreator PersonSafe `json:"private_message_creator,omitempty" url:"private_message_creator,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Resolver Optional[PersonSafe] `json:"resolver,omitempty" url:"resolver,omitempty"` +} + +type Tagline struct { + ID int `json:"id,omitempty" url:"id,omitempty"` + LocalSiteID int `json:"local_site_id,omitempty" url:"local_site_id,omitempty"` + Content string `json:"content,omitempty" url:"content,omitempty"` + Published string `json:"published,omitempty" url:"published,omitempty"` + Updated Optional[string] `json:"updated,omitempty" url:"updated,omitempty"` +} + +type CommentReplyView struct { + CommentReply CommentReply `json:"comment_reply,omitempty" url:"comment_reply,omitempty"` + Comment Comment `json:"comment,omitempty" url:"comment,omitempty"` + Creator PersonSafe `json:"creator,omitempty" url:"creator,omitempty"` + Post Post `json:"post,omitempty" url:"post,omitempty"` + Community CommunitySafe `json:"community,omitempty" url:"community,omitempty"` + Recipient PersonSafe `json:"recipient,omitempty" url:"recipient,omitempty"` + Counts CommentAggregates `json:"counts,omitempty" url:"counts,omitempty"` + CreatorBannedFromCommunity bool `json:"creator_banned_from_community,omitempty" url:"creator_banned_from_community,omitempty"` + Subscribed SubscribedType `json:"subscribed,omitempty" url:"subscribed,omitempty"` + Saved bool `json:"saved,omitempty" url:"saved,omitempty"` + CreatorBlocked bool `json:"creator_blocked,omitempty" url:"creator_blocked,omitempty"` + MyVote Optional[int] `json:"my_vote,omitempty" url:"my_vote,omitempty"` +}