Skip to content

Commit bc22fd6

Browse files
committed
Address Telegram rich report review comments
1 parent f357f49 commit bc22fd6

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

internal/notify/report_rich.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ func renderRichHeadline(sb *strings.Builder, h *health.HeadlineSignal) {
156156
func renderRichMorningSummary(sb *strings.Builder, b *health.BriefingResponse, f freshness, lang string) {
157157
sleepValue := "—"
158158
sleepRead := tr(lang, "tg_warn_no_sleep")
159-
if b.Sleep != nil {
159+
if f.sleepStale() && f.sleepKnown {
160+
sleepRead = fmt.Sprintf(tr(lang, "tg_sleep_silence"), fmtSilence(f.sleep, lang))
161+
} else if b.Sleep != nil {
160162
sleepValue = fmt.Sprintf("%.1fh", b.Sleep.TotalAvg)
161163
sleepRead = sectionSummary(findSection(b, "sleep"))
162164
}
165+
recoveryValue := fmt.Sprintf("%d%%", b.RecoveryPct)
163166
recoveryRead := sectionSummary(findSection(b, "recovery"))
164167
if f.watchOff() && f.watchKnown {
168+
recoveryValue = "—"
165169
recoveryRead = fmt.Sprintf(tr(lang, "tg_watch_off"), fmtSilence(f.watch, lang))
166170
}
167171
energyValue, energyRead := "—", "—"
@@ -174,7 +178,7 @@ func renderRichMorningSummary(sb *strings.Builder, b *health.BriefingResponse, f
174178
fmt.Fprintf(sb, "<tr><td>⚡ %s</td><td>%s</td><td>%s</td></tr>\n", richEsc(tr(lang, "tg_energy")), richEsc(energyValue), richText(energyRead))
175179
fmt.Fprintf(sb, "<tr><td>%s %s</td><td>%d/100</td><td>%s</td></tr>\n", richEsc(readinessEmoji(b.ReadinessToday)), richEsc(tr(lang, "tg_readiness")), b.ReadinessToday, richText(b.ReadinessTodayLabel))
176180
fmt.Fprintf(sb, "<tr><td>😴 Sleep</td><td>%s</td><td>%s</td></tr>\n", richEsc(sleepValue), richText(stripSimpleTags(sleepRead)))
177-
fmt.Fprintf(sb, "<tr><td>❤️ Recovery</td><td>%d%%</td><td>%s</td></tr>\n", b.RecoveryPct, richText(stripSimpleTags(recoveryRead)))
181+
fmt.Fprintf(sb, "<tr><td>❤️ Recovery</td><td>%s</td><td>%s</td></tr>\n", richEsc(recoveryValue), richText(stripSimpleTags(recoveryRead)))
178182
sb.WriteString("</table>\n")
179183
}
180184

internal/notify/report_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,28 @@ func TestFormatMorningRich_StructureAndEscaping(t *testing.T) {
196196
}
197197
}
198198

199+
func TestFormatMorningRich_SuppressesStaleSummaryMetrics(t *testing.T) {
200+
loc, _ := time.LoadLocation("UTC")
201+
briefing := sampleBriefing()
202+
out := formatMorningRich(briefing, nil, "en", loc, freshness{
203+
sleep: 48 * time.Hour,
204+
watch: 48 * time.Hour,
205+
sleepKnown: true,
206+
watchKnown: true,
207+
}, false, "")
208+
209+
for _, staleValue := range []string{"7.3h", "68%"} {
210+
if strings.Contains(out, staleValue) {
211+
t.Fatalf("rich summary should suppress stale value %q:\n%s", staleValue, out)
212+
}
213+
}
214+
for _, want := range []string{"No sleep recorded", "Apple Watch off"} {
215+
if !strings.Contains(out, want) {
216+
t.Fatalf("rich summary should include stale banner %q:\n%s", want, out)
217+
}
218+
}
219+
}
220+
199221
func TestFormatEveningRich_TodayTable(t *testing.T) {
200222
loc, _ := time.LoadLocation("UTC")
201223
now := time.Now().In(loc).Format("2006-01-02")

internal/notify/telegram.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ func (b *Bot) SendRichHTML(html string) error {
9191
return fmt.Errorf("telegram sendRichMessage: %w", err)
9292
}
9393
defer resp.Body.Close()
94-
body, _ := io.ReadAll(resp.Body)
94+
body, readErr := io.ReadAll(resp.Body)
95+
if readErr != nil {
96+
return fmt.Errorf("telegram sendRichMessage: read body: %w", readErr)
97+
}
9598
if resp.StatusCode != http.StatusOK {
9699
return fmt.Errorf("telegram API: status %d body=%s", resp.StatusCode, body)
97100
}

0 commit comments

Comments
 (0)