mirror of
https://git.freesoftwareextremist.com/bloat
synced 2024-12-22 01:00:44 +00:00
Add hashtag search
This commit is contained in:
parent
e46d067866
commit
efb0e0417c
5 changed files with 51 additions and 19 deletions
|
@ -56,7 +56,7 @@ type TimelineData struct {
|
|||
*CommonData
|
||||
Title string
|
||||
Type string
|
||||
Instance string
|
||||
Q string
|
||||
Statuses []*mastodon.Status
|
||||
NextLink string
|
||||
PrevLink string
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue