aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2021-09-05 17:17:59 +0000
committerr <r@freesoftwareextremist.com>2021-09-05 17:33:58 +0000
commit54c42455f393c5ae8ebdb19884d40ebd9a18f755 (patch)
treedeecf729e7ba3565058dca6678e2b78805206097
parent4351155f67963b58feeba0d16bb998862ceb4d69 (diff)
downloadbloat-54c42455f393c5ae8ebdb19884d40ebd9a18f755.tar.gz
bloat-54c42455f393c5ae8ebdb19884d40ebd9a18f755.zip
Add quick reply
-rw-r--r--model/post.go1
-rw-r--r--renderer/model.go7
-rw-r--r--renderer/renderer.go1
-rw-r--r--service/service.go56
-rw-r--r--service/transport.go17
-rw-r--r--templates/postform.tmpl1
-rw-r--r--templates/quickreply.tmpl12
-rw-r--r--templates/status.tmpl3
8 files changed, 96 insertions, 2 deletions
diff --git a/model/post.go b/model/post.go
index 40118ed..ccb8286 100644
--- a/model/post.go
+++ b/model/post.go
@@ -15,6 +15,7 @@ type PostContext struct {
type ReplyContext struct {
InReplyToID string
InReplyToName string
+ QuickReply bool
ReplyContent string
ForceVisibility bool
}
diff --git a/renderer/model.go b/renderer/model.go
index 4d3eea0..385ac7c 100644
--- a/renderer/model.go
+++ b/renderer/model.go
@@ -69,6 +69,13 @@ type ThreadData struct {
ReplyMap map[string][]mastodon.ReplyInfo
}
+type QuickReplyData struct {
+ *CommonData
+ Ancestor *mastodon.Status
+ Status *mastodon.Status
+ PostContext model.PostContext
+}
+
type StatusData struct {
*CommonData
Status *mastodon.Status
diff --git a/renderer/renderer.go b/renderer/renderer.go
index 340b0fc..6c9877a 100644
--- a/renderer/renderer.go
+++ b/renderer/renderer.go
@@ -20,6 +20,7 @@ const (
RootPage = "root.tmpl"
TimelinePage = "timeline.tmpl"
ThreadPage = "thread.tmpl"
+ QuickReplyPage = "quickreply.tmpl"
StatusPopup = "status.tmpl"
NotificationPage = "notification.tmpl"
UserPage = "user.tmpl"
diff --git a/service/service.go b/service/service.go
index c098c76..a846322 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 (svc *service) StatusPopup(c *client, id string) (err error) {
status, err := c.GetStatus(c.ctx, id)
if err != nil {
diff --git a/service/transport.go b/service/transport.go
index da09557..a022b02 100644
--- a/service/transport.go
+++ b/service/transport.go
@@ -186,6 +186,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)
@@ -272,6 +277,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)
@@ -279,9 +285,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
@@ -640,6 +652,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)
diff --git a/templates/postform.tmpl b/templates/postform.tmpl
index 421b118..35171a4 100644
--- a/templates/postform.tmpl
+++ b/templates/postform.tmpl
@@ -4,6 +4,7 @@
<input type="hidden" name="referrer" value="{{$.Ctx.Referrer}}">
{{if .ReplyContext}}
<input type="hidden" name="reply_to_id" value="{{.ReplyContext.InReplyToID}}" />
+ <input type="hidden" name="quickreply" value="{{.ReplyContext.QuickReply}}" />
<label for="post-content" class="post-form-title"> Reply to {{.ReplyContext.InReplyToName}} </label>
{{else}}
<label for="post-content" class="post-form-title"> New post </label>
diff --git a/templates/quickreply.tmpl b/templates/quickreply.tmpl
new file mode 100644
index 0000000..97ff20a
--- /dev/null
+++ b/templates/quickreply.tmpl
@@ -0,0 +1,12 @@
+{{with $s := .Data}}
+{{template "header.tmpl" (WithContext .CommonData $.Ctx)}}
+<div class="page-title"> Quick Reply </div>
+
+{{if .Ancestor}}
+{{template "status.tmpl" (WithContext .Ancestor $.Ctx)}}
+{{end}}
+{{template "status.tmpl" (WithContext .Status $.Ctx)}}
+{{template "postform.tmpl" (WithContext $s.PostContext $.Ctx)}}
+
+{{template "footer.tmpl"}}
+{{end}}
diff --git a/templates/status.tmpl b/templates/status.tmpl
index 7ca8192..a7cc10d 100644
--- a/templates/status.tmpl
+++ b/templates/status.tmpl
@@ -35,6 +35,9 @@
<a class="more-link" href="{{.URL}}" target="_blank">
source
</a>
+ <a class="more-link" href="/quickreply/{{.ID}}#status-{{.ID}}">
+ quickreply
+ </a>
{{if .Muted}}
<form action="/unmuteconv/{{.ID}}" method="post" target="_self">
<input type="hidden" name="csrf_token" value="{{$.Ctx.CSRFToken}}">