diff --git a/Chat.go b/Chat.go index 01810cc..32c27ec 100644 --- a/Chat.go +++ b/Chat.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "fmt" "net/url" "sort" "strings" @@ -15,6 +16,7 @@ import ( func ChatPageHandler(c *fiber.Ctx) error { authCookie := c.Cookies("jade-edgedb-auth-token", "") + fmt.Println("Main page") if authCookie != "" && !checkIfLogin() { edgeClient = edgeClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": authCookie}) @@ -64,7 +66,7 @@ func LoadChatHandler(c *fiber.Ctx) error { if checkIfLogin() { if IsCurrentUserLimiteReached() && !IsCurrentUserSubscribed() { return c.SendString(generateLimitReachedChatHTML()) - } else if getCurrentUserKeys() == nil { + } else if !checkIfHaveKey() { return c.SendString(generateEnterKeyChatHTML()) } return c.SendString(generateChatHTML()) @@ -84,9 +86,33 @@ type TemplateMessage struct { } func generateChatHTML() string { - // Get the messages from the database // Maybe redo that to be area by area because look like shit rn. It come from early stage of dev. It work tho soooo... - Messages := getAllMessages() + var Messages []Message + + err := edgeClient.Query(edgeCtx, ` + SELECT Message { + id, + selected, + role, + content, + date, + llm : { + name, + modelInfo : { + modelID, + name, + company : { + icon + } + } + } + } + FILTER .conversation = global currentConversation AND .conversation.user = global currentUser + ORDER BY .date ASC + `, &Messages) + if err != nil { + panic(err) + } htmlString := "