Add extra event type for follows

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-04-22 16:02:16 +02:00
parent 6e62d32832
commit aa20136f63
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
3 changed files with 17 additions and 0 deletions

1
api.go
View file

@ -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"

View file

@ -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,

View file

@ -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