diff --git a/api.go b/api.go index dc3e902..b835dcb 100644 --- a/api.go +++ b/api.go @@ -21,6 +21,7 @@ const ( msgTypeAlert string = "alert" msgTypeBits string = "bits" msgTypeCustom string = "custom" + msgTypeFollow string = "follow" msgTypeHost string = "host" msgTypeRaid string = "raid" msgTypeStore string = "store" diff --git a/demo.go b/demo.go index ff279d9..d77ca64 100644 --- a/demo.go +++ b/demo.go @@ -2,6 +2,7 @@ package main import ( "net/http" + "time" "github.com/gorilla/mux" "github.com/pkg/errors" @@ -24,6 +25,12 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) { "total_amount": 1337, } + case msgTypeFollow: + data = map[string]interface{}{ + "from": demoIssuer, + "followed_at": time.Now(), + } + case msgTypeHost: data = map[string]interface{}{ "from": demoIssuer, diff --git a/webhook.go b/webhook.go index 0a4f798..790049e 100644 --- a/webhook.go +++ b/webhook.go @@ -90,6 +90,15 @@ func handleWebHookPush(w http.ResponseWriter, r *http.Request) { continue } + fields := map[string]interface{}{ + "from": f.FromName, + "followed_at": f.FollowedAt, + } + + if err := subscriptions.SendAllSockets(msgTypeFollow, fields); err != nil { + log.WithError(err).Error("Unable to send update to all sockets") + } + logger.WithField("name", f.FromName).Info("New follower announced") store.WithModLock(func() error { store.Followers.Last = &f.FromName