From 3a4aacb9c49b7d2730b7ec46205a43c5095456d6 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 6 Jun 2021 03:01:19 -0700 Subject: better handling of follow when instance is offline --- main.go | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 5d0e782..eb3c4f0 100644 --- a/main.go +++ b/main.go @@ -452,7 +452,7 @@ func main() { } enc, _ := json.Marshal(followActivity) - + req, err := http.NewRequest("POST", actor.Outbox, bytes.NewBuffer(enc)) CheckError(err, "error with follow req") @@ -466,13 +466,14 @@ func main() { req.Header.Set("Content-Type", activitystreams) - _, err = http.DefaultClient.Do(req) - - CheckError(err, "error with add board follow resp") - - FollowingBoards = GetActorFollowingDB(db, Domain) + resp, err := http.DefaultClient.Do(req) - Boards = GetBoardCollection(db) + if err != nil && resp.StatusCode != 200 { + fmt.Println("error with add board follow resp") + } else { + FollowingBoards = GetActorFollowingDB(db, Domain) + Boards = GetBoardCollection(db) + } var redirect string if(actor.Name != "main") { @@ -1550,36 +1551,14 @@ func GetActorCollection(collection string) Collection { } func IsValidActor(id string) (Actor, bool) { - var respCollection Actor - req, err := http.NewRequest("GET", id, nil) - - CheckError(err, "error with valid actor request") - - req.Header.Set("Accept", activitystreams) - - resp, err := http.DefaultClient.Do(req) - CheckError(err, "error with valid actor response") + actor := FingerActor(id) - defer resp.Body.Close() - - if resp.StatusCode == 403 { - return respCollection, false; - } - - body, _ := ioutil.ReadAll(resp.Body) - - err = json.Unmarshal(body, &respCollection) - - if err != nil { - panic(err) - } - - if respCollection.Id != "" && respCollection.Inbox != "" && respCollection.Outbox != "" { - return respCollection, true; + if actor.Id != "" { + return actor, true; } - return respCollection, false; + return actor, false; } func IsActivityLocal(db *sql.DB, activity Activity) bool { -- cgit v1.2.3