diff --git a/mastodon/instance.go b/mastodon/instance.go index 1dc2c8e..9152808 100644 --- a/mastodon/instance.go +++ b/mastodon/instance.go @@ -17,6 +17,8 @@ type Instance struct { Stats *InstanceStats `json:"stats,omitempty"` Languages []string `json:"languages"` ContactAccount *Account `json:"account"` + MaxTootChars *int64 `json:"max_toot_chars"` + Pleroma *PleromaInstance `json:"pleroma"` } // InstanceStats hold information for mastodon instance stats. @@ -26,6 +28,16 @@ type InstanceStats struct { DomainCount int64 `json:"domain_count"` } +// For about instance if this Pleroma +type PleromaInstance struct { + MetaData MetaData `json:"metadata"` +} + +type MetaData struct { + Features *[]string `json:"features"` +} + + // GetInstance return Instance. func (c *Client) GetInstance(ctx context.Context) (*Instance, error) { var instance Instance diff --git a/renderer/model.go b/renderer/model.go index e7cfbfb..c81e76d 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -119,6 +119,11 @@ type AboutData struct { *CommonData } +type AboutInstanceData struct { + *CommonData + Instance *mastodon.Instance +} + type EmojiData struct { *CommonData Emojis []*mastodon.Emoji diff --git a/renderer/renderer.go b/renderer/renderer.go index cef03bb..2121cd9 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -27,6 +27,7 @@ const ( UserPage = "user.tmpl" UserSearchPage = "usersearch.tmpl" AboutPage = "about.tmpl" + AboutInstance = "aboutinstance.tmpl" EmojiPage = "emoji.tmpl" LikedByPage = "likedby.tmpl" RetweetedByPage = "retweetedby.tmpl" diff --git a/service/service.go b/service/service.go index cda42f8..8da1062 100644 --- a/service/service.go +++ b/service/service.go @@ -737,6 +737,19 @@ func (s *service) AboutPage(c *client) (err error) { return s.renderer.Render(c.rctx, c.w, renderer.AboutPage, data) } +func (s *service) AboutInstance(c *client) (err error) { + cdata := s.cdata(c, "about", 0, 0, "") + instance, err := c.GetInstance(c.ctx) + if err != nil { + return + } + data := &renderer.AboutInstanceData{ + CommonData: cdata, + Instance: instance, + } + return s.renderer.Render(c.rctx, c.w, renderer.AboutInstance, data) +} + func (s *service) EmojiPage(c *client) (err error) { emojis, err := c.GetInstanceEmojis(c.ctx) if err != nil { diff --git a/service/transport.go b/service/transport.go index 4518b1a..75ae33c 100644 --- a/service/transport.go +++ b/service/transport.go @@ -220,6 +220,10 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { aboutPage := handle(func(c *client) error { return s.AboutPage(c) }, SESSION, HTML) + + aboutInstance := handle(func(c *client) error { + return s.AboutInstance(c) + }, SESSION, HTML) emojisPage := handle(func(c *client) error { return s.EmojiPage(c) @@ -721,6 +725,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/user/{id}/{type}", userPage).Methods(http.MethodGet) r.HandleFunc("/usersearch/{id}", userSearchPage).Methods(http.MethodGet) r.HandleFunc("/about", aboutPage).Methods(http.MethodGet) + r.HandleFunc("/aboutinstance", aboutInstance).Methods(http.MethodGet) r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet) r.HandleFunc("/search", searchPage).Methods(http.MethodGet) r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet) diff --git a/templates/aboutinstance.tmpl b/templates/aboutinstance.tmpl new file mode 100644 index 0000000..3fb6073 --- /dev/null +++ b/templates/aboutinstance.tmpl @@ -0,0 +1,44 @@ +{{with .Data}} +{{template "header.tmpl" (WithContext .CommonData $.Ctx)}} + +
+ {{.Instance.Description}} +
+
+ Logo instance
+
+
+ Domains federated: {{.Instance.Stats.DomainCount}}
+ Registered users: {{.Instance.Stats.UserCount}}
+ Statuses writen: {{.Instance.Stats.StatusCount}}
+