fix: tasks with the same assignee as doer should not appear twice in overdue task mails

This commit is contained in:
kolaente 2022-09-30 18:35:40 +02:00
parent 86ee8273bc
commit 45defebcf4
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 15 additions and 5 deletions

View file

@ -18,6 +18,7 @@ package models
import ( import (
"bufio" "bufio"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -230,14 +231,23 @@ func (n *UndoneTaskOverdueNotification) Name() string {
// UndoneTasksOverdueNotification represents a UndoneTasksOverdueNotification notification // UndoneTasksOverdueNotification represents a UndoneTasksOverdueNotification notification
type UndoneTasksOverdueNotification struct { type UndoneTasksOverdueNotification struct {
User *user.User User *user.User
Tasks []*Task Tasks map[int64]*Task
} }
// ToMail returns the mail notification for UndoneTasksOverdueNotification // ToMail returns the mail notification for UndoneTasksOverdueNotification
func (n *UndoneTasksOverdueNotification) ToMail() *notifications.Mail { func (n *UndoneTasksOverdueNotification) ToMail() *notifications.Mail {
overdueLine := "" sortedTasks := make([]*Task, 0, len(n.Tasks))
for _, task := range 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 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" overdueLine += `* [` + task.Title + `](` + config.ServiceFrontendurl.GetString() + "tasks/" + strconv.FormatInt(task.ID, 10) + `), overdue since ` + utils.HumanizeDuration(until) + "\n"
} }

View file

@ -92,10 +92,10 @@ func getUndoneOverdueTasks(s *xorm.Session, now time.Time) (usersWithTasks map[i
if !exists { if !exists {
uts[t.User.ID] = &userWithTasks{ uts[t.User.ID] = &userWithTasks{
user: t.User, 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 { type userWithTasks struct {
user *user.User 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. // RegisterOverdueReminderCron registers a function which checks once a day for tasks that are overdue and not done.