aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2022-06-04 15:12:24 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit0b97866be3a15f64170673af9813b39cbc585db5 (patch)
tree0949491e1ccccb9d3861db2553c72a4794591903
parent60752f58ab0eade30e88c1e98ad530a4b151586e (diff)
archive page works
-rw-r--r--activitypub/object.go4
-rw-r--r--main.go3
-rw-r--r--route/routes/actor.go67
-rw-r--r--route/structs.go1
-rw-r--r--route/util.go10
-rw-r--r--views/archive.html60
-rw-r--r--views/catalog.html2
-rw-r--r--views/npost.html4
-rw-r--r--views/nposts.html4
-rw-r--r--views/partials/post_nav.html12
-rw-r--r--views/partials/top.html4
11 files changed, 119 insertions, 52 deletions
diff --git a/activitypub/object.go b/activitypub/object.go
index 4682832..891cb23 100644
--- a/activitypub/object.go
+++ b/activitypub/object.go
@@ -425,7 +425,7 @@ func (obj ObjectBase) GetCollectionFromPath() (Collection, error) {
var err error
- query := `select x.id, x.name, x.content, x.type, x.published, x.updated, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where id like $1 and type='Note' union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where id like $1 and type='Note') as x order by x.updated`
+ query := `select x.id, x.name, x.content, x.type, x.published, x.updated, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where id like $1 and (type='Note' or type='Archive') union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where id like $1 and (type='Note' or type='Archive')) as x order by x.updated`
if err = config.DB.QueryRow(query, obj.Id).Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.Updated, &post.AttributedTo, &post.Attachment[0].Id, &post.Preview.Id, &actor.Id, &post.TripCode, &post.Sensitive); err != nil {
return nColl, util.MakeError(err, "GetCollectionFromPath")
}
@@ -663,7 +663,7 @@ func (obj ObjectBase) GetRepliesReplies() (CollectionBase, int, int, error) {
var err error
var rows *sql.Rows
- query := `select count(x.id) over(), sum(case when RTRIM(x.attachment) = '' then 0 else 1 end) over(), x.id, x.name, x.content, x.type, x.published, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select * from activitystream where id in (select id from replies where inreplyto=$1) and type='Note' union select * from cacheactivitystream where id in (select id from replies where inreplyto=$1) and type='Note') as x order by x.published asc`
+ query := `select count(x.id) over(), sum(case when RTRIM(x.attachment) = '' then 0 else 1 end) over(), x.id, x.name, x.content, x.type, x.published, x.attributedto, x.attachment, x.preview, x.actor, x.tripcode, x.sensitive from (select * from activitystream where id in (select id from replies where inreplyto=$1) and (type='Note' or type='Archive') union select * from cacheactivitystream where id in (select id from replies where inreplyto=$1) and (type='Note' or type='Archive')) as x order by x.published asc`
if rows, err = config.DB.Query(query, obj.Id); err != nil {
return nColl, postCount, attachCount, util.MakeError(err, "GetRepliesReplies")
}
diff --git a/main.go b/main.go
index 66ecb6c..7e25243 100644
--- a/main.go
+++ b/main.go
@@ -89,12 +89,11 @@ func main() {
app.Get("/api/media", routes.Media)
// Board actor routes
- app.Get("/:actor/catalog", routes.ActorCatalogGet)
+ app.Get("/:actor/catalog", routes.ActorCatalog)
app.Post("/:actor/inbox", routes.ActorInbox)
app.All("/:actor/outbox", routes.ActorOutbox)
app.Get("/:actor/following", routes.ActorFollowing)
app.All("/:actor/followers", routes.ActorFollowers)
- app.Get("/:actor/reported", routes.ActorReported)
app.Get("/:actor/archive", routes.ActorArchive)
app.Get("/:actor", routes.ActorOutboxGet)
app.Post("/:actor", routes.ActorPost)
diff --git a/route/routes/actor.go b/route/routes/actor.go
index fc9795a..a7711d3 100644
--- a/route/routes/actor.go
+++ b/route/routes/actor.go
@@ -213,18 +213,6 @@ func ActorFollowers(ctx *fiber.Ctx) error {
return actor.GetFollowersResp(ctx)
}
-func ActorReported(c *fiber.Ctx) error {
- // STUB
-
- return c.SendString("actor reported")
-}
-
-func ActorArchive(c *fiber.Ctx) error {
- // STUB
-
- return c.SendString("actor archive")
-}
-
func ActorPost(ctx *fiber.Ctx) error {
header, _ := ctx.FormFile("file")
@@ -450,10 +438,6 @@ func ActorPostGet(ctx *fiber.Ctx) error {
}
}
- if len(data.Posts) > 0 {
- data.PostId = util.ShortURL(data.Board.To, data.Posts[0].Id)
- }
-
data.Board.Name = actor.Name
data.Board.PrefName = actor.PreferredUsername
data.Board.To = actor.Outbox
@@ -463,6 +447,11 @@ func ActorPostGet(ctx *fiber.Ctx) error {
data.Board.Domain = config.Domain
data.Board.Restricted = actor.Restricted
data.ReturnTo = "feed"
+ data.PostType = "reply"
+
+ if len(data.Posts) > 0 {
+ data.PostId = util.ShortURL(data.Board.To, data.Posts[0].Id)
+ }
capt, err := util.GetRandomCaptcha()
if err != nil {
@@ -496,28 +485,19 @@ func ActorPostGet(ctx *fiber.Ctx) error {
}, "layouts/main")
}
-func ActorCatalogGet(ctx *fiber.Ctx) error {
+func ActorCatalog(ctx *fiber.Ctx) error {
actorName := ctx.Params("actor")
actor, err := activitypub.GetActorByNameFromDB(actorName)
+
if err != nil {
- return util.MakeError(err, "CatalogGet")
+ return util.MakeError(err, "ActorCatalog")
}
collection, err := actor.GetCatalogCollection()
- // TODO: implement this in template functions
- // "showArchive": func() bool {
- // col, err := db.GetActorCollectionDBTypeLimit(collection.Actor.Id, "Archive", 1)
- // if err != nil {
- // // TODO: figure out what to do here
- // panic(err)
- // }
- //
- // if len(col.OrderedItems) > 0 {
- // return true
- // }
- // return false
- //},
+ if err != nil {
+ return util.MakeError(err, "ActorCatalog")
+ }
var data route.PageData
data.Board.Name = actor.Name
@@ -531,6 +511,7 @@ func ActorCatalogGet(ctx *fiber.Ctx) error {
data.Board.Restricted = actor.Restricted
data.Key = config.Key
data.ReturnTo = "catalog"
+ data.PostType = "new"
data.Board.Post.Actor = actor.Id
@@ -612,6 +593,7 @@ func ActorOutboxGet(ctx *fiber.Ctx) error {
data.Board.Restricted = actor.Restricted
data.CurrentPage = page
data.ReturnTo = "feed"
+ data.PostType = "new"
data.Board.Post.Actor = actor.Id
@@ -644,9 +626,19 @@ func ActorOutboxGet(ctx *fiber.Ctx) error {
}, "layouts/main")
}
-func ActorArchiveGet(ctx *fiber.Ctx) error {
- collection := ctx.Locals("collection").(activitypub.Collection)
- actor := collection.Actor
+func ActorArchive(ctx *fiber.Ctx) error {
+ actorName := ctx.Params("actor")
+ actor, err := activitypub.GetActorByNameFromDB(actorName)
+
+ if err != nil {
+ return util.MakeError(err, "ActorArchive")
+ }
+
+ collection, err := actor.GetCollectionType("Archive")
+
+ if err != nil {
+ return util.MakeError(err, "ActorArchive")
+ }
var returnData route.PageData
returnData.Board.Name = actor.Name
@@ -663,12 +655,11 @@ func ActorArchiveGet(ctx *fiber.Ctx) error {
returnData.Board.Post.Actor = actor.Id
- var err error
returnData.Instance, err = activitypub.GetActorFromDB(config.Domain)
capt, err := util.GetRandomCaptcha()
if err != nil {
- return util.MakeError(err, "ArchiveGet")
+ return util.MakeError(err, "ActorArchive")
}
returnData.Board.Captcha = config.Domain + "/" + capt
returnData.Board.CaptchaCode = post.GetCaptchaCode(returnData.Board.Captcha)
@@ -679,6 +670,10 @@ func ActorArchiveGet(ctx *fiber.Ctx) error {
returnData.Posts = collection.OrderedItems
+ returnData.Meta.Description = returnData.Board.Summary
+ returnData.Meta.Url = returnData.Board.Actor.Id
+ returnData.Meta.Title = returnData.Title
+
returnData.Themes = &config.Themes
returnData.ThemeCookie = route.GetThemeCookie(ctx)
diff --git a/route/structs.go b/route/structs.go
index fbfb327..73371ae 100644
--- a/route/structs.go
+++ b/route/structs.go
@@ -24,6 +24,7 @@ type PageData struct {
NewsItems []db.NewsItem
BoardRemainer []int
Meta Meta
+ PostType string
Themes *[]string
ThemeCookie string
diff --git a/route/util.go b/route/util.go
index 9a2de75..defa60e 100644
--- a/route/util.go
+++ b/route/util.go
@@ -386,4 +386,14 @@ func TemplateFunctions(engine *html.Engine) {
return board.Name + "/" + util.ShortURL(board.Outbox, OP) + "#" + util.ShortURL(board.Outbox, link)
})
+
+ engine.AddFunc("showArchive", func(actor activitypub.Actor) bool {
+ col, err := actor.GetCollectionTypeLimit("Archive", 1)
+
+ if err != nil || len(col.OrderedItems) == 0 {
+ return false
+ }
+
+ return true
+ })
}
diff --git a/views/archive.html b/views/archive.html
new file mode 100644
index 0000000..a5184a4
--- /dev/null
+++ b/views/archive.html
@@ -0,0 +1,60 @@
+{{ template "partials/top" .page }}
+
+{{ $board := .page.Board }}
+
+<hr>
+<ul id="navlinks">
+ <li>[<a href="/{{ $board.Name }}">Return</a>]</li>
+ {{ template "partials/post_nav" .page }}
+ <li>[<a href="#bottom" id="top">Bottom</a>]</li>
+</ul>
+<hr>
+
+{{ if .page.Posts }}
+<table align="center" style="table-layout:fixed; width:90%;">
+ <tr>
+ {{ if eq $board.ModCred $board.Domain $board.Actor.Id }}
+ <th style="width: 45px;"></th>
+ {{ end }}
+ <th style="width: 110px">No.</th>
+ <th>Excerpt</th>
+ <th style="width: 60px;"></th>
+ </tr>
+ {{ range $i, $e := .page.Posts }}
+ {{ if mod $i 2 }}
+ <tr class="box-alt">
+ {{ if eq $board.ModCred $board.Domain $board.Actor.Id }}
+ <td>[<a href="/poparchive?id={{ $e.Id }}&board={{ $board.Name }}">Pop</a>]</td>
+ {{ end }}
+ <td>{{ shortURL $board.Actor.Outbox $e.Id }}</td>
+ <td style="overflow: hidden; word-wrap: break-word; text-overflow: ellipsis;">{{ shortExcerpt $e }}</td>
+ <td style="text-align: center;">[<a href="/{{ $board.Actor.Name }}/{{ shortURL $board.Actor.Outbox $e.Id }}">View</a>]</td>
+ </tr>
+ {{ else }}
+ <tr class="box">
+ {{ if eq $board.ModCred $board.Domain $board.Actor.Id }}
+ <td>[<a href="/poparchive?id={{ $e.Id }}">Pop</a>]</td>
+ {{ end }}
+ <td>{{ shortURL $board.Actor.Outbox $e.Id }}</td>
+ <td style="overflow: hidden; word-wrap: break-word; text-overflow: ellipsis;">{{ shortExcerpt $e }}</td>
+ <td style="text-align: center;">[<a href="/{{ $board.Actor.Name }}/{{ shortURL $board.Actor.Outbox $e.Id }}">View</a>]</td>
+ </tr>
+ {{ end }}
+ {{ end }}
+</table>
+{{ end }}
+
+<hr>
+
+<ul id="navlinks">
+ <li>[<a href="/{{ $board.Name }}">Return</a>]</li>
+ {{ template "partials/post_nav" .page }}
+ <li>[<a href="#top" id="bottom">Top</a>]</li>
+</ul>
+
+<hr>
+
+{{ template "partials/bottom" .page }}
+{{ template "partials/footer" .page }}
+{{ template "partials/general_scripts" .page }}
+{{ template "partials/post_scripts" .page }}
diff --git a/views/catalog.html b/views/catalog.html
index d4ec009..6a99d8f 100644
--- a/views/catalog.html
+++ b/views/catalog.html
@@ -6,6 +6,7 @@
<ul id="navlinks">
<li>[<a href="/{{ .page.Board.Name }}">Return</a>]</li>
{{ template "partials/post_nav" .page }}
+ <li>[<a href="#bottom" id="top">Bottom</a>]</li>
</ul>
<hr>
@@ -81,6 +82,7 @@
<ul id="navlinks">
<li>[<a href="/{{ .page.Board.Name }}">Return</a>]</li>
{{ template "partials/post_nav" .page }}
+ <li>[<a href="#top" id="bottom">Top</a>]</li>
</ul>
<hr>
diff --git a/views/npost.html b/views/npost.html
index 07de021..7c22b9b 100644
--- a/views/npost.html
+++ b/views/npost.html
@@ -4,8 +4,8 @@
<ul id="navlinks">
<li>[<a href="/{{ .page.Board.Name }}">Return</a>]</li>
- <li>[<a href="/{{ .page.Board.Name }}/catalog">Catalog</a>]</li>
{{ template "partials/post_nav" .page }}
+ <li>[<a href="#bottom" id="top">Bottom</a>]</li>
</ul>
<hr>
@@ -19,8 +19,8 @@
<td>
<ul id="navlinks">
<li>[<a href="/{{ .page.Board.Name }}">Return</a>]</li>
- <li>[<a href="/{{ .page.Board.Name }}/catalog">Catalog</a>]</li>
{{ template "partials/post_nav" .page }}
+ <li>[<a href="#top" id="bottom">Top</a>]</li>
<li><input id="autoreload-checkbox" type="checkbox" onclick="autoTimer()"> Auto refresh <span id="autoreload-countdown" style="visibility: hidden;">0</span></li>
</ul>
</td>
diff --git a/views/nposts.html b/views/nposts.html
index 567b945..9ce120b 100644
--- a/views/nposts.html
+++ b/views/nposts.html
@@ -4,8 +4,8 @@
<hr>
<ul id="navlinks">
- <li>[<a href="/{{ .page.Board.Name }}/catalog">Catalog</a>]</li>
{{ template "partials/post_nav" .page }}
+ <li>[<a href="#bottom" id="top">Bottom</a>]</li>
</ul>
{{ template "partials/posts" .page }}
@@ -14,8 +14,8 @@
<ul id="navlinks">
- <li>[<a href="/{{ .page.Board.Name }}/catalog">Catalog</a>]</li>
{{ template "partials/post_nav" .page }}
+ <li>[<a href="#top" id="bottom">Top</a>]</li>
</ul>
<hr>
diff --git a/views/partials/post_nav.html b/views/partials/post_nav.html
index eab52d1..d999c35 100644
--- a/views/partials/post_nav.html
+++ b/views/partials/post_nav.html
@@ -1,7 +1,7 @@
-<!-- TODO: showArchive function needs to be fixed
- \{\{ if showArchive }}
- <li>[<a href="/{{ .Board.Name }}/archive">Archive</a>]</li>
- \{\{ end }}
- -->
-<li>[<a href="#top" id="bottom">Top</a>]</li>
+{{ if ne .ReturnTo "catalog" }}
+<li>[<a href="/{{ .Board.Name }}/catalog">Catalog</a>]</li>
+{{ end }}
+{{ if and (ne .ReturnTo "archive") (showArchive .Board.Actor) }}
+<li>[<a href="/{{ .Board.Name }}/archive">Archive</a>]</li>
+{{ end }}
<li>[<a href="javascript:location.reload()">Refresh</a>]</li>
diff --git a/views/partials/top.html b/views/partials/top.html
index 6e3bc4b..dddb206 100644
--- a/views/partials/top.html
+++ b/views/partials/top.html
@@ -3,9 +3,9 @@
<p style="text-align: center;">{{ .Board.Summary }}</p>
{{ $len := len .Posts }}
{{ if eq $len 0 }}
- {{ if .Board.InReplyTo }}
+ {{ if eq .PostType "reply" }}
<h3 id="newpostbtn" state="0" style="display: none; margin-bottom:100px;">[<a href="javascript:startNewPost()">Post a Reply</a>]</h3>
- {{ else }}
+ {{ else if eq .PostType "new" }}
<h3 id="newpostbtn" state="0" style="display: none; margin-bottom:100px;">[<a href="javascript:startNewPost()">Start a New Thread</a>]</h3>
{{ end }} <!-- end if inreplyto-->
<div id="newpost">