mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-05 11:28:45 +00:00
Add following and followers page
This commit is contained in:
parent
b9d7eb05be
commit
72dbe50341
9 changed files with 195 additions and 2 deletions
|
@ -149,6 +149,22 @@ func (s *authService) ServeRetweetedByPage(ctx context.Context, client io.Writer
|
|||
return s.Service.ServeRetweetedByPage(ctx, client, c, id)
|
||||
}
|
||||
|
||||
func (s *authService) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||
c, err = s.getClient(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return s.Service.ServeFollowingPage(ctx, client, c, id, maxID, minID)
|
||||
}
|
||||
|
||||
func (s *authService) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||
c, err = s.getClient(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return s.Service.ServeFollowersPage(ctx, client, c, id, maxID, minID)
|
||||
}
|
||||
|
||||
func (s *authService) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
|
||||
c, err = s.getClient(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -125,6 +125,22 @@ func (s *loggingService) ServeRetweetedByPage(ctx context.Context, client io.Wri
|
|||
return s.Service.ServeRetweetedByPage(ctx, client, c, id)
|
||||
}
|
||||
|
||||
func (s *loggingService) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
||||
"ServeFollowingPage", id, maxID, minID, time.Since(begin), err)
|
||||
}(time.Now())
|
||||
return s.Service.ServeFollowingPage(ctx, client, c, id, maxID, minID)
|
||||
}
|
||||
|
||||
func (s *loggingService) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
||||
"ServeFollowersPage", id, maxID, minID, time.Since(begin), err)
|
||||
}(time.Now())
|
||||
return s.Service.ServeFollowersPage(ctx, client, c, id, maxID, minID)
|
||||
}
|
||||
|
||||
func (s *loggingService) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
|
||||
defer func(begin time.Time) {
|
||||
s.logger.Printf("method=%v, q=%v, type=%v, offset=%v, took=%v, err=%v\n",
|
||||
|
|
|
@ -39,6 +39,8 @@ type Service interface {
|
|||
ServeEmojiPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
|
||||
ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||
ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||
ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
|
||||
ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
|
||||
ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error)
|
||||
ServeSettingsPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
|
||||
SaveSettings(ctx context.Context, client io.Writer, c *model.Client, settings *model.Settings) (err error)
|
||||
|
@ -603,6 +605,87 @@ func (svc *service) ServeRetweetedByPage(ctx context.Context, client io.Writer,
|
|||
return
|
||||
}
|
||||
|
||||
func (svc *service) ServeFollowingPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||
var hasNext bool
|
||||
var nextLink string
|
||||
|
||||
var pg = mastodon.Pagination{
|
||||
MaxID: maxID,
|
||||
MinID: minID,
|
||||
Limit: 20,
|
||||
}
|
||||
|
||||
followings, err := c.GetAccountFollowing(ctx, id, &pg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(followings) == 20 && len(pg.MaxID) > 0 {
|
||||
hasNext = true
|
||||
nextLink = "/following/" + id + "?max_id=" + pg.MaxID
|
||||
}
|
||||
|
||||
commonData, err := svc.getCommonData(ctx, client, c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data := &renderer.FollowingData{
|
||||
CommonData: commonData,
|
||||
Users: followings,
|
||||
HasNext: hasNext,
|
||||
NextLink: nextLink,
|
||||
}
|
||||
|
||||
err = svc.renderer.RenderFollowingPage(ctx, client, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *service) ServeFollowersPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||
var hasNext bool
|
||||
var nextLink string
|
||||
|
||||
var pg = mastodon.Pagination{
|
||||
MaxID: maxID,
|
||||
MinID: minID,
|
||||
Limit: 20,
|
||||
}
|
||||
|
||||
followers, err := c.GetAccountFollowers(ctx, id, &pg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(len(followers), pg.MaxID)
|
||||
if len(followers) == 20 && len(pg.MaxID) > 0 {
|
||||
hasNext = true
|
||||
nextLink = "/followers/" + id + "?max_id=" + pg.MaxID
|
||||
}
|
||||
|
||||
commonData, err := svc.getCommonData(ctx, client, c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data := &renderer.FollowersData{
|
||||
CommonData: commonData,
|
||||
Users: followers,
|
||||
HasNext: hasNext,
|
||||
NextLink: nextLink,
|
||||
}
|
||||
|
||||
err = svc.renderer.RenderFollowersPage(ctx, client, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (svc *service) ServeSearchPage(ctx context.Context, client io.Writer, c *model.Client, q string, qType string, offset int) (err error) {
|
||||
var hasNext bool
|
||||
var nextLink string
|
||||
|
|
|
@ -122,6 +122,34 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
|||
}
|
||||
}).Methods(http.MethodGet)
|
||||
|
||||
r.HandleFunc("/following/{id}", func(w http.ResponseWriter, req *http.Request) {
|
||||
ctx := getContextWithSession(context.Background(), req)
|
||||
|
||||
id, _ := mux.Vars(req)["id"]
|
||||
maxID := req.URL.Query().Get("max_id")
|
||||
minID := req.URL.Query().Get("min_id")
|
||||
|
||||
err := s.ServeFollowingPage(ctx, w, nil, id, maxID, minID)
|
||||
if err != nil {
|
||||
s.ServeErrorPage(ctx, w, err)
|
||||
return
|
||||
}
|
||||
}).Methods(http.MethodGet)
|
||||
|
||||
r.HandleFunc("/followers/{id}", func(w http.ResponseWriter, req *http.Request) {
|
||||
ctx := getContextWithSession(context.Background(), req)
|
||||
|
||||
id, _ := mux.Vars(req)["id"]
|
||||
maxID := req.URL.Query().Get("max_id")
|
||||
minID := req.URL.Query().Get("min_id")
|
||||
|
||||
err := s.ServeFollowersPage(ctx, w, nil, id, maxID, minID)
|
||||
if err != nil {
|
||||
s.ServeErrorPage(ctx, w, err)
|
||||
return
|
||||
}
|
||||
}).Methods(http.MethodGet)
|
||||
|
||||
r.HandleFunc("/like/{id}", func(w http.ResponseWriter, req *http.Request) {
|
||||
ctx := getContextWithSession(context.Background(), req)
|
||||
id, _ := mux.Vars(req)["id"]
|
||||
|
@ -323,7 +351,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
|||
copyScope := req.FormValue("copy_scope") == "true"
|
||||
settings := &model.Settings{
|
||||
DefaultVisibility: visibility,
|
||||
CopyScope: copyScope,
|
||||
CopyScope: copyScope,
|
||||
}
|
||||
|
||||
err := s.SaveSettings(ctx, w, nil, settings)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue