aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--renderer/model.go29
-rw-r--r--renderer/renderer.go28
-rw-r--r--service/auth.go16
-rw-r--r--service/logging.go16
-rw-r--r--service/service.go82
-rw-r--r--service/transport.go22
-rw-r--r--static/main.css32
-rw-r--r--templates/error.tmpl2
-rw-r--r--templates/likedby.tmpl7
-rw-r--r--templates/retweetedby.tmpl7
-rw-r--r--templates/status.tmpl65
-rw-r--r--templates/userlist.tmpl17
12 files changed, 273 insertions, 50 deletions
diff --git a/renderer/model.go b/renderer/model.go
index 4dfac84..20d11d8 100644
--- a/renderer/model.go
+++ b/renderer/model.go
@@ -21,6 +21,19 @@ type CommonData struct {
NavbarData *NavbarData
}
+type ErrorData struct {
+ *CommonData
+ Error string
+}
+
+type HomePageData struct {
+ *CommonData
+}
+
+type SigninData struct {
+ *CommonData
+}
+
type TimelineData struct {
*CommonData
Title string
@@ -59,6 +72,20 @@ type AboutData struct {
}
type EmojiData struct {
+ *CommonData
Emojis []*mastodon.Emoji
- CommonData *CommonData
+}
+
+type LikedByData struct {
+ *CommonData
+ Users []*mastodon.Account
+ HasNext bool
+ NextLink string
+}
+
+type RetweetedByData struct {
+ *CommonData
+ Users []*mastodon.Account
+ HasNext bool
+ NextLink string
}
diff --git a/renderer/renderer.go b/renderer/renderer.go
index 48c0879..061737c 100644
--- a/renderer/renderer.go
+++ b/renderer/renderer.go
@@ -12,15 +12,17 @@ import (
)
type Renderer interface {
- RenderErrorPage(ctx context.Context, writer io.Writer, err error)
- RenderHomePage(ctx context.Context, writer io.Writer) (err error)
- RenderSigninPage(ctx context.Context, writer io.Writer) (err error)
+ RenderErrorPage(ctx context.Context, writer io.Writer, data *ErrorData)
+ RenderHomePage(ctx context.Context, writer io.Writer, data *HomePageData) (err error)
+ RenderSigninPage(ctx context.Context, writer io.Writer, data *SigninData) (err error)
RenderTimelinePage(ctx context.Context, writer io.Writer, data *TimelineData) (err error)
RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadData) (err error)
RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationData) (err error)
RenderUserPage(ctx context.Context, writer io.Writer, data *UserData) (err error)
RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutData) (err error)
RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiData) (err error)
+ RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error)
+ RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error)
}
type renderer struct {
@@ -44,17 +46,17 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
}, nil
}
-func (r *renderer) RenderErrorPage(ctx context.Context, writer io.Writer, err error) {
- r.template.ExecuteTemplate(writer, "error.tmpl", err)
+func (r *renderer) RenderErrorPage(ctx context.Context, writer io.Writer, errorData *ErrorData) {
+ r.template.ExecuteTemplate(writer, "error.tmpl", errorData)
return
}
-func (r *renderer) RenderHomePage(ctx context.Context, writer io.Writer) (err error) {
- return r.template.ExecuteTemplate(writer, "homepage.tmpl", nil)
+func (r *renderer) RenderHomePage(ctx context.Context, writer io.Writer, homePageData *HomePageData) (err error) {
+ return r.template.ExecuteTemplate(writer, "homepage.tmpl", homePageData)
}
-func (r *renderer) RenderSigninPage(ctx context.Context, writer io.Writer) (err error) {
- return r.template.ExecuteTemplate(writer, "signin.tmpl", nil)
+func (r *renderer) RenderSigninPage(ctx context.Context, writer io.Writer, signinData *SigninData) (err error) {
+ return r.template.ExecuteTemplate(writer, "signin.tmpl", signinData)
}
func (r *renderer) RenderTimelinePage(ctx context.Context, writer io.Writer, data *TimelineData) (err error) {
@@ -81,6 +83,14 @@ func (r *renderer) RenderEmojiPage(ctx context.Context, writer io.Writer, data *
return r.template.ExecuteTemplate(writer, "emoji.tmpl", data)
}
+func (r *renderer) RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error) {
+ return r.template.ExecuteTemplate(writer, "likedby.tmpl", data)
+}
+
+func (r *renderer) RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error) {
+ return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", data)
+}
+
func EmojiFilter(content string, emojis []mastodon.Emoji) string {
var replacements []string
for _, e := range emojis {
diff --git a/service/auth.go b/service/auth.go
index cadb050..c408672 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -133,6 +133,22 @@ func (s *authService) ServeEmojiPage(ctx context.Context, client io.Writer, c *m
return s.Service.ServeEmojiPage(ctx, client, c)
}
+func (s *authService) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeLikedByPage(ctx, client, c, id)
+}
+
+func (s *authService) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ c, err = s.getClient(ctx)
+ if err != nil {
+ return
+ }
+ return s.Service.ServeRetweetedByPage(ctx, client, c, id)
+}
+
func (s *authService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
c, err = s.getClient(ctx)
if err != nil {
diff --git a/service/logging.go b/service/logging.go
index 87433a4..fbc6371 100644
--- a/service/logging.go
+++ b/service/logging.go
@@ -109,6 +109,22 @@ func (s *loggingService) ServeEmojiPage(ctx context.Context, client io.Writer, c
return s.Service.ServeEmojiPage(ctx, client, c)
}
+func (s *loggingService) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
+ "ServeLikedByPage", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeLikedByPage(ctx, client, c, id)
+}
+
+func (s *loggingService) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ defer func(begin time.Time) {
+ s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
+ "ServeRetweetedByPage", id, time.Since(begin), err)
+ }(time.Now())
+ return s.Service.ServeRetweetedByPage(ctx, client, c, id)
+}
+
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",
diff --git a/service/service.go b/service/service.go
index ea0d078..7dc784f 100644
--- a/service/service.go
+++ b/service/service.go
@@ -37,6 +37,8 @@ type Service interface {
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 *model.Client) (err error)
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)
Like(ctx context.Context, client io.Writer, c *model.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 *model.Client, id string) (err error)
@@ -192,25 +194,48 @@ func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *model
}
func (svc *service) ServeHomePage(ctx context.Context, client io.Writer) (err error) {
- err = svc.renderer.RenderHomePage(ctx, client)
+ commonData, err := svc.getCommonData(ctx, client, nil)
if err != nil {
return
}
- return
+ data := &renderer.HomePageData{
+ CommonData: commonData,
+ }
+
+ return svc.renderer.RenderHomePage(ctx, client, data)
}
func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
- svc.renderer.RenderErrorPage(ctx, client, err)
+ var errStr string
+ if err != nil {
+ errStr = err.Error()
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, nil)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.ErrorData{
+ CommonData: commonData,
+ Error: errStr,
+ }
+
+ svc.renderer.RenderErrorPage(ctx, client, data)
}
func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
- err = svc.renderer.RenderSigninPage(ctx, client)
+ commonData, err := svc.getCommonData(ctx, client, nil)
if err != nil {
return
}
- return
+ data := &renderer.SigninData{
+ CommonData: commonData,
+ }
+
+ return svc.renderer.RenderSigninPage(ctx, client, data)
}
func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
@@ -517,6 +542,53 @@ func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *mod
return
}
+func (svc *service) ServeLikedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ likers, err := c.GetFavouritedBy(ctx, id, nil)
+ if err != nil {
+ return
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.LikedByData{
+ CommonData: commonData,
+ Users: likers,
+ }
+
+ err = svc.renderer.RenderLikedByPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
+
+func (svc *service) ServeRetweetedByPage(ctx context.Context, client io.Writer, c *model.Client, id string) (err error) {
+ retweeters, err := c.GetRebloggedBy(ctx, id, nil)
+ if err != nil {
+ return
+ }
+
+ commonData, err := svc.getCommonData(ctx, client, c)
+ if err != nil {
+ return
+ }
+
+ data := &renderer.RetweetedByData{
+ CommonData: commonData,
+ Users: retweeters,
+ }
+
+ err = svc.renderer.RenderRetweetedByPage(ctx, client, data)
+ if err != nil {
+ return
+ }
+
+ return
+}
func (svc *service) getCommonData(ctx context.Context, client io.Writer, c *model.Client) (data *renderer.CommonData, err error) {
data = new(renderer.CommonData)
diff --git a/service/transport.go b/service/transport.go
index 438b39d..d4011db 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -98,6 +98,28 @@ func NewHandler(s Service, staticDir string) http.Handler {
}
}).Methods(http.MethodGet)
+ r.HandleFunc("/likedby/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.ServeLikedByPage(ctx, w, nil, id)
+ if err != nil {
+ s.ServeErrorPage(ctx, w, err)
+ return
+ }
+ }).Methods(http.MethodGet)
+
+ r.HandleFunc("/retweetedby/{id}", func(w http.ResponseWriter, req *http.Request) {
+ ctx := getContextWithSession(context.Background(), req)
+ id, _ := mux.Vars(req)["id"]
+
+ err := s.ServeRetweetedByPage(ctx, w, nil, id)
+ 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"]
diff --git a/static/main.css b/static/main.css
index 99e2cf0..87e2cfa 100644
--- a/static/main.css
+++ b/static/main.css
@@ -63,26 +63,31 @@
width: auto;
}
-.status-action {
+.status-action-container {
margin-top: 4px;
}
-.status-action a {
+.status-action {
display: inline-block;
min-width: 64px;
+}
+
+.status-action:last-child {
+ min-width: unset;
+}
+
+.status-action a {
+ display: inline-block;
text-decoration: none;
color: #333333;
vertical-align: middle;
}
-.status-action a:hover {
+.status-action a:hover,
+.status-action a:hover i {
color: #777777;
}
-.status-action .fa {
- margin: 0 4px 0 0;
-}
-
.status-action a.status-time {
width: auto;
}
@@ -368,3 +373,16 @@
margin-right: 2px;
}
+.user-list-container {
+ margin: 8px 0;
+}
+
+.user-list-item a {
+ text-decoration: none;
+}
+
+.user-list-item>div {
+ display: inline-block;
+ vertical-align: top;
+ margin: 0 4px 8px 0;
+}
diff --git a/templates/error.tmpl b/templates/error.tmpl
index 0389cdd..2049665 100644
--- a/templates/error.tmpl
+++ b/templates/error.tmpl
@@ -1,6 +1,6 @@
{{template "header.tmpl" .HeaderData}}
<div class="page-title"> Error </div>
-<div class="error-text"> {{.}} </div>
+<div class="error-text"> {{.Error}} </div>
<div>
<a href="/timeline/home">Home</a>
<a href="/signin">Sign In</a>
diff --git a/templates/likedby.tmpl b/templates/likedby.tmpl
new file mode 100644
index 0000000..72855e0
--- /dev/null
+++ b/templates/likedby.tmpl
@@ -0,0 +1,7 @@
+{{template "header.tmpl" .HeaderData}}
+{{template "navigation.tmpl" .NavbarData}}
+<div class="page-title"> Liked By </div>
+
+{{template "userlist.tmpl" .Users}}
+
+{{template "footer.tmpl"}}
diff --git a/templates/retweetedby.tmpl b/templates/retweetedby.tmpl
new file mode 100644
index 0000000..2d9c539
--- /dev/null
+++ b/templates/retweetedby.tmpl
@@ -0,0 +1,7 @@
+{{template "header.tmpl" .HeaderData}}
+{{template "navigation.tmpl" .NavbarData}}
+<div class="page-title"> Retweeted By </div>
+
+{{template "userlist.tmpl" .Users}}
+
+{{template "footer.tmpl"}}
diff --git a/templates/status.tmpl b/templates/status.tmpl
index 6534249..4e975ad 100644
--- a/templates/status.tmpl
+++ b/templates/status.tmpl
@@ -85,43 +85,54 @@
{{end}}
{{end}}
</div>
- <div class="status-action">
- <a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply">
- <i class="fa fa-reply"></i>
- <span> {{DisplayInteractionCount .RepliesCount}} </span>
- </a>
- {{if or (eq .Visibility "private") (eq .Visibility "direct")}}
- <a class="status-retweet" title="this status cannot be retweeted">
- <i class="fa fa-retweet"></i>
- <span> {{DisplayInteractionCount .ReblogsCount}} </span>
- </a>
- {{else}}
+ <div class="status-action-container">
+ <div class="status-action">
+ <a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply">
+ <i class="fa fa-reply"></i>
+ </a>
+ <a class="status-action-count" href="/thread/{{.ID}}#status-{{.ID}}">
+ <span> {{DisplayInteractionCount .RepliesCount}} </span>
+ </a>
+ </div>
+ <div class="status-action">
+ {{if or (eq .Visibility "private") (eq .Visibility "direct")}}
+ <a class="status-retweet" title="this status cannot be retweeted">
+ <i class="fa fa-retweet"></i>
+ </a>
+ {{else}}
{{if .Reblogged}}
<a class="status-retweet" href="/unretweet/{{.ID}}" title="undo retweet">
<i class="fa fa-retweet retweeted"></i>
- <span> {{DisplayInteractionCount .ReblogsCount}} </span>
</a>
{{else}}
<a class="status-retweet" href="/retweet/{{.ID}}" title="retweet">
<i class="fa fa-retweet"></i>
+ </a>
+ {{end}}
+ {{end}}
+ <a class="status-action-count" href="/retweetedby/{{.ID}}" title="click to see the the list">
<span> {{DisplayInteractionCount .ReblogsCount}} </span>
</a>
+ </div>
+ <div class="status-action">
+ {{if .Favourited}}
+ <a class="status-like" href="/unlike/{{.ID}}" title="unlike">
+ <i class="fa fa-star liked"></i>
+ </a>
+ {{else}}
+ <a class="status-like" href="/like/{{.ID}}" title="like">
+ <i class="fa fa-star-o"></i>
+ </a>
{{end}}
- {{end}}
- {{if .Favourited}}
- <a class="status-like" href="/unlike/{{.ID}}" title="unlike">
- <i class="fa fa-star liked"></i>
- <span> {{DisplayInteractionCount .FavouritesCount}} </span>
- </a>
- {{else}}
- <a class="status-like" href="/like/{{.ID}}" title="like">
- <i class="fa fa-star-o"></i>
- <span> {{DisplayInteractionCount .FavouritesCount}} </span>
- </a>
- {{end}}
- <a class="status-time" href="/thread/{{.ID}}#status-{{.ID}}">
- <time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{.CreatedAt}}"> {{TimeSince .CreatedAt}} </time>
- </a>
+ <a class="status-action-count" href="/likedby/{{.ID}}" title="click to see the the list">
+ <span> {{DisplayInteractionCount .FavouritesCount}} </span>
+ </a>
+ </div>
+ <div class="status-action">
+ <a class="status-time" href="/thread/{{.ID}}#status-{{.ID}}">
+ <time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{.CreatedAt}}"> {{TimeSince .CreatedAt}} </time>
+ </a>
+ </div>
</div>
</div>
</div>
diff --git a/templates/userlist.tmpl b/templates/userlist.tmpl
new file mode 100644
index 0000000..d52e67d
--- /dev/null
+++ b/templates/userlist.tmpl
@@ -0,0 +1,17 @@
+<div class="user-list-container">
+ {{range .}}
+ <div class="user-list-item">
+ <div>
+ <a class="img-link" href="/user/{{.ID}}">
+ <img class="status-profile-img" src="{{.AvatarStatic}}" alt="avatar" />
+ </a>
+ </div>
+ <div>
+ <div class="status-dname"> {{EmojiFilter .DisplayName .Emojis}} </div>
+ <a class="img-link" href="/user/{{.ID}}">
+ <div class="status-uname"> {{.Acct}} </div>
+ </a>
+ </div>
+ </div>
+ {{end}}
+</div>