manager.go (1069B)
1 package streamModals 2 3 import ( 4 "dkforest/pkg/database" 5 "dkforest/pkg/utils" 6 ) 7 8 type ModalsManager struct { 9 modals []IStreamModal 10 } 11 12 func NewModalsManager() *ModalsManager { 13 return &ModalsManager{} 14 } 15 16 func (m *ModalsManager) Css() (out string) { 17 out = "<style>" 18 for _, modal := range m.modals { 19 out += modal.Css() 20 out += "\n" 21 } 22 out += "</style>" 23 return 24 } 25 26 func (m *ModalsManager) Register(modal IStreamModal) { 27 m.modals = append(m.modals, modal) 28 } 29 30 // Topics gets the topics of all registered modals 31 func (m *ModalsManager) Topics() (out []string) { 32 for _, modal := range m.modals { 33 out = append(out, modal.Topics()...) 34 } 35 return 36 } 37 38 // Handle returns after the first modal that handle a specific topic 39 func (m *ModalsManager) Handle(db *database.DkfDB, authUser database.IUserRenderMessage, topic, csrf string, msgTyp database.ChatMessageType, send func(string)) bool { 40 for _, modal := range m.modals { 41 if utils.InArr(topic, modal.Topics()) { 42 if modal.Handle(db, authUser, topic, csrf, msgTyp, send) { 43 return true 44 } 45 } 46 } 47 return false 48 }