From c2184d6add23d9b0ca44dbbc5d026ab4f482dceb Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sat, 31 Jul 2021 16:35:42 -0700 Subject: added pop route for removing archived posts. removed seeing archive page when not archived posts. --- client.go | 20 ++++++++++++++-- database.go | 67 ++++++++++++++++++++++++++++++++++++++++++---------- main.go | 26 ++++++++++++++++---- static/archive.html | 9 +++++++ static/ncatalog.html | 4 ++++ static/nposts.html | 4 ++++ 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 @@ + {{ if eq $board.ModCred $board.Domain $board.Actor.Id }} + + {{ end }} @@ -46,12 +49,18 @@ {{ range $i, $e := .Posts }} {{ if mod $i 2 }} + {{ if eq $board.ModCred $board.Domain $board.Actor.Id }} + + {{ end }} {{ else }} + {{ if eq $board.ModCred $board.Domain $board.Actor.Id }} + + {{ end }} 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 @@
@@ -86,7 +88,9 @@
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 @@
@@ -27,7 +29,9 @@
-- cgit v1.2.3
No. Excerpt
[Pop]{{ short $board.Actor.Outbox $e.Id }} {{ shortExcerpt $e }} [View]
[Pop]{{ short $board.Actor.Outbox $e.Id }} {{ shortExcerpt $e }} [View]