Use a custom client for settings
This commit is contained in:
parent
e73eb1162a
commit
3af4361927
|
@ -0,0 +1,8 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
import "mastodon"
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
*mastodon.Client
|
||||||
|
Session Session
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ type Session struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
InstanceDomain string `json:"instance_domain"`
|
InstanceDomain string `json:"instance_domain"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
|
Settings Settings `json:"settings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionRepository interface {
|
type SessionRepository interface {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
type Settings struct {
|
||||||
|
}
|
|
@ -31,7 +31,7 @@ func getSessionID(ctx context.Context) (sessionID string, err error) {
|
||||||
return sessionID, nil
|
return sessionID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) getClient(ctx context.Context) (c *mastodon.Client, err error) {
|
func (s *authService) getClient(ctx context.Context) (c *model.Client, err error) {
|
||||||
sessionID, err := getSessionID(ctx)
|
sessionID, err := getSessionID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrInvalidSession
|
return nil, ErrInvalidSession
|
||||||
|
@ -44,12 +44,13 @@ func (s *authService) getClient(ctx context.Context) (c *mastodon.Client, err er
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c = mastodon.NewClient(&mastodon.Config{
|
mc := mastodon.NewClient(&mastodon.Config{
|
||||||
Server: client.InstanceURL,
|
Server: client.InstanceURL,
|
||||||
ClientID: client.ClientID,
|
ClientID: client.ClientID,
|
||||||
ClientSecret: client.ClientSecret,
|
ClientSecret: client.ClientSecret,
|
||||||
AccessToken: session.AccessToken,
|
AccessToken: session.AccessToken,
|
||||||
})
|
})
|
||||||
|
c = &model.Client{Client: mc}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ func (s *authService) GetAuthUrl(ctx context.Context, instance string) (
|
||||||
return s.Service.GetAuthUrl(ctx, instance)
|
return s.Service.GetAuthUrl(ctx, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) GetUserToken(ctx context.Context, sessionID string, c *mastodon.Client,
|
func (s *authService) GetUserToken(ctx context.Context, sessionID string, c *model.Client,
|
||||||
code string) (token string, err error) {
|
code string) (token string, err error) {
|
||||||
sessionID, err = getSessionID(ctx)
|
sessionID, err = getSessionID(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,7 +96,7 @@ func (s *authService) ServeSigninPage(ctx context.Context, client io.Writer) (er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
func (s *authService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
||||||
c *mastodon.Client, maxID string, sinceID string, minID string) (err error) {
|
c *model.Client, maxID string, sinceID string, minID string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -103,7 +104,7 @@ func (s *authService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
||||||
return s.Service.ServeTimelinePage(ctx, client, c, maxID, sinceID, minID)
|
return s.Service.ServeTimelinePage(ctx, client, c, maxID, sinceID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) ServeThreadPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, reply bool) (err error) {
|
func (s *authService) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -111,7 +112,7 @@ func (s *authService) ServeThreadPage(ctx context.Context, client io.Writer, c *
|
||||||
return s.Service.ServeThreadPage(ctx, client, c, id, reply)
|
return s.Service.ServeThreadPage(ctx, client, c, id, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) ServeNotificationPage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, minID string) (err error) {
|
func (s *authService) ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -119,7 +120,7 @@ func (s *authService) ServeNotificationPage(ctx context.Context, client io.Write
|
||||||
return s.Service.ServeNotificationPage(ctx, client, c, maxID, minID)
|
return s.Service.ServeNotificationPage(ctx, client, c, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) ServeUserPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, maxID string, minID string) (err error) {
|
func (s *authService) ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -127,7 +128,7 @@ func (s *authService) ServeUserPage(ctx context.Context, client io.Writer, c *ma
|
||||||
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
|
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error) {
|
func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -135,7 +136,7 @@ func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *m
|
||||||
return s.Service.ServeAboutPage(ctx, client, c)
|
return s.Service.ServeAboutPage(ctx, client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -143,7 +144,7 @@ func (s *authService) Like(ctx context.Context, client io.Writer, c *mastodon.Cl
|
||||||
return s.Service.Like(ctx, client, c, id)
|
return s.Service.Like(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *authService) UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -151,7 +152,7 @@ func (s *authService) UnLike(ctx context.Context, client io.Writer, c *mastodon.
|
||||||
return s.Service.UnLike(ctx, client, c, id)
|
return s.Service.UnLike(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *authService) Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -159,7 +160,7 @@ func (s *authService) Retweet(ctx context.Context, client io.Writer, c *mastodon
|
||||||
return s.Service.Retweet(ctx, client, c, id)
|
return s.Service.Retweet(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -167,7 +168,7 @@ func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *mastod
|
||||||
return s.Service.UnRetweet(ctx, client, c, id)
|
return s.Service.UnRetweet(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
|
func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -175,7 +176,7 @@ func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *mastod
|
||||||
return s.Service.PostTweet(ctx, client, c, content, replyToID, files)
|
return s.Service.PostTweet(ctx, client, c, content, replyToID, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) Follow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *authService) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -183,7 +184,7 @@ func (s *authService) Follow(ctx context.Context, client io.Writer, c *mastodon.
|
||||||
return s.Service.Follow(ctx, client, c, id)
|
return s.Service.Follow(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *authService) UnFollow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *authService) UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"mastodon"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"time"
|
"time"
|
||||||
|
"web/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type loggingService struct {
|
type loggingService struct {
|
||||||
|
@ -27,7 +27,7 @@ func (s *loggingService) GetAuthUrl(ctx context.Context, instance string) (
|
||||||
return s.Service.GetAuthUrl(ctx, instance)
|
return s.Service.GetAuthUrl(ctx, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) GetUserToken(ctx context.Context, sessionID string, c *mastodon.Client,
|
func (s *loggingService) GetUserToken(ctx context.Context, sessionID string, c *model.Client,
|
||||||
code string) (token string, err error) {
|
code string) (token string, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, session_id=%v, code=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, session_id=%v, code=%v, took=%v, err=%v\n",
|
||||||
|
@ -61,7 +61,7 @@ func (s *loggingService) ServeSigninPage(ctx context.Context, client io.Writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
func (s *loggingService) ServeTimelinePage(ctx context.Context, client io.Writer,
|
||||||
c *mastodon.Client, maxID string, sinceID string, minID string) (err error) {
|
c *model.Client, maxID string, sinceID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, max_id=%v, since_id=%v, min_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, max_id=%v, since_id=%v, min_id=%v, took=%v, err=%v\n",
|
||||||
"ServeTimelinePage", maxID, sinceID, minID, time.Since(begin), err)
|
"ServeTimelinePage", maxID, sinceID, minID, time.Since(begin), err)
|
||||||
|
@ -69,7 +69,7 @@ func (s *loggingService) ServeTimelinePage(ctx context.Context, client io.Writer
|
||||||
return s.Service.ServeTimelinePage(ctx, client, c, maxID, sinceID, minID)
|
return s.Service.ServeTimelinePage(ctx, client, c, maxID, sinceID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeThreadPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, reply bool) (err error) {
|
func (s *loggingService) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, reply=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, reply=%v, took=%v, err=%v\n",
|
||||||
"ServeThreadPage", id, reply, time.Since(begin), err)
|
"ServeThreadPage", id, reply, time.Since(begin), err)
|
||||||
|
@ -77,7 +77,7 @@ func (s *loggingService) ServeThreadPage(ctx context.Context, client io.Writer,
|
||||||
return s.Service.ServeThreadPage(ctx, client, c, id, reply)
|
return s.Service.ServeThreadPage(ctx, client, c, id, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeNotificationPage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, minID string) (err error) {
|
func (s *loggingService) ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
||||||
"ServeNotificationPage", maxID, minID, time.Since(begin), err)
|
"ServeNotificationPage", maxID, minID, time.Since(begin), err)
|
||||||
|
@ -85,7 +85,7 @@ func (s *loggingService) ServeNotificationPage(ctx context.Context, client io.Wr
|
||||||
return s.Service.ServeNotificationPage(ctx, client, c, maxID, minID)
|
return s.Service.ServeNotificationPage(ctx, client, c, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeUserPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, maxID string, minID string) (err error) {
|
func (s *loggingService) ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, max_id=%v, min_id=%v, took=%v, err=%v\n",
|
||||||
"ServeUserPage", id, maxID, minID, time.Since(begin), err)
|
"ServeUserPage", id, maxID, minID, time.Since(begin), err)
|
||||||
|
@ -93,7 +93,7 @@ func (s *loggingService) ServeUserPage(ctx context.Context, client io.Writer, c
|
||||||
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
|
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error) {
|
func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, took=%v, err=%v\n",
|
||||||
"ServeAboutPage", time.Since(begin), err)
|
"ServeAboutPage", time.Since(begin), err)
|
||||||
|
@ -101,7 +101,7 @@ func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c
|
||||||
return s.Service.ServeAboutPage(ctx, client, c)
|
return s.Service.ServeAboutPage(ctx, client, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"Like", id, time.Since(begin), err)
|
"Like", id, time.Since(begin), err)
|
||||||
|
@ -109,7 +109,7 @@ func (s *loggingService) Like(ctx context.Context, client io.Writer, c *mastodon
|
||||||
return s.Service.Like(ctx, client, c, id)
|
return s.Service.Like(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *loggingService) UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"UnLike", id, time.Since(begin), err)
|
"UnLike", id, time.Since(begin), err)
|
||||||
|
@ -117,7 +117,7 @@ func (s *loggingService) UnLike(ctx context.Context, client io.Writer, c *mastod
|
||||||
return s.Service.UnLike(ctx, client, c, id)
|
return s.Service.UnLike(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *loggingService) Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"Retweet", id, time.Since(begin), err)
|
"Retweet", id, time.Since(begin), err)
|
||||||
|
@ -125,7 +125,7 @@ func (s *loggingService) Retweet(ctx context.Context, client io.Writer, c *masto
|
||||||
return s.Service.Retweet(ctx, client, c, id)
|
return s.Service.Retweet(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) UnRetweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *loggingService) UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"UnRetweet", id, time.Since(begin), err)
|
"UnRetweet", id, time.Since(begin), err)
|
||||||
|
@ -133,7 +133,7 @@ func (s *loggingService) UnRetweet(ctx context.Context, client io.Writer, c *mas
|
||||||
return s.Service.UnRetweet(ctx, client, c, id)
|
return s.Service.UnRetweet(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
|
func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, content=%v, reply_to_id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, content=%v, reply_to_id=%v, took=%v, err=%v\n",
|
||||||
"PostTweet", content, replyToID, time.Since(begin), err)
|
"PostTweet", content, replyToID, time.Since(begin), err)
|
||||||
|
@ -141,7 +141,7 @@ func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *mas
|
||||||
return s.Service.PostTweet(ctx, client, c, content, replyToID, files)
|
return s.Service.PostTweet(ctx, client, c, content, replyToID, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) Follow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *loggingService) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"Follow", id, time.Since(begin), err)
|
"Follow", id, time.Since(begin), err)
|
||||||
|
@ -149,7 +149,7 @@ func (s *loggingService) Follow(ctx context.Context, client io.Writer, c *mastod
|
||||||
return s.Service.Follow(ctx, client, c, id)
|
return s.Service.Follow(ctx, client, c, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *loggingService) UnFollow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (s *loggingService) UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
defer func(begin time.Time) {
|
defer func(begin time.Time) {
|
||||||
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
|
||||||
"UnFollow", id, time.Since(begin), err)
|
"UnFollow", id, time.Since(begin), err)
|
||||||
|
|
|
@ -26,21 +26,21 @@ var (
|
||||||
type Service interface {
|
type Service interface {
|
||||||
ServeHomePage(ctx context.Context, client io.Writer) (err error)
|
ServeHomePage(ctx context.Context, client io.Writer) (err error)
|
||||||
GetAuthUrl(ctx context.Context, instance string) (url string, sessionID string, err error)
|
GetAuthUrl(ctx context.Context, instance string) (url string, sessionID string, err error)
|
||||||
GetUserToken(ctx context.Context, sessionID string, c *mastodon.Client, token string) (accessToken string, err error)
|
GetUserToken(ctx context.Context, sessionID string, c *model.Client, token string) (accessToken string, err error)
|
||||||
ServeErrorPage(ctx context.Context, client io.Writer, err error)
|
ServeErrorPage(ctx context.Context, client io.Writer, err error)
|
||||||
ServeSigninPage(ctx context.Context, client io.Writer) (err error)
|
ServeSigninPage(ctx context.Context, client io.Writer) (err error)
|
||||||
ServeTimelinePage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, sinceID string, minID string) (err error)
|
ServeTimelinePage(ctx context.Context, client io.Writer, c *model.Client, maxID string, sinceID string, minID string) (err error)
|
||||||
ServeThreadPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, reply bool) (err error)
|
ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error)
|
||||||
ServeNotificationPage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, minID string) (err error)
|
ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error)
|
||||||
ServeUserPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, maxID string, minID string) (err error)
|
ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error)
|
||||||
ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error)
|
ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error)
|
||||||
Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
UnRetweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error)
|
PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error)
|
||||||
Follow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
UnFollow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
|
@ -132,7 +132,7 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *mastodon.Client,
|
func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *model.Client,
|
||||||
code string) (token string, err error) {
|
code string) (token string, err error) {
|
||||||
if len(code) < 1 {
|
if len(code) < 1 {
|
||||||
err = ErrInvalidArgument
|
err = ErrInvalidArgument
|
||||||
|
@ -209,7 +209,7 @@ func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
|
func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
|
||||||
c *mastodon.Client, maxID string, sinceID string, minID string) (err error) {
|
c *model.Client, maxID string, sinceID string, minID string) (err error) {
|
||||||
|
|
||||||
var hasNext, hasPrev bool
|
var hasNext, hasPrev bool
|
||||||
var nextLink, prevLink string
|
var nextLink, prevLink string
|
||||||
|
@ -265,7 +265,7 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, reply bool) (err error) {
|
func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) {
|
||||||
status, err := c.GetStatus(ctx, id)
|
status, err := c.GetStatus(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -323,7 +323,7 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *ma
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, minID string) (err error) {
|
func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer, c *model.Client, maxID string, minID string) (err error) {
|
||||||
var hasNext bool
|
var hasNext bool
|
||||||
var nextLink string
|
var nextLink string
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, maxID string, minID string) (err error) {
|
func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *model.Client, id string, maxID string, minID string) (err error) {
|
||||||
user, err := c.GetAccount(ctx, id)
|
user, err := c.GetAccount(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -416,7 +416,7 @@ func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mast
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error) {
|
func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *model.Client) (err error) {
|
||||||
navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
|
navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -431,7 +431,7 @@ func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mas
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *mastodon.Client) (data *renderer.NavbarTemplateData, err error) {
|
func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.NavbarTemplateData, err error) {
|
||||||
notifications, err := c.GetNotifications(ctx, nil)
|
notifications, err := c.GetNotifications(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -449,27 +449,27 @@ func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (svc *service) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
_, err = c.Favourite(ctx, id)
|
_, err = c.Favourite(ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (svc *service) UnLike(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
_, err = c.Unfavourite(ctx, id)
|
_, err = c.Unfavourite(ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (svc *service) Retweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
_, err = c.Reblog(ctx, id)
|
_, err = c.Reblog(ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) UnRetweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (svc *service) UnRetweet(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
_, err = c.Unreblog(ctx, id)
|
_, err = c.Unreblog(ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
|
func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *model.Client, content string, replyToID string, files []*multipart.FileHeader) (id string, err error) {
|
||||||
var mediaIds []string
|
var mediaIds []string
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
a, err := c.UploadMediaFromMultipartFileHeader(ctx, f)
|
a, err := c.UploadMediaFromMultipartFileHeader(ctx, f)
|
||||||
|
@ -493,12 +493,12 @@ func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon
|
||||||
return s.ID, nil
|
return s.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) Follow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (svc *service) Follow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
_, err = c.AccountFollow(ctx, id)
|
_, err = c.AccountFollow(ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) UnFollow(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
|
func (svc *service) UnFollow(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
|
||||||
_, err = c.AccountUnfollow(ctx, id)
|
_, err = c.AccountUnfollow(ctx, id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -507,6 +507,7 @@ func addToReplyMap(m map[string][]mastodon.ReplyInfo, key interface{}, val strin
|
||||||
if key == nil {
|
if key == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
keyStr, ok := key.(string)
|
keyStr, ok := key.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue