aboutsummaryrefslogtreecommitdiff
path: root/webfinger
diff options
context:
space:
mode:
authorFChannel <>2022-04-30 22:17:32 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commit503a6637b8294aeb8e5e5546f8acbd2b3d6c4744 (patch)
tree56614d955df0d3e7284baa997bbf1a8dcc2e78f5 /webfinger
parent1892327cee2c3fa1d3bea729bd08eb63c2189a96 (diff)
first steps in posting connected. can make reply with no quote or quote OP
do not recommend working on this branch for the time being since things are being moved around a lot
Diffstat (limited to 'webfinger')
-rw-r--r--webfinger/webfinger.go116
1 files changed, 88 insertions, 28 deletions
diff --git a/webfinger/webfinger.go b/webfinger/webfinger.go
index 210a3d6..7e58d00 100644
--- a/webfinger/webfinger.go
+++ b/webfinger/webfinger.go
@@ -77,27 +77,23 @@ func FingerActor(path string) (activitypub.Actor, error) {
if ActorCache[actor+"@"+instance].Id != "" {
nActor = ActorCache[actor+"@"+instance]
- return nActor, nil
- }
+ } else {
+ r, _ := FingerRequest(actor, instance)
- r, err := FingerRequest(actor, instance)
- if err != nil {
- return nActor, err
- }
+ if r != nil && r.StatusCode == 200 {
+ defer r.Body.Close()
- if r != nil && r.StatusCode == 200 {
- defer r.Body.Close()
+ body, _ := ioutil.ReadAll(r.Body)
- body, _ := ioutil.ReadAll(r.Body)
+ json.Unmarshal(body, &nActor)
+ // if err := json.Unmarshal(body, &nActor); err != nil {
+ // return nActor, err
+ // }
- if err := json.Unmarshal(body, &nActor); err != nil {
- return nActor, err
+ ActorCache[actor+"@"+instance] = nActor
}
-
- ActorCache[actor+"@"+instance] = nActor
}
- // TODO: this just falls through and returns a blank Actor object. do something?
return nActor, nil
}
@@ -105,14 +101,14 @@ func FingerRequest(actor string, instance string) (*http.Response, error) {
acct := "acct:" + actor + "@" + instance
// TODO: respect https
- req, err := http.NewRequest("GET", "http://"+instance+"/.well-known/webfinger?resource="+acct, nil)
- if err != nil {
- return nil, err
- }
+ req, _ := http.NewRequest("GET", "http://"+instance+"/.well-known/webfinger?resource="+acct, nil)
+ // if err != nil {
+ // return nil, err
+ // }
resp, err := util.RouteProxy(req)
if err != nil {
- return resp, err
+ return resp, nil
}
var finger Webfinger
@@ -122,23 +118,24 @@ func FingerRequest(actor string, instance string) (*http.Response, error) {
body, _ := ioutil.ReadAll(resp.Body)
- if err := json.Unmarshal(body, &finger); err != nil {
- return resp, err
- }
+ json.Unmarshal(body, &finger)
+ // if err := json.Unmarshal(body, &finger); err != nil {
+ // return resp, err
+ // }
}
if len(finger.Links) > 0 {
for _, e := range finger.Links {
if e.Type == "application/activity+json" {
- req, err := http.NewRequest("GET", e.Href, nil)
- if err != nil {
- return resp, err
- }
+ req, _ := http.NewRequest("GET", e.Href, nil)
+ // if err != nil {
+ // return resp, err
+ // }
req.Header.Set("Accept", config.ActivityStreams)
- resp, err := util.RouteProxy(req)
- return resp, err
+ resp, _ := util.RouteProxy(req)
+ return resp, nil
}
}
}
@@ -179,3 +176,66 @@ func CheckValidActivity(id string) (activitypub.Collection, bool, error) {
return respCollection, false, nil
}
+
+func CreateActivity(activityType string, obj activitypub.ObjectBase) (activitypub.Activity, error) {
+ var newActivity activitypub.Activity
+
+ actor, err := FingerActor(obj.Actor)
+ if err != nil {
+ return newActivity, err
+ }
+
+ newActivity.AtContext.Context = "https://www.w3.org/ns/activitystreams"
+ newActivity.Type = activityType
+ newActivity.Published = obj.Published
+ newActivity.Actor = &actor
+ newActivity.Object = &obj
+
+ for _, e := range obj.To {
+ if obj.Actor != e {
+ newActivity.To = append(newActivity.To, e)
+ }
+ }
+
+ for _, e := range obj.Cc {
+ if obj.Actor != e {
+ newActivity.Cc = append(newActivity.Cc, e)
+ }
+ }
+
+ return newActivity, nil
+}
+
+func AddFollowersToActivity(activity activitypub.Activity) (activitypub.Activity, error) {
+ activity.To = append(activity.To, activity.Actor.Id)
+
+ for _, e := range activity.To {
+ aFollowers, err := GetActorCollection(e + "/followers")
+ if err != nil {
+ return activity, err
+ }
+
+ for _, k := range aFollowers.Items {
+ activity.To = append(activity.To, k.Id)
+ }
+ }
+
+ var nActivity activitypub.Activity
+
+ for _, e := range activity.To {
+ var alreadyTo = false
+ for _, k := range nActivity.To {
+ if e == k || e == activity.Actor.Id {
+ alreadyTo = true
+ }
+ }
+
+ if !alreadyTo {
+ nActivity.To = append(nActivity.To, e)
+ }
+ }
+
+ activity.To = nActivity.To
+
+ return activity, nil
+}