Make messages list update every 3s
This commit is contained in:
parent
455639dffd
commit
827c15431c
@ -142,6 +142,12 @@ func (app *Application) get_message_global_data() (MessageData, PageGlobalData)
|
|||||||
return chat_view_data, global_data
|
return chat_view_data, global_data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *Application) messages_refresh_list(w http.ResponseWriter, r *http.Request) {
|
||||||
|
chat_view_data, global_data := app.get_message_global_data()
|
||||||
|
chat_view_data.ActiveRoomID = scraper.DMChatRoomID(r.URL.Query().Get("active-chat"))
|
||||||
|
app.buffered_render_htmx(w, "chat-list", global_data, chat_view_data)
|
||||||
|
}
|
||||||
|
|
||||||
func (app *Application) Messages(w http.ResponseWriter, r *http.Request) {
|
func (app *Application) Messages(w http.ResponseWriter, r *http.Request) {
|
||||||
app.traceLog.Printf("'Messages' handler (path: %q)", r.URL.Path)
|
app.traceLog.Printf("'Messages' handler (path: %q)", r.URL.Path)
|
||||||
|
|
||||||
@ -157,6 +163,10 @@ func (app *Application) Messages(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
|
||||||
|
if parts[0] == "refresh-list" {
|
||||||
|
app.messages_refresh_list(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
room_id := scraper.DMChatRoomID(parts[0])
|
room_id := scraper.DMChatRoomID(parts[0])
|
||||||
|
|
||||||
// Messages index
|
// Messages index
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{define "chat-list"}}
|
{{define "chat-list"}}
|
||||||
<div class="chat-list">
|
<div class="chat-list" hx-get="/messages/refresh-list?active-chat={{.ActiveRoomID}}" hx-swap="outerHTML" hx-trigger="load delay:3s">
|
||||||
{{range .RoomIDs}}
|
{{range .RoomIDs}}
|
||||||
{{template "chat-list-entry" (dict
|
{{template "chat-list-entry" (dict
|
||||||
"room" (index $.Rooms .)
|
"room" (index $.Rooms .)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user