From fb84533aeae7c50df8c2d175083260597e057474 Mon Sep 17 00:00:00 2001 From: BreadMakesYouFat Date: Sat, 24 Jun 2023 17:21:08 -0400 Subject: [PATCH] Fullnames for lemmy instances: catalog@instance --- system/lemmy/lemmy.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/system/lemmy/lemmy.go b/system/lemmy/lemmy.go index 21b1a79..f0040ba 100644 --- a/system/lemmy/lemmy.go +++ b/system/lemmy/lemmy.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "strconv" + "strings" "time" "github.com/mrusme/neonmodem/models/author" @@ -154,6 +155,27 @@ func (sys *System) Load() error { return nil } +func communityFullname(community types.CommunitySafe) (communityName string) { + instanceName := "" + if community.ActorID != "" { + removeUrlScheme := strings.NewReplacer( + "http://", "", + "https://", "", + ) + instanceName = removeUrlScheme.Replace( + community.ActorID) + splitUrl := strings.Split(instanceName, "/") + if len(splitUrl) > 1 { + instanceName = splitUrl[0] + } + } + communityName = community.Name + if instanceName != "" { + communityName += "@" + instanceName + } + return communityName +} + func (sys *System) ListForums() ([]forum.Forum, error) { var models []forum.Forum for j := 1; j < 100; j++ { @@ -171,7 +193,7 @@ func (sys *System) ListForums() ([]forum.Forum, error) { for _, i := range resp.Communities { models = append(models, forum.Forum{ ID: strconv.Itoa(i.Community.ID), - Name: i.Community.Name, + Name: communityFullname(i.Community), Info: i.Community.Description.ValueOr(i.Community.Title), @@ -246,7 +268,7 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) { Forum: forum.Forum{ ID: strconv.Itoa(i.Post.CommunityID), - Name: i.Community.Name, + Name: communityFullname(i.Community), SysIDX: sys.ID, },