Allow to edit comments (#42)

pull/47/head
Jan-Lukas Else 2 months ago
parent 8098e77470
commit bef19c61fb

@ -1,3 +1,4 @@
# GoBlog
How to install and run (and other useful information about) GoBlog is explained in the [docs](https://docs.goblog.app/).

@ -27,29 +27,23 @@ type comment struct {
func (a *goBlog) serveComment(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(chi.URLParam(r, "id"))
if err != nil {
a.serveError(w, r, err.Error(), http.StatusBadRequest)
a.serveError(w, r, "id missing or wrong format", http.StatusBadRequest)
return
}
row, err := a.db.QueryRow("select id, target, name, website, comment, original from comments where id = @id", sql.Named("id", id))
comments, err := a.db.getComments(&commentsRequestConfig{id: id})
if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
a.serveError(w, r, "failed to query comments from database", http.StatusInternalServerError)
return
}
comment := &comment{}
if err = row.Scan(&comment.ID, &comment.Target, &comment.Name, &comment.Website, &comment.Comment, &comment.Original); err == sql.ErrNoRows {
if len(comments) < 1 {
a.serve404(w, r)
return
} else if err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
}
comment := comments[0]
_, bc := a.getBlog(r)
canonical := a.getFullAddress(bc.getRelativePath(path.Join(commentPath, strconv.Itoa(id))))
if comment.Original != "" {
canonical = comment.Original
}
a.render(w, r, a.renderComment, &renderData{
Canonical: canonical,
Canonical: defaultIfEmpty(comment.Original, canonical),
Data: comment,
})
}
@ -114,11 +108,7 @@ func (a *goBlog) createComment(bc *configBlog, target, comment, name, website, o
return commentAddress, 0, nil
}
} else {
_, err := a.db.Exec(
"update comments set target = @target, comment = @comment, name = @name, website = @website where id = @id",
sql.Named("target", target), sql.Named("comment", comment), sql.Named("name", name), sql.Named("website", website), sql.Named("id", updateId),
)
if err != nil {
if err := a.db.updateComment(updateId, comment, name, website); err != nil {
return "", http.StatusInternalServerError, errors.New("failed to update comment in database")
}
commentAddress := bc.getRelativePath(path.Join(commentPath, strconv.Itoa(updateId)))
@ -143,13 +133,18 @@ func (a *goBlog) checkCommentTarget(target string) (string, int, error) {
}
type commentsRequestConfig struct {
offset, limit int
id, offset, limit int
}
func buildCommentsQuery(config *commentsRequestConfig) (query string, args []any) {
queryBuilder := bufferpool.Get()
defer bufferpool.Put(queryBuilder)
queryBuilder.WriteString("select id, target, name, website, comment, original from comments order by id desc")
queryBuilder.WriteString("select id, target, name, website, comment, original from comments")
if config.id != 0 {
queryBuilder.WriteString(" where id = @id")
args = append(args, sql.Named("id", config.id))
}
queryBuilder.WriteString(" order by id desc")
if config.limit != 0 || config.offset != 0 {
queryBuilder.WriteString(" limit @limit offset @offset")
args = append(args, sql.Named("limit", config.limit), sql.Named("offset", config.offset))
@ -158,7 +153,7 @@ func buildCommentsQuery(config *commentsRequestConfig) (query string, args []any
}
func (db *database) getComments(config *commentsRequestConfig) ([]*comment, error) {
comments := []*comment{}
var comments []*comment
query, args := buildCommentsQuery(config)
rows, err := db.Query(query, args...)
if err != nil {
@ -186,6 +181,14 @@ func (db *database) countComments(config *commentsRequestConfig) (count int, err
return
}
func (db *database) updateComment(id int, comment, name, website string) error {
_, err := db.Exec(
"update comments set comment = @comment, name = @name, website = @website where id = @id",
sql.Named("comment", comment), sql.Named("name", name), sql.Named("website", website), sql.Named("id", id),
)
return err
}
func (db *database) deleteComment(id int) error {
_, err := db.Exec("delete from comments where id = @id", sql.Named("id", id))
return err

@ -0,0 +1,48 @@
package main
import (
"net/http"
"path"
"strconv"
)
const commentEditSubPath = "/edit"
func (a *goBlog) serveCommentsEditor(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(r.FormValue("id"))
if err != nil {
a.serveError(w, r, "id missing or wrong format", http.StatusBadRequest)
return
}
comments, err := a.db.getComments(&commentsRequestConfig{id: id})
if err != nil {
a.serveError(w, r, "failed to query comments from database", http.StatusInternalServerError)
return
}
if len(comments) < 1 {
a.serve404(w, r)
return
}
comment := comments[0]
blog, bc := a.getBlog(r)
if r.Method == http.MethodPost {
name := r.FormValue("name")
website := r.FormValue("website")
commentText := r.FormValue("comment")
if err := a.db.updateComment(id, commentText, name, website); err != nil {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
}
a.cache.purge()
// Resend webmention
commentAddress := bc.getRelativePath(path.Join(commentPath, strconv.Itoa(id)))
_ = a.createWebmention(a.getFullAddress(commentAddress), a.getFullAddress(comment.Target))
// Redirect to comment
http.Redirect(w, r, commentAddress, http.StatusFound)
return
}
a.render(w, r, a.renderCommentEditor, &renderData{
Data: comment,
BlogString: blog,
})
}

@ -0,0 +1,70 @@
package main
import (
"context"
"net/http"
"strings"
"testing"
"github.com/carlmjohnson/requests"
"github.com/spf13/cast"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_commentsEditor(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
app.cfg.Server.PublicAddress = "https://example.com"
err := app.initConfig(false)
require.NoError(t, err)
err = app.initCache()
require.NoError(t, err)
app.initMarkdown()
app.initSessions()
bc := app.cfg.Blogs[app.cfg.DefaultBlog]
addr, _, err := app.createComment(bc, "https://example.com/abc", "Test", "Name", "https://example.org", "")
require.NoError(t, err)
splittedAddr := strings.Split(addr, "/")
id := cast.ToInt(splittedAddr[len(splittedAddr)-1])
comments, err := app.db.getComments(&commentsRequestConfig{id: id})
require.NoError(t, err)
require.Len(t, comments, 1)
comment := comments[0]
assert.Equal(t, "/abc", comment.Target)
assert.Equal(t, "Test", comment.Comment)
assert.Equal(t, "Name", comment.Name)
assert.Equal(t, "https://example.org", comment.Website)
handlerClient := newHandlerClient(http.HandlerFunc(app.serveCommentsEditor))
requests.URL("https://example.com/comment/edit").
Method(http.MethodPost).
ParamInt("id", id).
Param("name", "Edited name").
Param("comment", "Edited comment").
Param("website", "").
Client(handlerClient).
Fetch(context.Background())
comments, err = app.db.getComments(&commentsRequestConfig{id: id})
require.NoError(t, err)
require.Len(t, comments, 1)
comment = comments[0]
assert.Equal(t, "/abc", comment.Target)
assert.Equal(t, "Edited comment", comment.Comment)
assert.Equal(t, "Edited name", comment.Name)
assert.Equal(t, "", comment.Website)
}

@ -10,6 +10,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/spf13/cast"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.goblog.app/app/pkgs/contenttype"
@ -197,3 +198,53 @@ func Test_commentsEnabled(t *testing.T) {
}))
}
func Test_commentsUpdateByOriginal(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
app.cfg.Server.PublicAddress = "https://example.com"
err := app.initConfig(false)
require.NoError(t, err)
err = app.initCache()
require.NoError(t, err)
app.initMarkdown()
app.initSessions()
bc := app.cfg.Blogs[app.cfg.DefaultBlog]
addr, _, err := app.createComment(bc, "https://example.com/abc", "Test", "Name", "https://example.org", "https://example.org/1")
require.NoError(t, err)
splittedAddr := strings.Split(addr, "/")
id := cast.ToInt(splittedAddr[len(splittedAddr)-1])
comments, err := app.db.getComments(&commentsRequestConfig{id: id})
require.NoError(t, err)
require.Len(t, comments, 1)
comment := comments[0]
assert.Equal(t, "/abc", comment.Target)
assert.Equal(t, "Test", comment.Comment)
assert.Equal(t, "Name", comment.Name)
assert.Equal(t, "https://example.org", comment.Website)
assert.Equal(t, "https://example.org/1", comment.Original)
_, _, err = app.createComment(bc, "https://example.com/abc", "Edited comment", "Edited name", "", "https://example.org/1")
require.NoError(t, err)
comments, err = app.db.getComments(&commentsRequestConfig{id: id})
require.NoError(t, err)
require.Len(t, comments, 1)
comment = comments[0]
assert.Equal(t, "/abc", comment.Target)
assert.Equal(t, "Edited comment", comment.Comment)
assert.Equal(t, "Edited name", comment.Name)
assert.Equal(t, "", comment.Website)
}

@ -13,7 +13,7 @@ require (
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b
github.com/carlmjohnson/requests v0.22.3
// master
github.com/cretz/bine v0.2.1-0.20220825052916-cb1f9e88dfba
github.com/cretz/bine v0.2.1-0.20221201125941-b9d31d9c7866
github.com/dchest/captcha v1.0.0
github.com/dgraph-io/ristretto v0.1.1
github.com/disintegration/imaging v1.6.2
@ -21,7 +21,7 @@ require (
github.com/elnormous/contenttype v1.0.3
github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead
github.com/emersion/go-smtp v0.15.0
github.com/go-ap/activitypub v0.0.0-20221119120906-cb8207231e18
github.com/go-ap/activitypub v0.0.0-20221206062958-cae46e718d79
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73
github.com/go-chi/chi/v5 v5.0.7
github.com/go-fed/httpsig v1.1.0
@ -46,7 +46,7 @@ require (
github.com/paulmach/go.geojson v1.4.0
github.com/posener/wstest v1.2.0
github.com/pquerna/otp v1.3.0
github.com/samber/lo v1.35.0
github.com/samber/lo v1.36.0
github.com/schollz/sqlite3dump v1.3.1
github.com/snabb/sitemap v1.0.0
github.com/spf13/cast v1.5.0
@ -62,9 +62,9 @@ require (
// master
github.com/yuin/goldmark-emoji v1.0.2-0.20210607094911-0487583eca38
golang.org/x/crypto v0.3.0
golang.org/x/net v0.2.0
golang.org/x/net v0.3.0
golang.org/x/sync v0.1.0
golang.org/x/text v0.4.0
golang.org/x/text v0.5.0
gopkg.in/yaml.v3 v3.0.1
nhooyr.io/websocket v1.8.7
// main
@ -82,7 +82,7 @@ require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ap/errors v0.0.0-20221115052505-8aaa26f930b4 // indirect
github.com/go-ap/errors v0.0.0-20221205040414-01c1adfc98ea // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/css v1.0.0 // indirect
@ -112,7 +112,7 @@ require (
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/sys v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect

@ -81,8 +81,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cretz/bine v0.2.1-0.20220825052916-cb1f9e88dfba h1:80J3s+Gi3CDC6EoPlb9L6Pdddwi1ZqjlrZtbKl5vTtU=
github.com/cretz/bine v0.2.1-0.20220825052916-cb1f9e88dfba/go.mod h1:WU4o9QR9wWp8AVKtTM1XD5vUHkEqnf2vVSo6dBqbetI=
github.com/cretz/bine v0.2.1-0.20221201125941-b9d31d9c7866 h1:8Cji9JDEuYibvDQrWHvc42r9/HxjlD2kahN67LECXFk=
github.com/cretz/bine v0.2.1-0.20221201125941-b9d31d9c7866/go.mod h1:WU4o9QR9wWp8AVKtTM1XD5vUHkEqnf2vVSo6dBqbetI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -124,10 +124,10 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-ap/activitypub v0.0.0-20221119120906-cb8207231e18 h1:ViTJy/5JI0zKtpeju09rAM0HPTc0Xmnh+uYtxYZ+tfs=
github.com/go-ap/activitypub v0.0.0-20221119120906-cb8207231e18/go.mod h1:acWwxqPWwm9hmjSlva1N1na1J6eGeC9kKTS3YEBOVJI=
github.com/go-ap/errors v0.0.0-20221115052505-8aaa26f930b4 h1:oySiT87Q2cd0o5O8er2zyjiRcTQA0KuOgw1N9+RQqG0=
github.com/go-ap/errors v0.0.0-20221115052505-8aaa26f930b4/go.mod h1:SaTNjEEkp0q+w3pUS1ccyEL/lUrHteORlDq/e21mCc8=
github.com/go-ap/activitypub v0.0.0-20221206062958-cae46e718d79 h1:iZ2ITdeyrEpQL0nOIWpdje6qtk3cBBuylB5fI7TI3Rc=
github.com/go-ap/activitypub v0.0.0-20221206062958-cae46e718d79/go.mod h1:1oVD0h0aPT3OEE1ZoSUoym/UGKzxe+e0y8K2AkQ1Hqs=
github.com/go-ap/errors v0.0.0-20221205040414-01c1adfc98ea h1:ywGtLGVjJjMrq4mu35Qmu+NtlhlTk/gTayE6Bb4tQZk=
github.com/go-ap/errors v0.0.0-20221205040414-01c1adfc98ea/go.mod h1:SaTNjEEkp0q+w3pUS1ccyEL/lUrHteORlDq/e21mCc8=
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73 h1:GMKIYXyXPGIp+hYiWOhfqK4A023HdgisDT4YGgf99mw=
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
@ -338,8 +338,8 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.35.0 h1:GlT8CV1GE+v97Y7MLF1wXvX6mjoxZ+hi61tj/ZcQwY0=
github.com/samber/lo v1.35.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8=
github.com/samber/lo v1.36.0 h1:4LaOxH1mHnbDGhTVE0i1z8v/lWaQW8AIfOD3HU4mSaw=
github.com/samber/lo v1.36.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8=
github.com/schollz/sqlite3dump v1.3.1 h1:QXizJ7XEJ7hggjqjZ3YRtF3+javm8zKtzNByYtEkPRA=
github.com/schollz/sqlite3dump v1.3.1/go.mod h1:mzSTjZpJH4zAb1FN3iNlhWPbbdyeBpOaTW0hukyMHyI=
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
@ -494,8 +494,8 @@ golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211020060615-d418f374d309/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk=
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -558,10 +558,10 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@ -569,8 +569,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

@ -384,6 +384,8 @@ func (a *goBlog) blogCommentsRouter(conf *configBlog) func(r chi.Router) {
r.Get("/", a.commentsAdmin)
r.Get(paginationPath, a.commentsAdmin)
r.Post("/delete", a.commentsAdminDelete)
r.Get(commentEditSubPath, a.serveCommentsEditor)
r.Post("/edit", a.serveCommentsEditor)
})
})
}

@ -18,6 +18,8 @@ docomment: "Kommentieren"
download: "Herunterladen"
drafts: "Entwürfe"
draftsdesc: "Posts mit dem Status `draft`."
edit: "Bearbeiten"
editcommenttitle: "Kommentar bearbeiten"
editor: "Editor"
editorpostdesc: "💡 Leere Parameter werden automatisch entfernt. Mehr mögliche Parameter: %s. Mögliche Zustände für `%s` und `%s`: %s und %s."
editorusetemplate: "Benutze Vorlage"

@ -24,6 +24,8 @@ docomment: "Comment"
download: "Download"
drafts: "Drafts"
draftsdesc: "Posts with status `draft`."
edit: "Edit"
editcommenttitle: "Edit comment"
editor: "Editor"
editorpostdesc: "💡 Empty parameters are removed automatically. More possible parameters: %s. Possible states for `%s` and `%s`: %s and %s."
editorusetemplate: "Use template"

41
ui.go

@ -373,6 +373,14 @@ func (a *goBlog) renderComment(h *htmlbuilder.HtmlBuilder, rd *renderData) {
hb.WriteElementClose("p")
}
hb.WriteElementClose("main")
// Editor
if rd.LoggedIn() {
hb.WriteElementOpen("div", "class", "actions")
hb.WriteElementOpen("a", "class", "button", "href", rd.Blog.getRelativePath(fmt.Sprintf("%s%s?id=%d", commentPath, commentEditSubPath, c.ID)))
hb.WriteEscaped(a.ts.GetTemplateStringVariant(rd.Blog.Lang, "edit"))
hb.WriteElementClose("a")
hb.WriteElementClose("div")
}
// Interactions
if a.commentsEnabledForBlog(rd.Blog) {
a.renderInteractions(hb, rd)
@ -1673,3 +1681,36 @@ func (a *goBlog) renderActivityPubRemoteFollow(hb *htmlbuilder.HtmlBuilder, rd *
},
)
}
func (a *goBlog) renderCommentEditor(h *htmlbuilder.HtmlBuilder, rd *renderData) {
c, ok := rd.Data.(*comment)
if !ok {
return
}
a.renderBase(
h, rd,
func(hb *htmlbuilder.HtmlBuilder) {
a.renderTitleTag(hb, rd.Blog, a.ts.GetTemplateStringVariant(rd.Blog.Lang, "editcommenttitle"))
},
func(hb *htmlbuilder.HtmlBuilder) {
// Form
hb.WriteElementOpen("form", "class", "fw p", "method", "post")
hb.WriteElementOpen("input", "type", "hidden", "name", "id", "value", c.ID)
hb.WriteElementOpen("input", "type", "text", "disabled", "", "value", c.Target)
if c.Original != "" {
hb.WriteElementOpen("input", "type", "text", "disabled", "", "value", c.Original)
}
if c.Name != "" {
hb.WriteElementOpen("input", "type", "text", "name", "name", "placeholder", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "nameopt"), "value", c.Name)
}
if c.Website != "" {
hb.WriteElementOpen("input", "type", "url", "name", "website", "placeholder", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "websiteopt"), "value", c.Website)
}
hb.WriteElementOpen("textarea", "name", "comment", "required", "", "placeholder", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "comment"))
hb.WriteEscaped(c.Comment)
hb.WriteElementClose("textarea")
hb.WriteElementOpen("input", "type", "submit", "value", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "update"))
hb.WriteElementClose("form")
},
)
}

Loading…
Cancel
Save