Focus relevant status on like, retweet and reply
authorr <r@freesoftwareextremist.com>
Sat, 14 Dec 2019 18:12:48 +0000 (18:12 +0000)
committerr <r@freesoftwareextremist.com>
Sat, 14 Dec 2019 18:12:48 +0000 (18:12 +0000)
service/auth.go
service/logging.go
service/service.go
service/transport.go
templates/status.tmpl

index cb442a7f5e5278c9415b2e2caef951add78ddfe0..5ee2001fdeb3c43bf7c5388d4c544015ac6a56ce 100644 (file)
@@ -142,7 +142,7 @@ func (s *authService) UnRetweet(ctx context.Context, client io.Writer, c *mastod
        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)
        if err != nil {
                return
index b11599ef52c5ca124d51668dd4372b3d4627abf3..0ed40bdc135ead3bfbe89050586ce4bffeff0e7a 100644 (file)
@@ -108,7 +108,7 @@ func (s *loggingService) UnRetweet(ctx context.Context, client io.Writer, c *mas
        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) {
                s.logger.Printf("method=%v, content=%v, reply_to_id=%v, took=%v, err=%v\n",
                        "PostTweet", content, replyToID, time.Since(begin), err)
index b10a5de31b6b70400831200f82c6cd9d00af8877..3bfb163a9f95ff39736d263a07770e1b068137d5 100644 (file)
@@ -36,7 +36,7 @@ type Service interface {
        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)
        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 {
@@ -292,11 +292,16 @@ func (svc *service) UnRetweet(ctx context.Context, client io.Writer, c *mastodon
        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{
                Status:      content,
                InReplyToID: replyToID,
        }
-       _, err = c.PostStatus(ctx, tweet)
-       return
+
+       s, err := c.PostStatus(ctx, tweet)
+       if err != nil {
+               return
+       }
+
+       return s.ID, nil
 }
index 709a2ff2b61f58e837ac1ac5454b08f502b39417..00f7430daf2ddb67ca12eb370143502f0a341811 100644 (file)
@@ -108,7 +108,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                        return
                }
 
-               w.Header().Add("Location", req.Header.Get("Referer"))
+               w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
                w.WriteHeader(http.StatusSeeOther)
        }).Methods(http.MethodGet)
 
@@ -121,7 +121,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                        return
                }
 
-               w.Header().Add("Location", req.Header.Get("Referer"))
+               w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
                w.WriteHeader(http.StatusSeeOther)
        }).Methods(http.MethodGet)
 
@@ -134,7 +134,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                        return
                }
 
-               w.Header().Add("Location", req.Header.Get("Referer"))
+               w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
                w.WriteHeader(http.StatusSeeOther)
        }).Methods(http.MethodGet)
 
@@ -147,7 +147,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
                        return
                }
 
-               w.Header().Add("Location", req.Header.Get("Referer"))
+               w.Header().Add("Location", req.Header.Get("Referer")+"#status-"+id)
                w.WriteHeader(http.StatusSeeOther)
        }).Methods(http.MethodGet)
 
@@ -155,15 +155,15 @@ func NewHandler(s Service, staticDir string) http.Handler {
                ctx := getContextWithSession(context.Background(), req)
                content := req.FormValue("content")
                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 {
                        s.ServeErrorPage(ctx, w, err)
                        return
                }
 
-               location := "/timeline"
+               location := "/timeline" + "#status-" + id
                if len(replyToID) > 0 {
-                       location = "/thread/" + replyToID
+                       location = "/thread/" + replyToID + "#status-" + id
                }
                w.Header().Add("Location", location)
                w.WriteHeader(http.StatusSeeOther)
index 3953f2391cba3cba825d7520b6d3408b584be250..24f9a540d23a3c1015f7ca40ca7fd54f308f505b 100644 (file)
@@ -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}}
        <div class="retweet-info">
                <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="profile-avatar" />
@@ -67,7 +67,7 @@
                                        <span> {{DisplayInteractionCount .FavouritesCount}} </span>
                                </a>
                                {{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> 
                                </a>
                        </div>