diff options
-rw-r--r-- | CacheDatabase.go | 18 | ||||
-rw-r--r-- | Database.go | 47 | ||||
-rw-r--r-- | OutboxPost.go | 21 | ||||
-rw-r--r-- | client.go | 5 | ||||
-rw-r--r-- | static/posts.html | 2 |
5 files changed, 68 insertions, 25 deletions
diff --git a/CacheDatabase.go b/CacheDatabase.go index d5f9c97..84a18d0 100644 --- a/CacheDatabase.go +++ b/CacheDatabase.go @@ -404,7 +404,7 @@ func GetObjectRepliesCache(db *sql.DB, parent ObjectBase) (*CollectionBase, int, var postCnt int var imgCnt int - post.Replies, postCnt, imgCnt = GetObjectRepliesRepliesDB(db, post) + post.Replies, postCnt, imgCnt = GetObjectRepliesRepliesCache(db, post) post.Replies.TotalItems, post.Replies.TotalImgs = GetObjectRepliesCacheCount(db, post) @@ -445,18 +445,30 @@ func GetObjectRepliesRepliesCache(db *sql.DB, parent ObjectBase) (*CollectionBas err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.AttributedTo, &attachID, &previewID, &actor.Id) - CheckError(err, "error with replies replies cache scan") post.Actor = &actor post.Attachment = GetObjectAttachmentCache(db, attachID) - post.Preview = GetObjectPreviewCache(db, previewID) + post.Preview = GetObjectPreviewCache(db, previewID) result = append(result, post) } + nColl.OrderedItems = result + + remoteCollection, postc, imgc := GetObjectRepliesReplies(db, parent) + + for _, e := range remoteCollection.OrderedItems { + + nColl.OrderedItems = append(nColl.OrderedItems, e) + postc = postc + 1 + if len(e.Attachment) > 0 { + imgc = imgc + 1 + } + } + return &nColl, 0, 0 } diff --git a/Database.go b/Database.go index 9b8ecda..19002e3 100644 --- a/Database.go +++ b/Database.go @@ -600,6 +600,46 @@ func GetObjectRepliesRemote(db *sql.DB, parent ObjectBase) CollectionBase { return nColl } +func GetObjectRepliesReplies(db *sql.DB, parent ObjectBase) (*CollectionBase, int, int) { + + + var nColl CollectionBase + var result []ObjectBase + + query := `select id, name, content, type, published, attributedto, attachment, preview, actor from activitystream where id in (select id from replies where inreplyto=$1) and type='Note' order by published asc` + + rows, err := db.Query(query, parent.Id) + + CheckError(err, "error with replies replies db query") + + defer rows.Close() + for rows.Next() { + var post ObjectBase + var actor Actor + var attachID string + var previewID string + + post.InReplyTo = append(post.InReplyTo, parent) + + err = rows.Scan(&post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.AttributedTo, &attachID, &previewID, &actor.Id) + + + CheckError(err, "error with replies replies db scan") + + post.Actor = &actor + + post.Attachment = GetObjectAttachment(db, attachID) + + post.Preview = GetObjectPreview(db, previewID) + + result = append(result, post) + } + + nColl.OrderedItems = result + + return &nColl, 0, 0 +} + func GetObjectRepliesRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase, int, int) { var nColl CollectionBase @@ -634,7 +674,9 @@ func GetObjectRepliesRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase, result = append(result, post) } - remoteCollection, postc, imgc := GetObjectRepliesCache(db, parent) + nColl.OrderedItems = result + + remoteCollection, postc, imgc := GetObjectRepliesRepliesCache(db, parent) for _, e := range remoteCollection.OrderedItems { @@ -645,9 +687,6 @@ func GetObjectRepliesRepliesDB(db *sql.DB, parent ObjectBase) (*CollectionBase, } } - - nColl.OrderedItems = result - return &nColl, 0, 0 } diff --git a/OutboxPost.go b/OutboxPost.go index 0280573..4ef58b3 100644 --- a/OutboxPost.go +++ b/OutboxPost.go @@ -14,7 +14,6 @@ import "strings" func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { var activity Activity - var object ObjectBase actor := GetActorFromPath(db, r.URL.Path, "/") contentType := GetContentType(r.Header.Get("content-type")) @@ -75,16 +74,9 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { if IsActivityLocal(db, activity) { switch activity.Type { case "Create": - if(true) { // add condition for creating - object = GetObjectFromActivity(activity) - writeObjectToDB(db, object) - w.WriteHeader(http.StatusCreated) - w.Header().Set("Location", object.Id) - } else { - w.WriteHeader(http.StatusUnauthorized) - w.Write([]byte("")) - } - + w.WriteHeader(http.StatusBadRequest) + w.Write([]byte("")) + break case "Follow": var validActor bool @@ -121,14 +113,16 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { } w.Write([]byte("")) + break case "Delete": fmt.Println("This is a delete") w.WriteHeader(http.StatusBadRequest) w.Write([]byte("could not process activity")) - + break case "Note": w.WriteHeader(http.StatusBadRequest) w.Write([]byte("could not process activity")) + break case "New": @@ -175,13 +169,12 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("")) - + break default: w.WriteHeader(http.StatusBadRequest) w.Write([]byte("could not process activity")) } } else { - fmt.Println("is NOT activity") w.WriteHeader(http.StatusBadRequest) w.Write([]byte("could not process activity")) @@ -159,8 +159,6 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co DeleteTombstonePosts(&mergeCollection) sort.Sort(ObjectBaseSortDesc(mergeCollection.OrderedItems)) - - returnData.Boards = GetBoardCollection(db) offset := 8 @@ -173,7 +171,6 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co } } - for i, e := range returnData.Posts { var replies []ObjectBase for i := 0; i < 5; i++ { @@ -190,6 +187,8 @@ func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Co orderedReplies = append(orderedReplies, replies[cur]) } } + + returnData.Posts[i].Replies.TotalItems = len(returnData.Posts[i].Replies.OrderedItems) returnData.Posts[i].Replies.OrderedItems = orderedReplies } diff --git a/static/posts.html b/static/posts.html index a7b18a9..fcc8aec 100644 --- a/static/posts.html +++ b/static/posts.html @@ -65,7 +65,7 @@ {{ if .Replies }} {{ $replies := .Replies }} {{ if gt $replies.TotalItems 5 }} - <span>{{ $replies.TotalItems }} replies{{ if gt $replies.TotalImgs 0}} and {{ $replies.TotalImgs }} images{{ end }}, Click <a id="view" post="{{.Id}}" href="/{{ $board.Name }}/{{ .Id }}">here</a> to view all.</span> + <span>{{ $replies.TotalItems }} replies{{ if gt $replies.TotalImgs 0}} and {{ $replies.TotalImgs }} images{{ end }}, Click <a id="view" post="{{.Id}}" href="/{{ $board.Name }}/{{ .Id }}">here</a> to view all.</span> {{ end }} {{ range $replies.OrderedItems }} <div id="{{ .Id }}"> |