diff options
Diffstat (limited to 'service')
-rw-r--r-- | service/service.go | 56 | ||||
-rw-r--r-- | service/transport.go | 17 |
2 files changed, 71 insertions, 2 deletions
diff --git a/service/service.go b/service/service.go index d548342..03f0ff3 100644 --- a/service/service.go +++ b/service/service.go @@ -321,6 +321,62 @@ func (s *service) ThreadPage(c *client, id string, reply bool) (err error) { return s.renderer.Render(c.rctx, c.w, renderer.ThreadPage, data) } +func (s *service) QuickReplyPage(c *client, id string) (err error) { + status, err := c.GetStatus(c.ctx, id) + if err != nil { + return + } + + var ancestor *mastodon.Status + if status.InReplyToID != nil { + ancestor, err = c.GetStatus(c.ctx, status.InReplyToID.(string)) + if err != nil { + return + } + } + + var content string + if c.s.UserID != status.Account.ID { + content += "@" + status.Account.Acct + " " + } + for i := range status.Mentions { + if status.Mentions[i].ID != c.s.UserID && + status.Mentions[i].ID != status.Account.ID { + content += "@" + status.Mentions[i].Acct + " " + } + } + + var visibility string + isDirect := status.Visibility == "direct" + if isDirect || c.s.Settings.CopyScope { + visibility = status.Visibility + } else { + visibility = c.s.Settings.DefaultVisibility + } + + pctx := model.PostContext{ + DefaultVisibility: visibility, + DefaultFormat: c.s.Settings.DefaultFormat, + Formats: s.postFormats, + ReplyContext: &model.ReplyContext{ + InReplyToID: id, + InReplyToName: status.Account.Acct, + QuickReply: true, + ReplyContent: content, + ForceVisibility: isDirect, + }, + } + + cdata := s.cdata(c, "post by "+status.Account.DisplayName, 0, 0, "") + data := &renderer.QuickReplyData{ + Ancestor: ancestor, + Status: status, + PostContext: pctx, + CommonData: cdata, + } + return s.renderer.Render(c.rctx, c.w, renderer.QuickReplyPage, data) +} + func (s *service) LikedByPage(c *client, id string) (err error) { likers, err := c.GetFavouritedBy(c.ctx, id, nil) if err != nil { diff --git a/service/transport.go b/service/transport.go index f448cc3..42b371a 100644 --- a/service/transport.go +++ b/service/transport.go @@ -177,6 +177,11 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return s.ThreadPage(c, id, len(reply) > 1) }, SESSION, HTML) + quickReplyPage := handle(func(c *client) error { + id, _ := mux.Vars(c.r)["id"] + return s.QuickReplyPage(c, id) + }, SESSION, HTML) + likedByPage := handle(func(c *client) error { id, _ := mux.Vars(c.r)["id"] return s.LikedByPage(c, id) @@ -263,6 +268,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { format := c.r.FormValue("format") visibility := c.r.FormValue("visibility") isNSFW := c.r.FormValue("is_nsfw") == "true" + quickReply := c.r.FormValue("quickreply") == "true" files := c.r.MultipartForm.File["attachments"] id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, files) @@ -270,9 +276,15 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return err } - location := c.r.FormValue("referrer") + var location string if len(replyToID) > 0 { - location = "/thread/" + replyToID + "#status-" + id + if quickReply { + location = "/quickreply/" + id + "#status-" + id + } else { + location = "/thread/" + replyToID + "#status-" + id + } + } else { + location = c.r.FormValue("referrer") } redirect(c, location) return nil @@ -626,6 +638,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { r.HandleFunc("/timeline/{type}", timelinePage).Methods(http.MethodGet) r.HandleFunc("/timeline", defaultTimelinePage).Methods(http.MethodGet) r.HandleFunc("/thread/{id}", threadPage).Methods(http.MethodGet) + r.HandleFunc("/quickreply/{id}", quickReplyPage).Methods(http.MethodGet) r.HandleFunc("/likedby/{id}", likedByPage).Methods(http.MethodGet) r.HandleFunc("/retweetedby/{id}", retweetedByPage).Methods(http.MethodGet) r.HandleFunc("/notifications", notificationsPage).Methods(http.MethodGet) |