aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <=>2021-01-20 14:55:50 -0800
committerFChannel <=>2021-01-20 14:55:50 -0800
commitb6c03f8aa0ce125a76464699a72ff156769feb0e (patch)
tree1d270f5e81a823046cb0d7d9390b16787510b8b6
parent08fea42e13bd16b7f50ece10eebcbebe8c9509fb (diff)
added actor object to context json
-rw-r--r--Database.go6
-rw-r--r--activityPubStruct.go2
-rw-r--r--main.go17
-rw-r--r--outboxGet.go3
4 files changed, 19 insertions, 9 deletions
diff --git a/Database.go b/Database.go
index d0f6892..f79bf50 100644
--- a/Database.go
+++ b/Database.go
@@ -290,8 +290,11 @@ func WritePreviewToDB(db *sql.DB, obj NestedObjectBase) {
func GetActivityFromDB(db *sql.DB, id string) Collection {
var nColl Collection
+ var nActor Actor
var result []ObjectBase
+ nColl.Actor = &nActor
+
query := `select actor, id, name, content, type, published, updated, attributedto, attachment, preview, actor from activitystream where id=$1 order by updated asc`
rows, err := db.Query(query, id)
@@ -305,7 +308,8 @@ func GetActivityFromDB(db *sql.DB, id string) Collection {
var attachID string
var previewID string
- err = rows.Scan(&nColl.Actor, &post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.Updated, &post.AttributedTo, &attachID, &previewID, &actor.Id)
+
+ err = rows.Scan(&nColl.Actor.Id, &post.Id, &post.Name, &post.Content, &post.Type, &post.Published, &post.Updated, &post.AttributedTo, &attachID, &previewID, &actor.Id)
CheckError(err, "error scan object into post struct")
diff --git a/activityPubStruct.go b/activityPubStruct.go
index d200f64..f145a01 100644
--- a/activityPubStruct.go
+++ b/activityPubStruct.go
@@ -176,7 +176,7 @@ type NestedObjectBase struct {
}
type CollectionBase struct {
- Actor string `json:"actor,omitempty"`
+ Actor *Actor `json:"actor,omitempty"`
Summary string `json:"summary,omitempty"`
Type string `json:"type,omitempty"`
TotalItems int `json:"totalItems,omitempty"`
diff --git a/main.go b/main.go
index 8c7ff94..865d1ef 100644
--- a/main.go
+++ b/main.go
@@ -271,8 +271,6 @@ func main() {
return
}
-
-
actor := GetActorFromPath(db, id, "/")
if !HasAuth(db, auth[1], actor.Id) {
@@ -280,7 +278,7 @@ func main() {
w.Write([]byte(""))
return
}
-
+
reported := DeleteReportActivity(db, id)
if reported {
w.Write([]byte(""))
@@ -709,7 +707,10 @@ func GetActor(id string) Actor {
resp, err := http.DefaultClient.Do(req)
- CheckError(err, "error with getting actor resp")
+ if err != nil {
+ fmt.Println("error with getting actor resp")
+ return respActor
+ }
defer resp.Body.Close()
@@ -910,7 +911,7 @@ func ReportActivity(db *sql.DB, id string) bool {
}
if count < 1 {
- query = fmt.Sprintf("insert into reported (id, count, board) values ('%s', %d, '%s')", id, 1, actor.Actor)
+ query = fmt.Sprintf("insert into reported (id, count, board) values ('%s', %d, '%s')", id, 1, actor.Actor.Id)
_, err := db.Exec(query)
@@ -966,16 +967,20 @@ func GetActorReported(w http.ResponseWriter, r *http.Request, db *sql.DB, id str
func MakeActivityRequest(activity Activity) {
j, _ := json.MarshalIndent(activity, "", "\t")
+
for _, e := range activity.To {
+
actor := GetActor(e)
+ if actor.Inbox != "" {
req, err := http.NewRequest("POST", actor.Inbox, bytes.NewBuffer(j))
CheckError(err, "error with sending activity req to")
_, err = http.DefaultClient.Do(req)
- CheckError(err, "error with sending activity resp to")
+ CheckError(err, "error with sending activity resp to")
+ }
}
}
diff --git a/outboxGet.go b/outboxGet.go
index 7aaf70f..dbd0fa9 100644
--- a/outboxGet.go
+++ b/outboxGet.go
@@ -13,7 +13,8 @@ func GetActorOutbox(w http.ResponseWriter, r *http.Request, db *sql.DB) {
collection.OrderedItems = GetObjectFromDB(db, actor).OrderedItems
collection.AtContext.Context = "https://www.w3.org/ns/activitystreams"
- collection.Actor = actor.Id
+ collection.Actor = &actor
+ collection.Actor.AtContext.Context = ""
collection.TotalItems = GetObjectPostsTotalDB(db, actor)
collection.TotalImgs = GetObjectImgsTotalDB(db, actor)