From 33480e92c66fa7c471b2a38417da2d30a7d6dd9d Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 23 Nov 2020 10:02:08 +0100 Subject: [PATCH] Add api-call to remove last follower --- api.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api.go b/api.go index 508561b..5cfa53e 100644 --- a/api.go +++ b/api.go @@ -92,10 +92,25 @@ var upgrader = websocket.Upgrader{ } func registerAPI(r *mux.Router) { + r.HandleFunc("/api/follows/clear-last", handleClearLastFollower) r.HandleFunc("/api/subscribe", handleUpdateSocket) r.HandleFunc("/api/webhook/{type}", handleWebHookPush) } +func handleClearLastFollower(w http.ResponseWriter, r *http.Request) { + store.Followers.Last = nil + + if err := store.Save(cfg.StoreFile); err != nil { + log.WithError(err).Error("Unable to update persistent store") + } + + if err := subscriptions.SendAllSockets(msgTypeStore, store); err != nil { + log.WithError(err).Error("Unable to send update to all sockets") + } + + w.WriteHeader(http.StatusAccepted) +} + func handleUpdateSocket(w http.ResponseWriter, r *http.Request) { // Upgrade connection to socket conn, err := upgrader.Upgrade(w, r, nil)