aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2024-06-17 14:48:13 +0000
committerr <r@freesoftwareextremist.com>2024-06-17 14:48:13 +0000
commitefb0e0417c4b290bfa36113b8662f52837bb713e (patch)
treed11bd031325c052a52fbf3acc70ed34e252f1797
parente46d067866d3345d9e160fa50fd16af5430e2418 (diff)
downloadbloat-efb0e0417c4b290bfa36113b8662f52837bb713e.tar.gz
bloat-efb0e0417c4b290bfa36113b8662f52837bb713e.zip
Add hashtag search
-rw-r--r--renderer/model.go2
-rw-r--r--service/service.go40
-rw-r--r--service/transport.go13
-rw-r--r--templates/search.tmpl1
-rw-r--r--templates/timeline.tmpl14
5 files changed, 51 insertions, 19 deletions
diff --git a/renderer/model.go b/renderer/model.go
index 59e7cb9..f3e7d5d 100644
--- a/renderer/model.go
+++ b/renderer/model.go
@@ -56,7 +56,7 @@ type TimelineData struct {
*CommonData
Title string
Type string
- Instance string
+ Q string
Statuses []*mastodon.Status
NextLink string
PrevLink string
diff --git a/service/service.go b/service/service.go
index 32912f6..4f17817 100644
--- a/service/service.go
+++ b/service/service.go
@@ -121,7 +121,7 @@ func (s *service) NavPage(c *client) (err error) {
return s.renderer.Render(c.rctx, c.w, renderer.NavPage, data)
}
-func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
+func (s *service) TimelinePage(c *client, tType, q, listId, maxID,
minID string) (err error) {
var nextLink, prevLink, title string
@@ -155,12 +155,12 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
}
title = "Local Timeline"
case "remote":
- if len(instance) > 0 {
- statuses, err = c.GetTimelinePublic(c.ctx, false, instance, &pg)
+ if len(q) > 0 {
+ statuses, err = c.GetTimelinePublic(c.ctx, false, q, &pg)
if err != nil {
return err
}
- refreshLink += "?instance=" + instance
+ refreshLink += "?q=" + q
}
title = "Remote Timeline"
case "twkn":
@@ -180,6 +180,16 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
}
title = "List Timeline - " + list.Title
refreshLink += "?list=" + listId
+ case "hashtag":
+ q = strings.TrimPrefix(q, "#")
+ if len(q) > 0 {
+ statuses, err = c.GetTimelineHashtag(c.ctx, q, false, &pg)
+ if err != nil {
+ return err
+ }
+ refreshLink += "?q=" + q
+ }
+ title = "Hashtag Timeline"
}
for i := range statuses {
@@ -191,8 +201,8 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
if (len(maxID) > 0 || len(minID) > 0) && len(statuses) > 0 {
v := make(url.Values)
v.Set("min_id", statuses[0].ID)
- if len(instance) > 0 {
- v.Set("instance", instance)
+ if len(q) > 0 {
+ v.Set("q", q)
}
if len(listId) > 0 {
v.Set("list", listId)
@@ -203,8 +213,8 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
if len(minID) > 0 || (len(pg.MaxID) > 0 && len(statuses) == 20) {
v := make(url.Values)
v.Set("max_id", pg.MaxID)
- if len(instance) > 0 {
- v.Set("instance", instance)
+ if len(q) > 0 {
+ v.Set("q", q)
}
if len(listId) > 0 {
v.Set("list", listId)
@@ -216,7 +226,7 @@ func (s *service) TimelinePage(c *client, tType, instance, listId, maxID,
data := &renderer.TimelineData{
Title: title,
Type: tType,
- Instance: instance,
+ Q: q,
Statuses: statuses,
NextLink: nextLink,
PrevLink: prevLink,
@@ -731,17 +741,21 @@ func (s *service) EmojiPage(c *client) (err error) {
return s.renderer.Render(c.rctx, c.w, renderer.EmojiPage, data)
}
-func (s *service) SearchPage(c *client,
- q string, qType string, offset int) (err error) {
+func (s *service) SearchPage(c *client, q string, qType string, offset int) (
+ rurl string, err error) {
var nextLink string
var title = "Search"
var results *mastodon.Results
if len(q) > 0 {
+ if qType == "hashtags" {
+ rurl = "/timeline/hashtag?q=" + url.QueryEscape(q)
+ return
+ }
results, err = c.Search(c.ctx, q, qType, 20, true, offset, "", false)
if err != nil {
- return err
+ return "", err
}
} else {
results = &mastodon.Results{}
@@ -767,7 +781,7 @@ func (s *service) SearchPage(c *client,
Statuses: results.Statuses,
NextLink: nextLink,
}
- return s.renderer.Render(c.rctx, c.w, renderer.SearchPage, data)
+ return "", s.renderer.Render(c.rctx, c.w, renderer.SearchPage, data)
}
func (s *service) SettingsPage(c *client) (err error) {
diff --git a/service/transport.go b/service/transport.go
index f7e31d6..1b1a10e 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -134,11 +134,11 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
timelinePage := handle(func(c *client) error {
tType, _ := mux.Vars(c.r)["type"]
q := c.r.URL.Query()
- instance := q.Get("instance")
+ query := q.Get("q")
list := q.Get("list")
maxID := q.Get("max_id")
minID := q.Get("min_id")
- return s.TimelinePage(c, tType, instance, list, maxID, minID)
+ return s.TimelinePage(c, tType, query, list, maxID, minID)
}, SESSION, HTML)
defaultTimelinePage := handle(func(c *client) error {
@@ -210,7 +210,14 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
sq := q.Get("q")
qType := q.Get("type")
offset, _ := strconv.Atoi(q.Get("offset"))
- return s.SearchPage(c, sq, qType, offset)
+ rurl, err := s.SearchPage(c, sq, qType, offset)
+ if err != nil {
+ return err
+ }
+ if len(rurl) > 0 {
+ c.redirect(rurl)
+ }
+ return nil
}, SESSION, HTML)
settingsPage := handle(func(c *client) error {
diff --git a/templates/search.tmpl b/templates/search.tmpl
index 076858e..481f763 100644
--- a/templates/search.tmpl
+++ b/templates/search.tmpl
@@ -12,6 +12,7 @@
<select name="type">
<option value="statuses" {{if eq .Type "statuses"}}selected{{end}}>Statuses</option>
<option value="accounts" {{if eq .Type "accounts"}}selected{{end}}>Accounts</option>
+ <option value="hashtags" {{if eq .Type "hashtags"}}selected{{end}}>Hashtags</option>
</select>
</label>
<button type="submit"> Search </button>
diff --git a/templates/timeline.tmpl b/templates/timeline.tmpl
index b3421ba..eb7571b 100644
--- a/templates/timeline.tmpl
+++ b/templates/timeline.tmpl
@@ -5,8 +5,18 @@
{{if eq .Type "remote"}}
<form action="/timeline/remote" method="GET">
<span>
- <label for="instance"> Instance </label>
- <input type="text" id="instance" name="instance" value="{{.Instance}}">
+ <label for="q"> Instance </label>
+ <input type="text" id="q" name="q" value="{{.Q}}">
+ </span>
+ <button type="submit"> Submit </button>
+</form>
+{{end}}
+
+{{if eq .Type "hashtag"}}
+<form action="/timeline/hashtag" method="GET">
+ <span>
+ <label for="q"> Tag </label>
+ <input type="text" id="q" name="q" value="{{.Q}}">
</span>
<button type="submit"> Submit </button>
</form>