mirror of
https://git.freesoftwareextremist.com/bloat
synced 2024-12-22 17:10:42 +00:00
Add liked by and retweeted by page
This commit is contained in:
parent
c34bde2d52
commit
ac4ff88adb
12 changed files with 276 additions and 53 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
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.ErrorData{
|
||||
CommonData: commonData,
|
||||
Error: errStr,
|
||||
}
|
||||
|
||||
svc.renderer.RenderErrorPage(ctx, client, data)
|
||||
}
|
||||
|
||||
func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
|
||||
commonData, err := svc.getCommonData(ctx, client, nil)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -63,26 +63,31 @@
|
|||
width: auto;
|
||||
}
|
||||
|
||||
.status-action {
|
||||
.status-action-container {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.status-action {
|
||||
display: inline-block;
|
||||
min-width: 64px;
|
||||
}
|
||||
|
||||
.status-action:last-child {
|
||||
min-width: unset;
|
||||
}
|
||||
|
||||
.status-action a {
|
||||
display: inline-block;
|
||||
min-width: 64px;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
7
templates/likedby.tmpl
Normal file
7
templates/likedby.tmpl
Normal file
|
@ -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"}}
|
7
templates/retweetedby.tmpl
Normal file
7
templates/retweetedby.tmpl
Normal file
|
@ -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"}}
|
|
@ -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>
|
||||
<span> {{DisplayInteractionCount .ReblogsCount}} </span>
|
||||
</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>
|
||||
{{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}}
|
||||
<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>
|
||||
|
|
17
templates/userlist.tmpl
Normal file
17
templates/userlist.tmpl
Normal file
|
@ -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>
|
Loading…
Reference in a new issue