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" msgTypeAlert string = "alert"
msgTypeBits string = "bits" msgTypeBits string = "bits"
msgTypeCustom string = "custom" msgTypeCustom string = "custom"
msgTypeFollow string = "follow"
msgTypeHost string = "host" msgTypeHost string = "host"
msgTypeRaid string = "raid" msgTypeRaid string = "raid"
msgTypeStore string = "store" msgTypeStore string = "store"

View file

@ -2,6 +2,7 @@ package main
import ( import (
"net/http" "net/http"
"time"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -24,6 +25,12 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
"total_amount": 1337, "total_amount": 1337,
} }
case msgTypeFollow:
data = map[string]interface{}{
"from": demoIssuer,
"followed_at": time.Now(),
}
case msgTypeHost: case msgTypeHost:
data = map[string]interface{}{ data = map[string]interface{}{
"from": demoIssuer, "from": demoIssuer,

View file

@ -90,6 +90,15 @@ func handleWebHookPush(w http.ResponseWriter, r *http.Request) {
continue 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") logger.WithField("name", f.FromName).Info("New follower announced")
store.WithModLock(func() error { store.WithModLock(func() error {
store.Followers.Last = &f.FromName store.Followers.Last = &f.FromName