aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2022-06-04 11:55:19 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit60752f58ab0eade30e88c1e98ad530a4b151586e (patch)
tree421b06b577250ff13f40bf05773332beea857523
parent89795236377c1db1821c7ccbbc48a94562a70995 (diff)
redirect to OP thread if not OP
-rw-r--r--activitypub/object.go12
-rw-r--r--route/routes/actor.go6
-rw-r--r--route/util.go13
-rw-r--r--views/manage.html2
4 files changed, 32 insertions, 1 deletions
diff --git a/activitypub/object.go b/activitypub/object.go
index f2241b7..4682832 100644
--- a/activitypub/object.go
+++ b/activitypub/object.go
@@ -54,6 +54,18 @@ func (obj ObjectBase) CheckIfOP() (bool, error) {
return true, nil
}
+func (obj ObjectBase) GetOP() (string, error) {
+ var id string
+
+ query := `select id from replies where inreplyto='' and id in (select inreplyto from replies where id=$1)`
+
+ if err := config.DB.QueryRow(query, obj.Id).Scan(&id); err != nil {
+ return obj.Id, nil
+ }
+
+ return id, nil
+}
+
func (obj ObjectBase) CreatePreview() *NestedObjectBase {
var nPreview NestedObjectBase
diff --git a/route/routes/actor.go b/route/routes/actor.go
index e1372ee..fc9795a 100644
--- a/route/routes/actor.go
+++ b/route/routes/actor.go
@@ -398,6 +398,12 @@ func ActorPostGet(ctx *fiber.Ctx) error {
inReplyTo := actor.Id + "/" + postId
+ // check if actually OP if not redirect to op to get full thread
+ var obj = activitypub.ObjectBase{Id: inReplyTo}
+ if OP, _ := obj.GetOP(); OP != obj.Id {
+ return ctx.Redirect(config.Domain+"/"+actor.Name+"/"+util.ShortURL(actor.Outbox, OP)+"#"+util.ShortURL(actor.Outbox, inReplyTo), http.StatusMovedPermanently)
+ }
+
var data route.PageData
re = regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+")
diff --git a/route/util.go b/route/util.go
index 838961e..9a2de75 100644
--- a/route/util.go
+++ b/route/util.go
@@ -373,4 +373,17 @@ func TemplateFunctions(engine *html.Engine) {
return returnString
})
+
+ engine.AddFunc("parseLink", func(board activitypub.Actor, link string) string {
+ var obj = activitypub.ObjectBase{
+ Id: link,
+ }
+
+ var OP string
+ if OP, _ = obj.GetOP(); OP == obj.Id {
+ return board.Name + "/" + util.ShortURL(board.Outbox, obj.Id)
+ }
+
+ return board.Name + "/" + util.ShortURL(board.Outbox, OP) + "#" + util.ShortURL(board.Outbox, link)
+ })
}
diff --git a/views/manage.html b/views/manage.html
index 356e09a..da59340 100644
--- a/views/manage.html
+++ b/views/manage.html
@@ -46,7 +46,7 @@
{{ $domain := .page.Domain }}
{{ range .page.Reported }}
<li>
- <a id="rpost" post="{{ .ID }}" href="{{ $board.Actor.Id }}/{{ shortURL $board.Actor.Outbox .ID }}">{{ shortURL $board.Actor.Outbox .ID }}</a> - <b>{{ .Count }}</b> [<a href="/delete?id={{ .ID }}&board={{ $board.Name }}&manage=t">Remove Post</a>] [<a href="/deleteattach?id={{ .ID }}&board={{ $board.Name }}&manage=t">Remove Attachment</a>] [<a href="/report?id={{ .ID }}&close=1&board={{ $board.Name }}">Close</a>]
+ <a id="rpost" post="{{ .ID }}" href="/{{ parseLink $board.Actor .ID }}">{{ shortURL $board.Actor.Outbox .ID }}</a> - <b>{{ .Count }}</b> [<a href="/delete?id={{ .ID }}&board={{ $board.Name }}&manage=t">Remove Post</a>] [<a href="/deleteattach?id={{ .ID }}&board={{ $board.Name }}&manage=t">Remove Attachment</a>] [<a href="/report?id={{ .ID }}&close=1&board={{ $board.Name }}">Close</a>]
<ul>
{{ range .Reason }}
<li>