From 9cac79071bf16a92cbb92cb0ebc49038b562e561 Mon Sep 17 00:00:00 2001 From: Dima Krasner Date: Sat, 13 Apr 2024 12:31:32 +0300 Subject: [PATCH] switch to chronological order in /local and drop /federated --- README.md | 1 - front/README.md | 2 - front/federated.go | 38 ----------------- front/handler.go | 3 -- front/local.go | 35 ++++------------ front/menu.go | 1 - front/static/help.gmi | 17 -------- front/static/users/help.gmi | 17 -------- test/federated_test.go | 82 ------------------------------------- 9 files changed, 7 insertions(+), 189 deletions(-) delete mode 100644 front/federated.go delete mode 100644 test/federated_test.go diff --git a/README.md b/README.md index fee3c381..ce1e8634 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ Welcome, fedinaut! localhost.localdomain:8443 is an instance of tootik, a federa ⚡️ Followed users 😈 My profile 📡 This planet -✨ FOMO from outer space 🔥 Hashtags 🔭 Find user 🔎 Search posts diff --git a/front/README.md b/front/README.md index 1555a05a..f1ef4c8d 100644 --- a/front/README.md +++ b/front/README.md @@ -4,7 +4,6 @@ * /local shows a compact list of local posts; each entry contains a link to /view. * / is the homepage: it shows an ASCII art logo, a short description of this server and a list of local posts. -* /federated shows a compact list of federated posts. * /hashtag shows a compact list of posts with a given hashtag. * /search shows an input prompt and redirects to /hashtag. * /hashtags shows a list of popular hashtags. @@ -42,7 +41,6 @@ Users are authenticated using TLS client certificates; see [Gemini protocol spec Some clients generate a certificate for / (all pages of this capsule) when /foo requests a client certificate, while others use the certificate requested by /foo only for /foo and /foo/bar. Therefore, pages that don't require authentication are also mirrored under /users: * /users/local -* /users/federated * /users/hashtag * /users/hashtags * /users/fts diff --git a/front/federated.go b/front/federated.go deleted file mode 100644 index d93727fe..00000000 --- a/front/federated.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2023, 2024 Dima Krasner - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package front - -import ( - "database/sql" - "github.com/dimkr/tootik/front/text" -) - -func (h *Handler) federated(w text.Writer, r *request, args ...string) { - h.showFeedPage( - w, - r, - "✨️ FOMO From Outer Space", - func(offset int) (*sql.Rows, error) { - return r.Query( - `select notes.object, persons.actor, groups.actor, notes.inserted from notes join persons on notes.author = persons.id left join (select author, max(inserted) as last, count(*)/(60*60*24) as avg from notes where inserted > unixepoch()-60*60*24*7 group by author) stats on notes.author = stats.author left join (select id, actor from persons where actor->>'$.type' = 'Group') groups on groups.id = notes.object->>'$.audience' where notes.public = 1 group by notes.id order by notes.inserted / 3600 desc, stats.avg asc, stats.last asc, notes.inserted desc limit $1 offset $2`, - h.Config.PostsPerPage, - offset, - ) - }, - false, - ) -} diff --git a/front/handler.go b/front/handler.go index b967d039..eb403b11 100644 --- a/front/handler.go +++ b/front/handler.go @@ -76,9 +76,6 @@ func NewHandler(domain string, closed bool, cfg *cfg.Config) (Handler, error) { h.handlers[regexp.MustCompile(`^/local$`)] = withCache(withUserMenu(h.local), time.Minute*15, &cache, cfg) h.handlers[regexp.MustCompile(`^/users/local$`)] = withCache(withUserMenu(h.local), time.Minute*15, &cache, cfg) - h.handlers[regexp.MustCompile(`^/federated$`)] = withCache(withUserMenu(h.federated), time.Minute*10, &cache, cfg) - h.handlers[regexp.MustCompile(`^/users/federated$`)] = withCache(withUserMenu(h.federated), time.Minute*10, &cache, cfg) - h.handlers[regexp.MustCompile(`^/outbox/(\S+)$`)] = withUserMenu(h.userOutbox) h.handlers[regexp.MustCompile(`^/users/outbox/(\S+)$`)] = withUserMenu(h.userOutbox) h.handlers[regexp.MustCompile(`^/users/me$`)] = withUserMenu(me) diff --git a/front/local.go b/front/local.go index 99fe5955..7e4cc618 100644 --- a/front/local.go +++ b/front/local.go @@ -29,44 +29,23 @@ func (h *Handler) local(w text.Writer, r *request, args ...string) { func(offset int) (*sql.Rows, error) { return r.Query( ` - select u.object, u.actor, u.sharer, u.inserted from + select object, actor, sharer, inserted from ( - select notes.id, notes.author, notes.object, notes.inserted, persons.actor, null as sharer from persons + select notes.object, persons.actor, null as sharer, notes.inserted from persons join notes on notes.author = persons.id where notes.public = 1 and persons.host = $1 - union - select notes.id, notes.author, notes.object, shares.inserted, persons.actor, sharers.actor as sharer from persons sharers + union all + select notes.object, persons.actor, sharers.actor as sharer, shares.inserted from persons sharers join shares on shares.by = sharers.id join notes on notes.id = shares.note join persons on persons.id = notes.author - where notes.public = 1 and notes.host != $1 and sharers.host = $1 - ) u - left join ( - select object->>'$.inReplyTo' as id, count(*) as count from notes - where host = $1 and inserted > unixepoch()-60*60*24*7 - group by object->>'$.inReplyTo' - ) replies - on - replies.id = u.id - left join ( - select author, max(inserted) as last, round(count(*)/7.0, 1) as avg from notes - where host = $1 and inserted > unixepoch()-60*60*24*7 - group by author - ) stats - on - stats.author = u.author - group by - u.id - order by - u.inserted / 86400 desc, - replies.count desc, - stats.avg asc, - stats.last asc, - u.inserted desc + where notes.public = 1 and sharers.host = $1 + ) + order by inserted desc limit $2 offset $3 `, diff --git a/front/menu.go b/front/menu.go index 1b8d7a4f..57611793 100644 --- a/front/menu.go +++ b/front/menu.go @@ -38,7 +38,6 @@ func writeUserMenu(w text.Writer, user *ap.Actor) { } w.Link(prefix+"/local", "📡 This planet") - w.Link(prefix+"/federated", "✨ FOMO from outer space") if user == nil { w.Link("/hashtags", "🔥 Hashtags") diff --git a/front/static/help.gmi b/front/static/help.gmi index c1b97aba..d3160e40 100644 --- a/front/static/help.gmi +++ b/front/static/help.gmi @@ -11,23 +11,6 @@ This is an instance of tootik, a "slow", "boring" and non-addictive social netwo This page shows public posts published on this server. -Posts are sorted by: -* Day of posting -* Number of replies -* Author's number of posts -* Time since the author's previous post -* Exact time of posting - -> ✨ FOMO from outer space - -This page shows public posts from the fediverse. - -Posts are sorted by: -* Hour of posting -* Author's number of posts -* Time since the author's previous post -* Exact time of posting - > 🔥 Hashtags This page shows popular hashtags, allowing you to discover trends and shared interests. diff --git a/front/static/users/help.gmi b/front/static/users/help.gmi index d3121676..3e09d5d9 100644 --- a/front/static/users/help.gmi +++ b/front/static/users/help.gmi @@ -27,23 +27,6 @@ This page shows your profile. This page shows public posts published on this server. -Posts are sorted by: -* Day of posting -* Number of replies -* Author's number of posts -* Time since the author's previous post -* Exact time of posting - -> ✨ FOMO from outer space - -This page shows public posts from the fediverse. - -Posts are sorted by: -* Hour of posting -* Author's number of posts -* Time since the author's previous post -* Exact time of posting - > 🔥 Hashtags This page shows popular hashtags, allowing you to discover trends and shared interests. diff --git a/test/federated_test.go b/test/federated_test.go deleted file mode 100644 index 1ce7fa01..00000000 --- a/test/federated_test.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2023 Dima Krasner - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package test - -import ( - "github.com/stretchr/testify/assert" - "testing" -) - -func TestFederated_AuthenticatedUser(t *testing.T) { - server := newTestServer() - defer server.Shutdown() - - assert := assert.New(t) - - federated := server.Handle("/users/federated", server.Alice) - assert.Regexp("^20 text/gemini\r\n", federated) -} - -func TestFederated_UnauthenticatedUser(t *testing.T) { - server := newTestServer() - defer server.Shutdown() - - assert := assert.New(t) - - federated := server.Handle("/federated", nil) - assert.Regexp("^20 text/gemini\r\n", federated) -} - -func TestFederated_InvalidOffset(t *testing.T) { - server := newTestServer() - defer server.Shutdown() - - assert := assert.New(t) - - federated := server.Handle("/users/federated?a", server.Alice) - assert.Equal("40 Invalid query\r\n", federated) -} - -func TestFederated_BigOffset(t *testing.T) { - server := newTestServer() - defer server.Shutdown() - - assert := assert.New(t) - - federated := server.Handle("/users/federated?901", server.Alice) - assert.Equal("40 Offset must be <= 900\r\n", federated) -} - -func TestFederated_SecondPage(t *testing.T) { - server := newTestServer() - defer server.Shutdown() - - assert := assert.New(t) - - federated := server.Handle("/users/federated?30", server.Alice) - assert.Regexp("^20 text/gemini\r\n", federated) -} - -func TestFederated_SecondPageUnauthenticatedUser(t *testing.T) { - server := newTestServer() - defer server.Shutdown() - - assert := assert.New(t) - - federated := server.Handle("/federated?30", nil) - assert.Regexp("^20 text/gemini\r\n", federated) -}