2022-09-13 08:36:56 +12:00
|
|
|
package handler
|
2020-09-27 11:10:34 +13:00
|
|
|
|
|
|
|
import (
|
2021-10-06 09:38:24 +13:00
|
|
|
"m1k1o/neko/internal/types"
|
|
|
|
"m1k1o/neko/internal/types/event"
|
|
|
|
"m1k1o/neko/internal/types/message"
|
2020-09-27 11:10:34 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
func (h *MessageHandler) boradcastCreate(session types.Session, payload *message.BroadcastCreate) error {
|
|
|
|
if !session.Admin() {
|
|
|
|
h.logger.Debug().Msg("user not admin")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-16 02:05:26 +12:00
|
|
|
pipelineErr := h.broadcast.Create(payload.URL)
|
|
|
|
if pipelineErr != nil {
|
|
|
|
if err := session.Send(
|
|
|
|
message.SystemMessage{
|
|
|
|
Event: event.SYSTEM_ERROR,
|
|
|
|
Title: "Error while starting broadcast",
|
|
|
|
Message: pipelineErr.Error(),
|
|
|
|
}); err != nil {
|
|
|
|
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SYSTEM_ERROR)
|
|
|
|
return err
|
|
|
|
}
|
2021-08-16 01:37:27 +12:00
|
|
|
}
|
2020-09-27 11:10:34 +13:00
|
|
|
|
2021-12-12 01:52:31 +13:00
|
|
|
if err := h.boradcastStatus(nil); err != nil {
|
2020-09-27 11:10:34 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MessageHandler) boradcastDestroy(session types.Session) error {
|
|
|
|
if !session.Admin() {
|
|
|
|
h.logger.Debug().Msg("user not admin")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
h.broadcast.Destroy()
|
|
|
|
|
2021-12-12 01:52:31 +13:00
|
|
|
if err := h.boradcastStatus(nil); err != nil {
|
2020-09-27 11:10:34 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *MessageHandler) boradcastStatus(session types.Session) error {
|
2021-12-12 01:52:31 +13:00
|
|
|
// if no session, broadcast change
|
|
|
|
if session == nil {
|
|
|
|
if err := h.sessions.AdminBroadcast(
|
|
|
|
message.BroadcastStatus{
|
|
|
|
Event: event.BORADCAST_STATUS,
|
|
|
|
IsActive: h.broadcast.IsActive(),
|
|
|
|
URL: h.broadcast.GetUrl(),
|
|
|
|
}, nil); err != nil {
|
|
|
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.BORADCAST_STATUS)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-27 11:10:34 +13:00
|
|
|
if !session.Admin() {
|
|
|
|
h.logger.Debug().Msg("user not admin")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := session.Send(
|
|
|
|
message.BroadcastStatus{
|
|
|
|
Event: event.BORADCAST_STATUS,
|
|
|
|
IsActive: h.broadcast.IsActive(),
|
|
|
|
URL: h.broadcast.GetUrl(),
|
|
|
|
}); err != nil {
|
|
|
|
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.BORADCAST_STATUS)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|