2024-09-30 21:05:06 +00:00
|
|
|
package partials
|
|
|
|
|
|
|
|
|
|
import (
|
2024-10-01 01:32:42 +00:00
|
|
|
"chat/chat"
|
|
|
|
|
"chat/components"
|
2024-09-30 21:05:06 +00:00
|
|
|
"github.com/maddalax/htmgo/framework/h"
|
|
|
|
|
)
|
|
|
|
|
|
2024-10-01 01:32:42 +00:00
|
|
|
func CreateOrJoinRoom(ctx *h.RequestContext) *h.Partial {
|
|
|
|
|
locator := ctx.ServiceLocator()
|
|
|
|
|
service := chat.NewService(locator)
|
2024-09-30 21:05:06 +00:00
|
|
|
|
2024-10-01 01:32:42 +00:00
|
|
|
chatRoomId := ctx.FormValue("join-chat-room")
|
2024-09-30 21:05:06 +00:00
|
|
|
|
2024-10-01 01:32:42 +00:00
|
|
|
if chatRoomId != "" {
|
|
|
|
|
room, _ := service.GetRoom(chatRoomId)
|
|
|
|
|
if room == nil {
|
|
|
|
|
return h.SwapPartial(ctx, components.FormError("Room not found"))
|
|
|
|
|
} else {
|
|
|
|
|
return h.RedirectPartial("/chat/" + chatRoomId)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-30 21:05:06 +00:00
|
|
|
|
2024-10-01 01:32:42 +00:00
|
|
|
chatRoomName := ctx.FormValue("chat-room-name")
|
|
|
|
|
if chatRoomName != "" {
|
|
|
|
|
// create room
|
|
|
|
|
}
|
2024-09-30 21:05:06 +00:00
|
|
|
|
2024-10-01 01:32:42 +00:00
|
|
|
return h.SwapPartial(ctx, components.FormError("Create a new room or join an existing one"))
|
2024-09-30 21:05:06 +00:00
|
|
|
}
|