Focus relevant status on like, retweet and reply
This commit is contained in:
parent
787a197ad8
commit
ea66bd539d
|
@ -142,7 +142,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) (err error) {
|
func (s *authService) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (id string, err error) {
|
||||||
c, err = s.getClient(ctx)
|
c, err = s.getClient(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -108,7 +108,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) (err error) {
|
func (s *loggingService) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (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)
|
||||||
|
|
|
@ -36,7 +36,7 @@ type Service interface {
|
||||||
UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
|
UnLike(ctx context.Context, client io.Writer, c *mastodon.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 *mastodon.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 *mastodon.Client, id string) (err error)
|
||||||
PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (err error)
|
PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (id string, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
|
@ -292,11 +292,16 @@ func (svc *service) UnRetweet(ctx context.Context, client io.Writer, c *mastodon
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (err error) {
|
func (svc *service) PostTweet(ctx context.Context, client io.Writer, c *mastodon.Client, content string, replyToID string) (id string, err error) {
|
||||||
tweet := &mastodon.Toot{
|
tweet := &mastodon.Toot{
|
||||||
Status: content,
|
Status: content,
|
||||||
InReplyToID: replyToID,
|
InReplyToID: replyToID,
|
||||||
}
|
}
|
||||||
_, err = c.PostStatus(ctx, tweet)
|
|
||||||
return
|
s, err := c.PostStatus(ctx, tweet)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.ID, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("Location", req.Header.Get("Referer"))
|
w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
|
||||||
w.WriteHeader(http.StatusSeeOther)
|
w.WriteHeader(http.StatusSeeOther)
|
||||||
}).Methods(http.MethodGet)
|
}).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("Location", req.Header.Get("Referer"))
|
w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
|
||||||
w.WriteHeader(http.StatusSeeOther)
|
w.WriteHeader(http.StatusSeeOther)
|
||||||
}).Methods(http.MethodGet)
|
}).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("Location", req.Header.Get("Referer"))
|
w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
|
||||||
w.WriteHeader(http.StatusSeeOther)
|
w.WriteHeader(http.StatusSeeOther)
|
||||||
}).Methods(http.MethodGet)
|
}).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("Location", req.Header.Get("Referer"))
|
w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
|
||||||
w.WriteHeader(http.StatusSeeOther)
|
w.WriteHeader(http.StatusSeeOther)
|
||||||
}).Methods(http.MethodGet)
|
}).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
@ -155,15 +155,15 @@ func NewHandler(s Service, staticDir string) http.Handler {
|
||||||
ctx := getContextWithSession(context.Background(), req)
|
ctx := getContextWithSession(context.Background(), req)
|
||||||
content := req.FormValue("content")
|
content := req.FormValue("content")
|
||||||
replyToID := req.FormValue("reply_to_id")
|
replyToID := req.FormValue("reply_to_id")
|
||||||
err := s.PostTweet(ctx, w, nil, content, replyToID)
|
id, err := s.PostTweet(ctx, w, nil, content, replyToID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.ServeErrorPage(ctx, w, err)
|
s.ServeErrorPage(ctx, w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
location := "/timeline"
|
location := "/timeline" + "#status-" + id
|
||||||
if len(replyToID) > 0 {
|
if len(replyToID) > 0 {
|
||||||
location = "/thread/" + replyToID
|
location = "/thread/" + replyToID + "#status-" + id
|
||||||
}
|
}
|
||||||
w.Header().Add("Location", location)
|
w.Header().Add("Location", location)
|
||||||
w.WriteHeader(http.StatusSeeOther)
|
w.WriteHeader(http.StatusSeeOther)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div id="status-{{.ID}}" class="status-container-container">
|
<div id="status-{{if .Reblog}}{{.Reblog.ID}}{{else}}{{.ID}}{{end}}" class="status-container-container">
|
||||||
{{if .Reblog}}
|
{{if .Reblog}}
|
||||||
<div class="retweet-info">
|
<div class="retweet-info">
|
||||||
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
|
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
<span> {{DisplayInteractionCount .FavouritesCount}} </span>
|
<span> {{DisplayInteractionCount .FavouritesCount}} </span>
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
<a class="status-time" href="/thread/{{.ID}}">
|
<a class="status-time" href="/thread/{{.ID}}#status-{{.ID}}">
|
||||||
<time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{.CreatedAt}}"> {{TimeSince .CreatedAt}} </time>
|
<time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{.CreatedAt}}"> {{TimeSince .CreatedAt}} </time>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue