aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.go20
-rw-r--r--database.go67
-rw-r--r--main.go26
-rw-r--r--static/archive.html9
-rw-r--r--static/ncatalog.html4
-rw-r--r--static/nposts.html4
6 files changed, 110 insertions, 20 deletions
diff --git a/client.go b/client.go
index c3e89cd..5ccdade 100644
--- a/client.go
+++ b/client.go
@@ -206,6 +206,14 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co
"isOnion": func(url string) bool {
return IsOnion(url)
},
+ "showArchive": func() bool {
+ col := GetActorCollectionDBTypeLimit(db, collection.Actor.Id, "Archive", 1)
+
+ if len(col.OrderedItems) > 0 {
+ return true
+ }
+ return false;
+ },
"parseReplyLink": func(actorId string, op string, id string, content string) template.HTML {
actor := FingerActor(actorId)
title := strings.ReplaceAll(ParseLinkTitle(actor.Id, op, content), `/\<`, ">")
@@ -282,6 +290,14 @@ func CatalogGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection C
"isOnion": func(url string) bool {
return IsOnion(url)
},
+ "showArchive": func() bool {
+ col := GetActorCollectionDBTypeLimit(db, collection.Actor.Id, "Archive", 1)
+
+ if len(col.OrderedItems) > 0 {
+ return true
+ }
+ return false;
+ },
"sub": func (i, j int) int { return i - j }}).ParseFiles("./static/main.html", "./static/ncatalog.html", "./static/top.html"))
actor := collection.Actor
@@ -1008,7 +1024,7 @@ func ShortExcerpt(post ObjectBase) string {
returnString = post.Content;
}
- re := regexp.MustCompile(`(^.{100})`)
+ re := regexp.MustCompile(`(^(.|\r\n|\n){100})`)
match := re.FindStringSubmatch(returnString)
@@ -1028,7 +1044,7 @@ func ShortExcerpt(post ObjectBase) string {
}
func IsOnion(url string) bool {
- re := regexp.MustCompile(`\.onion$`)
+ re := regexp.MustCompile(`\.onion`)
if(re.MatchString(url)) {
return true;
}
diff --git a/database.go b/database.go
index e3f4050..d0b6fcc 100644
--- a/database.go
+++ b/database.go
@@ -568,7 +568,7 @@ func GetObjectFromDB(db *sql.DB, id string) Collection {
var nColl Collection
var result []ObjectBase
- query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where id=$1 order by updated desc`
+ query := `select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where id=$1 union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where id=$1 order by updated desc`
rows, err := db.Query(query, id)
@@ -1914,6 +1914,47 @@ func GetActorCollectionDBType(db *sql.DB, actorId string, nType string) Collecti
return nColl
}
+func GetActorCollectionDBTypeLimit(db *sql.DB, actorId string, nType string, limit int) Collection {
+ var nColl Collection
+ var result []ObjectBase
+
+ 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 actor=$1 and id in (select id from replies where inreplyto='') and type=$2 union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from activitystream where actor in (select following from following where id=$1) and id in (select id from replies where inreplyto='') and type=$2 union select id, name, content, type, published, updated, attributedto, attachment, preview, actor, tripcode, sensitive from cacheactivitystream where actor in (select following from following where id=$1) and id in (select id from replies where inreplyto='') and type=$2) as x order by x.updated desc limit $3`
+
+ rows, err := db.Query(query, actorId, nType, limit)
+
+ CheckError(err, "error query object from db archive")
+
+ defer rows.Close()
+ for rows.Next(){
+ var post ObjectBase
+ var actor Actor
+ var attachID string
+ var previewID string
+
+ err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.Updated, &post.AttributedTo, &attachID, &previewID, &actor.Id, &post.TripCode, &post.Sensitive)
+
+ CheckError(err, "error scan object into post struct archive")
+
+ post.Actor = actor.Id
+
+ var replies CollectionBase
+
+ post.Replies = &replies
+
+ post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCount(db, post)
+
+ post.Attachment = GetObjectAttachment(db, attachID)
+
+ post.Preview = GetObjectPreview(db, previewID)
+
+ result = append(result, post)
+ }
+
+ nColl.OrderedItems = result
+
+ return nColl
+}
+
func UpdateObjectTypeDB(db *sql.DB, id string, nType string) {
query := `update activitystream set type=$2 where id=$1 and type !='Tombstone'`
@@ -1928,25 +1969,25 @@ func UpdateObjectTypeDB(db *sql.DB, id string, nType string) {
CheckError(err, "error updating cache reply type to archive")
}
-func UnArchiveLast(db *sql.DB) {
- query := `select id, updated from activitystream where type='Archive' union select id, updated from cacheactivitystream where type='Archive' order by updated desc limit 1`
-
- rows, err := db.Query(query)
-
- CheckError(err, "error with unarchive last")
+func UnArchiveLast(db *sql.DB, actorId string) {
+ col := GetActorCollectionDBTypeLimit(db, actorId, "Archive", 1)
- var id, updated string
- defer rows.Close()
- rows.Next()
- rows.Scan(&id, &updated)
+ for _, e := range col.OrderedItems {
+ for _, k := range e.Replies.OrderedItems {
+ UpdateObjectTypeDB(db, k.Id, "Note")
+ }
+ UpdateObjectTypeDB(db, e.Id, "Note")
+ }
+}
+func SetObjectType(db *sql.DB, id string, nType string) {
col := GetObjectFromDB(db, id)
for _, e := range col.OrderedItems {
for _, k := range e.Replies.OrderedItems {
- UpdateObjectTypeDB(db, k.Id, "Note")
+ UpdateObjectTypeDB(db, k.Id, nType)
}
- UpdateObjectTypeDB(db, e.Id, "Note")
+ UpdateObjectTypeDB(db, e.Id, nType)
}
}
diff --git a/main.go b/main.go
index d43fab0..76876f2 100644
--- a/main.go
+++ b/main.go
@@ -855,7 +855,7 @@ func main() {
go DeleteObjectRequest(db, id)
}
- UnArchiveLast(db)
+ UnArchiveLast(db, actor)
if !isOP {
if (!IsIDLocal(db, id)){
@@ -889,9 +889,9 @@ func main() {
manage := r.URL.Query().Get("manage")
col := GetCollectionFromID(id)
-
if len(col.OrderedItems) < 1 {
- if !HasAuth(db, auth, GetActorByNameFromDB(db, board).Id) {
+ actor := GetActorByNameFromDB(db, board)
+ if !HasAuth(db, auth, actor.Id) {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(""))
return
@@ -903,7 +903,7 @@ func main() {
TombstoneObjectAndReplies(db, id)
}
- UnArchiveLast(db)
+ UnArchiveLast(db, actor.Id)
if(manage == "t"){
@@ -944,7 +944,7 @@ func main() {
go DeleteObjectRequest(db, id)
}
- UnArchiveLast(db)
+ UnArchiveLast(db, actor)
if(manage == "t"){
http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther)
@@ -1345,6 +1345,22 @@ func main() {
go AddInstanceToIndexDB(db, actor)
})
+ http.HandleFunc("/poparchive", func(w http.ResponseWriter, r *http.Request) {
+
+ actor := GetActorFromDB(db, Domain)
+
+ if !HasValidation(w, r, actor) {
+ return
+ }
+
+ id := r.URL.Query().Get("id")
+ board := r.URL.Query().Get("board")
+
+ SetObjectType(db, id, "Note")
+
+ http.Redirect(w, r, "/" + board + "/archive", http.StatusSeeOther)
+ })
+
http.HandleFunc("/blacklist", func(w http.ResponseWriter, r *http.Request) {
actor := GetActorFromDB(db, Domain)
diff --git a/static/archive.html b/static/archive.html
index 2b7d69a..aa37c94 100644
--- a/static/archive.html
+++ b/static/archive.html
@@ -39,6 +39,9 @@
<table align="center" style="width: 900px;">
<tr>
+ {{ if eq $board.ModCred $board.Domain $board.Actor.Id }}
+ <td></td>
+ {{ end }}
<th style="width: 100px">No.</th>
<th>Excerpt</th>
<th style="width: 100px;"></th>
@@ -46,12 +49,18 @@
{{ range $i, $e := .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>{{ short $board.Actor.Outbox $e.Id }}</td>
<td>{{ shortExcerpt $e }}</td>
<td style="text-align: center;"><a href="/{{ $board.Actor.Name }}/{{ short $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>{{ short $board.Actor.Outbox $e.Id }}</td>
<td>{{ shortExcerpt $e }}</td>
<td style="text-align: center;"><a href="/{{ $board.Actor.Name }}/{{ short $board.Actor.Outbox $e.Id }}">[View]</a></td>
diff --git a/static/ncatalog.html b/static/ncatalog.html
index 65a7d84..c51a5a3 100644
--- a/static/ncatalog.html
+++ b/static/ncatalog.html
@@ -19,7 +19,9 @@
<hr>
<ul style="margin: 0; padding: 0; display: inline">
<li style="display: inline"><a href="/{{ $board.Name }}">[Return]</a></li>
+ {{ if showArchive }}
<li style="display: inline"><a href="/{{ $board.Name }}/archive">[Archive]</a></li>
+ {{ end }}
<li style="display: inline"><a href="#bottom">[Bottom]</a></li>
<li style="display: inline"><a href="javascript:location.reload()">[Refresh]</a></li>
</ul>
@@ -86,7 +88,9 @@
<hr>
<ul style="margin: 0; padding: 0; display: inline">
<li style="display: inline"><a href="/{{ $board.Name }}">[Return]</a></li>
+ {{ if showArchive }}
<li style="display: inline"><a href="/{{ $board.Name }}/archive">[Archive]</a></li>
+ {{ end }}
<li style="display: inline"><a id="bottom" href="#top">[Top]</a></li>
<li style="display: inline"><a href="javascript:location.reload()">[Refresh]</a></li>
</ul>
diff --git a/static/nposts.html b/static/nposts.html
index e70b982..6def8b2 100644
--- a/static/nposts.html
+++ b/static/nposts.html
@@ -17,7 +17,9 @@
<hr>
<ul style="margin: 0; padding: 0; display: inline">
<li style="display: inline"><a href="/{{ $board.Name }}/catalog">[Catalog]</a></li>
+ {{ if showArchive }}
<li style="display: inline"><a href="/{{ $board.Name }}/archive">[Archive]</a></li>
+ {{ end }}
<li style="display: inline"><a href="#bottom">[Bottom]</a></li>
<li style="display: inline"><a href="javascript:location.reload()">[Refresh]</a></li>
</ul>
@@ -27,7 +29,9 @@
<hr>
<ul style="margin: 0; padding: 0; display: inline">
<li style="display: inline"><a href="/{{ $board.Name }}/catalog">[Catalog]</a></li>
+ {{ if showArchive }}
<li style="display: inline"><a href="/{{ $board.Name }}/archive">[Archive]</a></li>
+ {{ end }}
<li style="display: inline"><a id="bottom" href="#top">[Top]</a></li>
<li style="display: inline"><a href="javascript:location.reload()">[Refresh]</a></li>
</ul>