From 8d8406df0582e7347517a8ea251abcde40c55b3d Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 3 Dec 2024 08:26:23 +0100 Subject: [PATCH] fix: task overdue at the same time as the notification If a task is overdue at the same time the notification is sent, it would contain a message like "overdue since" without a time. This now shows "overdue now" instead. --- pkg/models/notifications.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/models/notifications.go b/pkg/models/notifications.go index 6851bd3cc..a9e887f3b 100644 --- a/pkg/models/notifications.go +++ b/pkg/models/notifications.go @@ -207,6 +207,15 @@ func (n *TeamMemberAddedNotification) Name() string { return "team.member.added" } +func getOverdueSinceString(until time.Duration) (overdueSince string) { + overdueSince = `overdue since ` + utils.HumanizeDuration(until) + if until == 0 { + overdueSince = `overdue now` + } + + return +} + // UndoneTaskOverdueNotification represents a UndoneTaskOverdueNotification notification type UndoneTaskOverdueNotification struct { User *user.User @@ -220,7 +229,7 @@ func (n *UndoneTaskOverdueNotification) ToMail() *notifications.Mail { return notifications.NewMail(). Subject(`Task "`+n.Task.Title+`" (`+n.Project.Title+`) is overdue`). Greeting("Hi "+n.User.GetName()+","). - Line(`This is a friendly reminder of the task "`+n.Task.Title+`" (`+n.Project.Title+`) which is overdue since `+utils.HumanizeDuration(until)+` and not yet done.`). + Line(`This is a friendly reminder of the task "`+n.Task.Title+`" (`+n.Project.Title+`) which is `+getOverdueSinceString(until)+` and not yet done.`). Action("Open Task", config.ServicePublicURL.GetString()+"tasks/"+strconv.FormatInt(n.Task.ID, 10)). Line("Have a nice day!") } @@ -257,7 +266,7 @@ func (n *UndoneTasksOverdueNotification) ToMail() *notifications.Mail { overdueLine := "" for _, task := range sortedTasks { until := time.Until(task.DueDate).Round(1*time.Hour) * -1 - overdueLine += `* [` + task.Title + `](` + config.ServicePublicURL.GetString() + "tasks/" + strconv.FormatInt(task.ID, 10) + `) (` + n.Projects[task.ProjectID].Title + `), overdue since ` + utils.HumanizeDuration(until) + "\n" + overdueLine += `* [` + task.Title + `](` + config.ServicePublicURL.GetString() + "tasks/" + strconv.FormatInt(task.ID, 10) + `) (` + n.Projects[task.ProjectID].Title + `), ` + getOverdueSinceString(until) + "\n" } return notifications.NewMail().