diff --git a/backend/internal/web/handlers_discussion.go b/backend/internal/web/handlers_discussion.go index 7212a59..50c4bde 100644 --- a/backend/internal/web/handlers_discussion.go +++ b/backend/internal/web/handlers_discussion.go @@ -22,14 +22,14 @@ type DiscussionDeps struct { Realtime DiscussionRealtime } -func loadDiscussionTabData(w http.ResponseWriter, r *http.Request, q *sqlc.Queries, tablo sqlc.Tablo) (templates.DiscussionTabData, bool) { +func loadDiscussionTabData(w http.ResponseWriter, r *http.Request, q *sqlc.Queries, tablo sqlc.Tablo, currentUserID uuid.UUID) (templates.DiscussionTabData, bool) { rows, err := q.ListDiscussionMessagesByTablo(r.Context(), tablo.ID) if err != nil { slog.Default().Error("discussion: ListDiscussionMessagesByTablo failed", "tablo_id", tablo.ID, "err", err) http.Error(w, "internal server error", http.StatusInternalServerError) return templates.DiscussionTabData{}, false } - data := templates.DiscussionTabData{Messages: templates.DiscussionMessagesFromRows(rows)} + data := templates.DiscussionTabData{Messages: templates.DiscussionMessagesFromRows(rows, currentUserID)} return data, true } @@ -53,7 +53,7 @@ func TabloDiscussionTabHandler(deps DiscussionDeps) http.HandlerFunc { if !ok { return } - data, ok := loadDiscussionTabData(w, r, deps.Queries, tablo) + data, ok := loadDiscussionTabData(w, r, deps.Queries, tablo, user.ID) if !ok { return } @@ -118,9 +118,9 @@ func DiscussionMessageCreateHandler(deps DiscussionDeps) http.HandlerFunc { http.Error(w, "internal server error", http.StatusInternalServerError) return } - data := templates.DiscussionTabData{Messages: []templates.DiscussionMessageView{templates.DiscussionMessageFromRow(row)}} + message := templates.DiscussionMessageFromRow(row, row.AuthorUserID == user.ID) + data := templates.DiscussionTabData{Messages: []templates.DiscussionMessageView{message}} markDiscussionRead(r, deps.Queries, tablo, user.ID, data) - message := templates.DiscussionMessageFromRow(row) if deps.Realtime != nil { html, err := renderDiscussionMessageHTML(r, message) if err != nil { diff --git a/backend/templates/discussion.templ b/backend/templates/discussion.templ index a9f9cc0..69bfb8e 100644 --- a/backend/templates/discussion.templ +++ b/backend/templates/discussion.templ @@ -19,12 +19,14 @@ templ DiscussionTabFragment(tablo sqlc.Tablo, data DiscussionTabData, form Discu if len(data.Messages) == 0 { @DiscussionEmptyState() } else { - for i, message := range data.Messages { - if DiscussionShowDaySeparator(data.Messages, i) { - @DiscussionDaySeparator(message.CreatedAt) +