aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2021-05-30 23:50:40 -0700
committerFChannel <>2021-05-30 23:50:40 -0700
commit13fddffc60b9cd6350e888ea4e92745a58e1f256 (patch)
treeef644acc72929f9aae114f9962558e084685bc1f
parentcaa24b5f43709f3201faf0eabf2ac7afcdee17f7 (diff)
added finger methods for getting the actor
-rw-r--r--client.go10
-rw-r--r--main.go90
-rw-r--r--static/npost.html2
3 files changed, 98 insertions, 4 deletions
diff --git a/client.go b/client.go
index 1ef6250..6ca3ee0 100644
--- a/client.go
+++ b/client.go
@@ -215,15 +215,17 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){
name := GetActorFollowNameFromPath(path)
followActors := GetActorsFollowFromName(actor, name)
followCollection := GetActorsFollowPostFromId(db, followActors, postId)
-
- returnData.Board.Post.Actor = followCollection.Actor
-
+
DeleteRemovedPosts(db, &followCollection)
DeleteTombstoneReplies(&followCollection)
- if len(followCollection.OrderedItems) > 0 {
+ if len(followCollection.OrderedItems) > 0 {
returnData.Board.InReplyTo = followCollection.OrderedItems[0].Id
returnData.Posts = append(returnData.Posts, followCollection.OrderedItems[0])
+
+ var actor Actor
+ actor = FingerActor(returnData.Board.InReplyTo)
+ returnData.Board.Post.Actor = &actor
}
} else {
collection := GetObjectByIDFromDB(db, inReplyTo)
diff --git a/main.go b/main.go
index 6fa1486..246a9f1 100644
--- a/main.go
+++ b/main.go
@@ -2136,3 +2136,93 @@ func CreatedNeededDirectories() {
os.MkdirAll("./pem/board", 0700)
}
}
+
+//looks for actor with pattern of board@instance
+func FingerActor(path string) Actor{
+
+ actor, instance := GetActorInstance(path)
+
+ r := FingerRequest(actor, instance)
+
+ var nActor Actor
+
+ if r.StatusCode == 200 {
+ defer r.Body.Close()
+
+ body, _ := ioutil.ReadAll(r.Body)
+
+ err := json.Unmarshal(body, &nActor)
+
+ CheckError(err, "error getting fingerrequet resp from json body")
+ }
+
+ return nActor
+}
+
+func FingerRequest(actor string, instance string) (*http.Response){
+ acct := "acct:" + actor + "@" + instance
+ req, err := http.NewRequest("GET", "http://" + instance + "/.well-known/webfinger?resource=" + acct, nil)
+
+ CheckError(err, "could not get finger request from id req")
+
+ req.Header.Set("Accept", activitystreams)
+
+ resp, err := http.DefaultClient.Do(req)
+
+ var finger Webfinger
+
+ if err != nil {
+ CheckError(err, "could not get actor from finger resp with id " + acct)
+ }
+
+ if resp.StatusCode == 200 {
+ defer resp.Body.Close()
+
+ body, _ := ioutil.ReadAll(resp.Body)
+
+ err := json.Unmarshal(body, &finger)
+
+ CheckError(err, "error getting fingerrequet resp from json body")
+ }
+
+ if(len(finger.Links) > 0) {
+ for _, e := range finger.Links {
+ if(e.Type == "application/activity+json"){
+ req, err := http.NewRequest("GET", e.Href, nil)
+
+ CheckError(err, "could not get finger request from id req")
+
+ req.Header.Set("Accept", activitystreams)
+
+ resp, err := http.DefaultClient.Do(req)
+ return resp
+ }
+ }
+ }
+
+ return resp
+}
+
+func GetActorInstance(path string) (string, string) {
+ re := regexp.MustCompile(`([@]?([\w\d.-_]+)[@](.+))`)
+ atFormat := re.MatchString(path)
+
+ if(atFormat) {
+ match := re.FindStringSubmatch(path)
+ if(len(match) > 1) {
+ return match[1], match[2]
+ }
+ }
+
+ re = regexp.MustCompile(`(http:\\|https:\\)?(www)?([\w\d-_.:]+)\/([\w\d-_.]+)`)
+ httpFormat := re.MatchString(path)
+
+ if(httpFormat) {
+ match := re.FindStringSubmatch(path)
+ if(len(match) > 3) {
+ return match[4], match[3]
+ }
+ }
+
+ return "", ""
+}
diff --git a/static/npost.html b/static/npost.html
index b91b795..e3c4cec 100644
--- a/static/npost.html
+++ b/static/npost.html
@@ -14,6 +14,8 @@
</ul>
<hr>
+{{ $board.Restricted }}
+
{{ template "posts" . }}
<hr>