Skip to content

Commit

Permalink
New pherephone. Functionality should match the old one
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Demetriou committed Sep 20, 2019
1 parent 3b654dd commit b770bc5
Show file tree
Hide file tree
Showing 39 changed files with 129 additions and 638 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storage/
26 changes: 26 additions & 0 deletions actors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"myAwesomeList4" : {
"summary": "a list of favorite writers",
"follow": [
"https://pixelfed.social/users/qwazix",
"https://mastodon.social/users/qwazix",
"https://cybre.space/users/qwazix"
]
},
"myAwesomeList5" : {
"summary": "a list of favorite writers",
"follow": [
"https://pixelfed.social/users/qwazix",
"https://print3d.social/users/qwazix",
"https://mixt.qwazix.com/api/collections/qwazix",
"https://cybre.space/users/qwazix"
]
},
"myAwesomeList6" : {
"summary": "a list of favorite writers",
"follow": [
"https://print3d.social/users/qwazix",
"https://mixt.qwazix.com/api/collections/qwazix"
]
}
}
3 changes: 2 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

baseURL = https://floorb.qwazix.com
storage = storage ; can be relative or absolute path
userAgent = "pherephone"
userAgent = "pherephone"
announce_replies = false ; whether to boost replies of followers by default
128 changes: 100 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package main

import (
"encoding/json"
"flag"
"fmt"

// "os"
// "strings"

// "errors"

// "encoding/json"
// "io/ioutil"
// "net/http"

// "net/url"
// "context"
// "html"
"io/ioutil"
"os"
"strings"

"github.com/gologme/log"

// "github.com/go-fed/activity/streams"
// "github.com/gorilla/mux"
// "gopkg.in/ini.v1"
// "github.com/davecgh/go-spew/spew"

"../activityserve"
"github.com/writeas/activityserve"
)

var err error
Expand All @@ -50,16 +36,102 @@ func main() {
log.EnableLevel("error")
}

activityserve.Setup("config.ini", *debugFlag)
// create a logger with levels but without prefixes for easier to read
// debug output
printer := log.New(os.Stdout, "", 0)
printer.EnableLevel("error")

// actor, _ := activityserve.MakeActor("activityserve_test_actor_2", "This is an activityserve test actor", "Service")
// actor, _ := activityserve.LoadActor("activityserve_test_actor_2")
// actor.Follow("https://cybre.space/users/tzo")
// actor.CreateNote("Hello World!")
if *debugFlag == true {
fmt.Println()
fmt.Println("debug mode on")
log.EnableLevel("info")
printer.EnableLevel("info")
}

actor, _ :=
activityserve.LoadActor("activityserve_test_actor_2")
actor.CreateNote("I'm building #ActivityPub stuff", "")
configurationFile := activityserve.Setup("config.ini", *debugFlag)

announceReplies, _ := configurationFile.Section("general").Key("announce_replies").Bool()

// get the list of local actors to host and the list
// of remote actors any of them relays (boosts, announces)
jsonFile, err := os.Open("actors.json")
if err != nil {
log.Info("something is wrong with the json file containing the actors")
log.Info(err)
}

// Unmarshall it into a map of string arrays
whoFollowsWho := make(map[string]map[string]interface{})
byteValue, _ := ioutil.ReadAll(jsonFile)
err = json.Unmarshal(byteValue, &whoFollowsWho)
if err != nil {
printer.Error("There's an error in your actors.json. Please check!")
printer.Error("")
return
}

actors := make(map[string]activityserve.Actor)

// create all local actors if they don't exist yet
for follower, data := range whoFollowsWho {
followees := data["follow"].([]interface{})
printer.Info()
log.Info("Local Actor: " + follower)
if strings.ContainsAny(follower, " \\/:*?\"<>|") {
log.Warn("local actors can't have spaces or any of these characters in their name: \\/:*?\"<>|")
log.Warn("Actor " + follower + " will be ignored")
continue
}
localActor, err := activityserve.GetActor(follower, data["summary"].(string), "Service")
if err != nil {
log.Info("error creating local actor")
return
}
// Now follow each one of it's users
log.Info("Users to relay:")
for _, followee := range followees {
log.Info(followee)
go localActor.Follow(followee.(string))
}
// Iterate over the current following users and if anybody doesn't exist
// in the users to follow list unfollow them
for following := range localActor.Following() {
exists := false
for _, followee := range followees {
if followee.(string) == following {
exists = true
break
}
}
if exists == false {
go localActor.Unfollow(following)
}
}

// boost everything that comes in
localActor.OnReceiveContent = func(activity map[string]interface{}) {
log.Info("callback")
// check if we are following the person that sent us the
// message otherwise we're open in spraying spam from whoever
// messages us to our followers
if _, ok := localActor.Following()[activity["actor"].(string)]; ok {
inReplyTo, ok := activity["inReplyTo"]
isReply := false
// if the field exists and is not null and is not empty
// then it's a reply
if ok && inReplyTo != nil && inReplyTo != "" {
isReply = true
}
// if it's a reply and announce_replies config option
// is set to false then bail out
if !(announceReplies == false && isReply == true) {
content := activity["object"].(map[string]interface{})
go localActor.Announce(content["id"].(string))
}
}
}
actors[localActor.Name] = localActor
}

activityserve.Serve()
activityserve.Serve(actors)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b770bc5

Please sign in to comment.