Add support for Delete of actor and Unfollow
This commit is contained in:
parent
dc13138cd8
commit
03df5b5916
15
actor.go
15
actor.go
|
@ -190,16 +190,13 @@ func (a *Actor) NewFollower(iri string, inbox string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Actor) RemoveFollower(iri string) error {
|
func (a *Actor) RemoveFollower(iri string) error {
|
||||||
|
if _, ok := a.followers[iri]; ok {
|
||||||
delete(a.followers, iri)
|
delete(a.followers, iri)
|
||||||
|
fmt.Println("Removed follower: ", iri)
|
||||||
return a.save()
|
return a.save()
|
||||||
}
|
}
|
||||||
|
fmt.Println(iri, "is not following")
|
||||||
// batchSend sends a batch of http posts to a list of recipients
|
return nil
|
||||||
func (a *Actor) batchSend(activity map[string]interface{}, recipients []string) (err error) {
|
|
||||||
for _, v := range recipients {
|
|
||||||
_ = a.signedHTTPPost(activity, v)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send to followers sends a batch of http posts to each one of the followers
|
// send to followers sends a batch of http posts to each one of the followers
|
||||||
|
@ -210,7 +207,9 @@ func (a *Actor) sendToFollowers(activity map[string]interface{}) {
|
||||||
recipients[i] = inbox.(string)
|
recipients[i] = inbox.(string)
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
_ = a.batchSend(activity, recipients)
|
for _, v := range recipients {
|
||||||
|
_ = a.signedHTTPPost(activity, v)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
31
http.go
31
http.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -65,13 +66,23 @@ func Serve() {
|
||||||
defer func() { _ = f.Close() }()
|
defer func() { _ = f.Close() }()
|
||||||
_, _ = f.Write(b)
|
_, _ = f.Write(b)
|
||||||
_, _ = f.WriteString("\n---\n")
|
_, _ = f.WriteString("\n---\n")
|
||||||
if activity["type"] == "Follow" {
|
switch activity["type"] {
|
||||||
|
case "Follow":
|
||||||
actor.Accept(activity)
|
actor.Accept(activity)
|
||||||
} else if activity["type"] == "Undo" {
|
case "Undo":
|
||||||
// TODO: Implement unfollow
|
{
|
||||||
} else if activity["type"] == "Create" {
|
if object, ok := activity["object"].(map[string]interface{}); ok {
|
||||||
object, ok := activity["object"].(map[string]interface{})
|
if objectType, ok := object["type"].(string); ok && objectType == "Follow" {
|
||||||
if ok {
|
if iri, ok := object["actor"].(string); ok && iri == activity["actor"] {
|
||||||
|
_ = actor.RemoveFollower(iri)
|
||||||
|
fmt.Println(iri, "unfollowed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "Create":
|
||||||
|
{
|
||||||
|
if object, ok := activity["object"].(map[string]interface{}); ok {
|
||||||
inReplyTo, ok := object["inReplyTo"].(string)
|
inReplyTo, ok := object["inReplyTo"].(string)
|
||||||
id, ok2 := object["id"].(string)
|
id, ok2 := object["id"].(string)
|
||||||
if ok && ok2 && len(inReplyTo) > 0 && len(id) > 0 {
|
if ok && ok2 && len(inReplyTo) > 0 && len(id) > 0 {
|
||||||
|
@ -89,6 +100,14 @@ func Serve() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "Delete":
|
||||||
|
{
|
||||||
|
if object, ok := activity["object"].(string); ok && len(object) > 0 && activity["actor"] == object {
|
||||||
|
_ = actor.RemoveFollower(object)
|
||||||
|
fmt.Println("Deleted", object)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Return 201
|
// Return 201
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user