From 56910b94268d3d70d5cc5c8794bae4180be61f7a Mon Sep 17 00:00:00 2001 From: Tyler Davis Date: Thu, 21 Dec 2023 05:37:38 +0000 Subject: [PATCH] Fix for lemmy 0.19.0 - Update go-lemmy dependency -> v0.19.0 - Remove `types` references per go-lemmy upgrade - Use more robust strconv type parsers/formatters for int64 handling --- go.mod | 8 +++--- go.sum | 6 ++++ system/lemmy/lemmy.go | 64 +++++++++++++++++++++---------------------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 36240df..1f6efd6 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/mrusme/neonmodem -go 1.19 +go 1.21 require ( github.com/JohannesKaufmann/html-to-markdown v1.4.0 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/charmbracelet/bubbles v0.16.1 - github.com/charmbracelet/bubbletea v0.24.2 + github.com/charmbracelet/bubbletea v0.25.0 github.com/charmbracelet/glamour v0.6.0 github.com/charmbracelet/lipgloss v0.7.1 github.com/eliukblau/pixterm v1.3.1 @@ -22,7 +22,7 @@ require ( github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 - go.elara.ws/go-lemmy v0.18.0 + go.elara.ws/go-lemmy v0.19.0 go.uber.org/zap v1.24.0 golang.org/x/term v0.13.0 ) @@ -47,7 +47,7 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-localereader v0.0.1 // indirect - github.com/microcosm-cc/bluemonday v1.0.25 // indirect + github.com/microcosm-cc/bluemonday v1.0.26 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect diff --git a/go.sum b/go.sum index 228dffa..5bd3fd8 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,8 @@ github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5 github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= +github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM= +github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg= github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc= github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc= github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= @@ -207,6 +209,8 @@ github.com/mergestat/timediff v0.0.3/go.mod h1:yvMUaRu2oetc+9IbPLYBJviz6sA7xz8OX github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= github.com/microcosm-cc/bluemonday v1.0.25 h1:4NEwSfiJ+Wva0VxN5B8OwMicaJvD8r9tlJWm9rtloEg= github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU02nx4bn030ixfHLE= +github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58= +github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= @@ -286,6 +290,8 @@ github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GA github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY= go.elara.ws/go-lemmy v0.18.0 h1:c83VhfGtePegDZRV8X4PWfkl4cqBqug4li20VChN6sE= go.elara.ws/go-lemmy v0.18.0/go.mod h1:rurQND/HT3yWfX/T4w+hb6vEwRAeAlV+9bSGFkkx5rA= +go.elara.ws/go-lemmy v0.19.0 h1:FdPfiA+8yOa2IhrLdBp8jdYbnY6H55bfwnBbiGr0OHg= +go.elara.ws/go-lemmy v0.19.0/go.mod h1:aZbF/4c1VA7qPXsP4Pth0ERu3HGZFPPl8bTY1ltBrcQ= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/system/lemmy/lemmy.go b/system/lemmy/lemmy.go index 36bc7ec..d1b3469 100644 --- a/system/lemmy/lemmy.go +++ b/system/lemmy/lemmy.go @@ -14,7 +14,6 @@ import ( "github.com/mrusme/neonmodem/models/reply" "github.com/mrusme/neonmodem/system/adapter" "go.elara.ws/go-lemmy" - "go.elara.ws/go-lemmy/types" "go.uber.org/zap" ) @@ -144,7 +143,7 @@ func (sys *System) Load() error { credentials[k] = v.(string) } - err = sys.client.ClientLogin(context.Background(), types.Login{ + err = sys.client.ClientLogin(context.Background(), lemmy.Login{ UsernameOrEmail: credentials["username"], Password: credentials["password"], }) @@ -155,8 +154,8 @@ func (sys *System) Load() error { } func (sys *System) ListForums() ([]forum.Forum, error) { - resp, err := sys.client.Communities(context.Background(), types.ListCommunities{ - Type: types.NewOptional(types.ListingTypeSubscribed), + resp, err := sys.client.Communities(context.Background(), lemmy.ListCommunities{ + Type: lemmy.NewOptional(lemmy.ListingTypeSubscribed), }) if err != nil { return []forum.Forum{}, err @@ -165,7 +164,7 @@ func (sys *System) ListForums() ([]forum.Forum, error) { var models []forum.Forum for _, i := range resp.Communities { models = append(models, forum.Forum{ - ID: strconv.Itoa(i.Community.ID), + ID: strconv.FormatInt(i.Community.ID, 10), Name: i.Community.Name, Info: i.Community.Description.ValueOr(i.Community.Title), @@ -178,10 +177,10 @@ func (sys *System) ListForums() ([]forum.Forum, error) { } func (sys *System) ListPosts(forumID string) ([]post.Post, error) { - resp, err := sys.client.Posts(context.Background(), types.GetPosts{ - Type: types.NewOptional(types.ListingTypeSubscribed), - Sort: types.NewOptional(types.SortTypeNew), - Limit: types.NewOptional(int64(50)), + resp, err := sys.client.Posts(context.Background(), lemmy.GetPosts{ + Type: lemmy.NewOptional(lemmy.ListingTypeSubscribed), + Sort: lemmy.NewOptional(lemmy.SortTypeNew), + Limit: lemmy.NewOptional(int64(50)), }) if err != nil { @@ -200,11 +199,12 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { body = i.Post.URL.ValueOr("") } - createdAt := i.Post.Published.Time - lastCommentedAt := i.Counts.NewestCommentTime.Time + createdAt := i.Post.Published + //lastCommentedAt := i.Counts.NewestCommentTime.Time + lastCommentedAt := i.Counts.Published models = append(models, post.Post{ - ID: strconv.Itoa(i.Post.ID), + ID: strconv.FormatInt(i.Post.ID, 10), Subject: i.Post.Name, Body: body, @@ -217,12 +217,12 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { LastCommentedAt: lastCommentedAt, Author: author.Author{ - ID: strconv.Itoa(i.Post.CreatorID), + ID: strconv.FormatInt(i.Post.CreatorID, 10), Name: i.Creator.Name, }, Forum: forum.Forum{ - ID: strconv.Itoa(i.Post.CommunityID), + ID: strconv.FormatInt(i.Post.CommunityID, 10), Name: i.Community.Name, SysIDX: sys.ID, @@ -242,7 +242,7 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { } func (sys *System) LoadPost(p *post.Post) error { - pid, err := strconv.Atoi(p.ID) + pid, err := strconv.ParseInt(p.ID, 10, 64) if err != nil { return err } @@ -251,8 +251,8 @@ func (sys *System) LoadPost(p *post.Post) error { // return err // } - resp, err := sys.client.Comments(context.Background(), types.GetComments{ - PostID: types.NewOptional[int](pid), + resp, err := sys.client.Comments(context.Background(), lemmy.GetComments{ + PostID: lemmy.NewOptional[int64](pid), }) if err != nil { return err @@ -260,10 +260,10 @@ func (sys *System) LoadPost(p *post.Post) error { p.Replies = []reply.Reply{} for _, i := range resp.Comments { - createdAt := i.Comment.Published.Time + createdAt := i.Comment.Published p.Replies = append(p.Replies, reply.Reply{ - ID: strconv.Itoa(i.Comment.ID), + ID: strconv.FormatInt(i.Comment.ID, 10), InReplyTo: p.ID, @@ -272,7 +272,7 @@ func (sys *System) LoadPost(p *post.Post) error { CreatedAt: createdAt, Author: author.Author{ - ID: strconv.Itoa(i.Comment.CreatorID), + ID: strconv.FormatInt(i.Comment.CreatorID, 10), Name: i.Creator.Name, }, @@ -283,46 +283,46 @@ func (sys *System) LoadPost(p *post.Post) error { } func (sys *System) CreatePost(p *post.Post) error { - communityID, err := strconv.Atoi(p.Forum.ID) + communityID, err := strconv.ParseInt(p.Forum.ID, 10, 64) if err != nil { return err } - resp, err := sys.client.CreatePost(context.Background(), types.CreatePost{ + resp, err := sys.client.CreatePost(context.Background(), lemmy.CreatePost{ Name: p.Subject, CommunityID: communityID, - Body: types.NewOptional(p.Body), - NSFW: types.NewOptional(false), + Body: lemmy.NewOptional(p.Body), + NSFW: lemmy.NewOptional(false), }) if err != nil { return err } - p.ID = strconv.Itoa(resp.PostView.Post.ID) + p.ID = strconv.FormatInt(resp.PostView.Post.ID, 10) return nil } func (sys *System) CreateReply(r *reply.Reply) error { - ID, err := strconv.Atoi(r.ID) + ID, err := strconv.ParseInt(r.ID, 10, 64) if err != nil { return err } - var create types.CreateComment + var create lemmy.CreateComment if r.InReplyTo != "" { // Reply to a reply of a post - InReplyTo, err := strconv.Atoi(r.InReplyTo) + InReplyTo, err := strconv.ParseInt(r.InReplyTo, 10, 64) if err != nil { return err } - create = types.CreateComment{ + create = lemmy.CreateComment{ PostID: InReplyTo, - ParentID: types.NewOptional(ID), + ParentID: lemmy.NewOptional(ID), Content: r.Body, } } else { // Reply to a post - create = types.CreateComment{ + create = lemmy.CreateComment{ PostID: ID, Content: r.Body, } @@ -333,6 +333,6 @@ func (sys *System) CreateReply(r *reply.Reply) error { return err } - r.ID = strconv.Itoa(resp.CommentView.Comment.ID) + r.ID = strconv.FormatInt(resp.CommentView.Comment.ID, 10) return nil }