aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/auth.go9
-rw-r--r--service/logging.go9
-rw-r--r--service/service.go45
-rw-r--r--service/transport.go25
4 files changed, 87 insertions, 1 deletions
diff --git a/service/auth.go b/service/auth.go
index 78934fd..f127f5c 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -162,6 +162,15 @@ func (s *as) ServeSearchPage(ctx context.Context, c *model.Client, q string,
return s.Service.ServeSearchPage(ctx, c, q, qType, offset)
}
+func (s *as) ServeUserSearchPage(ctx context.Context, c *model.Client,
+ id string, q string, offset int) (err error) {
+ err = s.authenticateClient(ctx, c)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeUserSearchPage(ctx, c, id, q, offset)
+}
+
func (s *as) ServeSettingsPage(ctx context.Context, c *model.Client) (err error) {
err = s.authenticateClient(ctx, c)
if err != nil {
diff --git a/service/logging.go b/service/logging.go
index e4f8985..edd1035 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -129,6 +129,15 @@ func (s *ls) ServeSearchPage(ctx context.Context, c *model.Client, q string,
return s.Service.ServeSearchPage(ctx, c, q, qType, offset)
}
+func (s *ls) ServeUserSearchPage(ctx context.Context, c *model.Client,
+ id string, q string, offset int) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, took=%v, err=%v\n",
+ "ServeUserSearchPage", time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeUserSearchPage(ctx, c, id, q, offset)
+}
+
func (s *ls) ServeSettingsPage(ctx context.Context, c *model.Client) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
diff --git a/service/service.go b/service/service.go
index fbf617a..fe025b8 100644
--- a/service/service.go
+++ b/service/service.go
@@ -32,6 +32,7 @@ type Service interface {
ServeAboutPage(ctx context.Context, c *model.Client) (err error)
ServeEmojiPage(ctx context.Context, c *model.Client) (err error)
ServeSearchPage(ctx context.Context, c *model.Client, q string, qType string, offset int) (err error)
+ ServeUserSearchPage(ctx context.Context, c *model.Client, id string, q string, offset int) (err error)
ServeSettingsPage(ctx context.Context, c *model.Client) (err error)
NewSession(ctx context.Context, instance string) (redirectUrl string, sessionID string, err error)
Signin(ctx context.Context, c *model.Client, sessionID string, code string) (token string, err error)
@@ -560,6 +561,48 @@ func (svc *service) ServeUserPage(ctx context.Context, c *model.Client,
return svc.renderer.RenderUserPage(rCtx, c.Writer, data)
}
+func (svc *service) ServeUserSearchPage(ctx context.Context, c *model.Client,
+ id string, q string, offset int) (err error) {
+
+ var nextLink string
+ var title = "search"
+
+ user, err := c.GetAccount(ctx, id)
+ if err != nil {
+ return
+ }
+
+ results, err := c.Search(ctx, q, "statuses", 20, true, offset, id)
+ if err != nil {
+ return
+ }
+
+ if len(results.Statuses) == 20 {
+ offset += 20
+ nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, q, offset)
+ }
+
+ if len(q) > 0 {
+ title += " \"" + q + "\""
+ }
+
+ commonData, err := svc.getCommonData(ctx, c, title)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.UserSearchData{
+ CommonData: commonData,
+ User: user,
+ Q: q,
+ Statuses: results.Statuses,
+ NextLink: nextLink,
+ }
+
+ rCtx := getRendererContext(c)
+ return svc.renderer.RenderUserSearchPage(rCtx, c.Writer, data)
+}
+
func (svc *service) ServeAboutPage(ctx context.Context, c *model.Client) (err error) {
commonData, err := svc.getCommonData(ctx, c, "about")
if err != nil {
@@ -600,7 +643,7 @@ func (svc *service) ServeSearchPage(ctx context.Context, c *model.Client,
var nextLink string
var title = "search"
- results, err := c.Search(ctx, q, qType, 20, true, offset)
+ results, err := c.Search(ctx, q, qType, 20, true, offset, "")
if err != nil {
return
}
diff --git a/service/transport.go b/service/transport.go
index fbab2e5..8f6c547 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -188,6 +188,30 @@ func NewHandler(s Service, staticDir string) http.Handler {
}
}
+ userSearchPage := func(w http.ResponseWriter, req *http.Request) {
+ c := newClient(w)
+ ctx := newCtxWithSesion(req)
+ id, _ := mux.Vars(req)["id"]
+ q := req.URL.Query().Get("q")
+ offsetStr := req.URL.Query().Get("offset")
+
+ var offset int
+ var err error
+ if len(offsetStr) > 1 {
+ offset, err = strconv.Atoi(offsetStr)
+ if err != nil {
+ s.ServeErrorPage(ctx, c, err)
+ return
+ }
+ }
+
+ err = s.ServeUserSearchPage(ctx, c, id, q, offset)
+ if err != nil {
+ s.ServeErrorPage(ctx, c, err)
+ return
+ }
+ }
+
aboutPage := func(w http.ResponseWriter, req *http.Request) {
c := newClient(w)
ctx := newCtxWithSesion(req)
@@ -545,6 +569,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/followers/{id}", followersPage).Methods(http.MethodGet)
r.HandleFunc("/notifications", notificationsPage).Methods(http.MethodGet)
r.HandleFunc("/user/{id}", userPage).Methods(http.MethodGet)
+ r.HandleFunc("/usersearch/{id}", userSearchPage).Methods(http.MethodGet)
r.HandleFunc("/about", aboutPage).Methods(http.MethodGet)
r.HandleFunc("/emojis", emojisPage).Methods(http.MethodGet)
r.HandleFunc("/search", searchPage).Methods(http.MethodGet)