78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package chat
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"gitnet.fr/deblan/owncast-webhook/backend/store"
|
|
"gitnet.fr/deblan/owncast-webhook/backend/view"
|
|
. "maragu.dev/gomponents"
|
|
. "maragu.dev/gomponents/components"
|
|
. "maragu.dev/gomponents/html"
|
|
)
|
|
|
|
type Controller struct {
|
|
}
|
|
|
|
func New(e *echo.Echo) *Controller {
|
|
c := Controller{}
|
|
|
|
e.GET("/chat/messages", c.Messages)
|
|
|
|
return &c
|
|
}
|
|
|
|
func (ctrl *Controller) Messages(c echo.Context) error {
|
|
page := HTML5(HTML5Props{
|
|
Title: "Chat",
|
|
Language: "fr",
|
|
Head: []Node{
|
|
Group(view.EntrypointCss("main")),
|
|
Link(Rel("icon"), Type("image/x-icon"), Href(view.Asset("static/img/favicon.png"))),
|
|
},
|
|
Body: []Node{
|
|
ID("chat"),
|
|
Div(
|
|
Class("messages"),
|
|
Map(store.GetMessageStore().All(), func(message store.MessageInterface) Node {
|
|
var containerStyle Node
|
|
var userStyle Node
|
|
|
|
if message.Origin() == store.MessageOriginOwncast {
|
|
msg := message.(store.OwncastMessage)
|
|
|
|
containerStyle = StyleAttr(fmt.Sprintf(
|
|
"border-color: var(--theme-color-users-%d)",
|
|
msg.WebhookMessage.User.DisplayColor,
|
|
))
|
|
|
|
userStyle = StyleAttr(fmt.Sprintf(
|
|
"color: var(--theme-color-users-%d)",
|
|
msg.WebhookMessage.User.DisplayColor,
|
|
))
|
|
}
|
|
|
|
return Div(
|
|
Class("message"),
|
|
ID(message.ID()),
|
|
containerStyle,
|
|
Div(
|
|
Class("message-user"),
|
|
userStyle,
|
|
Text(message.Author()),
|
|
),
|
|
Div(
|
|
Class("message-body"),
|
|
Raw(message.Content()),
|
|
),
|
|
)
|
|
}),
|
|
),
|
|
Group(view.EntrypointJs("main")),
|
|
},
|
|
})
|
|
|
|
page.Render(c.Response().Writer)
|
|
|
|
return nil
|
|
}
|