package main

import (
	"flag"
	"fmt"

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

func init() {

	debugFlag := flag.Bool("debug", true, "set to true to get debugging information in the console")
	flag.Parse()

	if *debugFlag {
		log.EnableLevel("info")
		log.EnableLevel("error")
	} else {
		log.DisableLevel("info")
	}

	activityserve.Setup("config.ini", *debugFlag)

	UserDbInit()
}

func startActor(a activityserve.Actor) {

	a.OnReceiveContent = func(activity map[string]interface{}) {
		object := activity["object"].(map[string]interface{})
		fmt.Println(object["content"].(string))
	}
}

func main() {

	var actors []activityserve.Actor

	for acct := range Userdb.Keys(nil) {

		acTemp, _ := activityserve.GetActor(acct, "This is an activityserver test actor", "Service")
		log.Info("Created actor for user: ", acTemp.Name)
		actors = append(actors, acTemp)
		startActor(acTemp)

	}

	for _, ac := range actors {

		ac.Follow("https://bbs.keinpfusch.net/uriel")
		ac.CreateNote("Hello from: "+ac.Name, "")

	}

	// creating a default listener

	instance, _ := activityserve.GetActor("inbox", "This is an activityserver test actor", "Service")
	startActor(instance)
	activityserve.ServeSingleActor(instance)

}
