diff --git a/pkg/models/notifications.go b/pkg/models/notifications.go index 02688b8b..8867d0df 100644 --- a/pkg/models/notifications.go +++ b/pkg/models/notifications.go @@ -18,6 +18,7 @@ package models import ( "bufio" + "sort" "strconv" "strings" "time" @@ -230,14 +231,23 @@ func (n *UndoneTaskOverdueNotification) Name() string { // UndoneTasksOverdueNotification represents a UndoneTasksOverdueNotification notification type UndoneTasksOverdueNotification struct { User *user.User - Tasks []*Task + Tasks map[int64]*Task } // ToMail returns the mail notification for UndoneTasksOverdueNotification func (n *UndoneTasksOverdueNotification) ToMail() *notifications.Mail { - overdueLine := "" + sortedTasks := make([]*Task, 0, len(n.Tasks)) for _, task := range n.Tasks { + sortedTasks = append(sortedTasks, task) + } + + sort.Slice(sortedTasks, func(i, j int) bool { + return sortedTasks[i].DueDate.Before(sortedTasks[j].DueDate) + }) + + overdueLine := "" + for _, task := range sortedTasks { until := time.Until(task.DueDate).Round(1*time.Hour) * -1 overdueLine += `* [` + task.Title + `](` + config.ServiceFrontendurl.GetString() + "tasks/" + strconv.FormatInt(task.ID, 10) + `), overdue since ` + utils.HumanizeDuration(until) + "\n" } diff --git a/pkg/models/task_overdue_reminder.go b/pkg/models/task_overdue_reminder.go index a96db958..0feff61a 100644 --- a/pkg/models/task_overdue_reminder.go +++ b/pkg/models/task_overdue_reminder.go @@ -92,10 +92,10 @@ func getUndoneOverdueTasks(s *xorm.Session, now time.Time) (usersWithTasks map[i if !exists { uts[t.User.ID] = &userWithTasks{ user: t.User, - tasks: []*Task{}, + tasks: make(map[int64]*Task), } } - uts[t.User.ID].tasks = append(uts[t.User.ID].tasks, t.Task) + uts[t.User.ID].tasks[t.Task.ID] = t.Task } } @@ -104,7 +104,7 @@ func getUndoneOverdueTasks(s *xorm.Session, now time.Time) (usersWithTasks map[i type userWithTasks struct { user *user.User - tasks []*Task + tasks map[int64]*Task } // RegisterOverdueReminderCron registers a function which checks once a day for tasks that are overdue and not done.