From 1a131d79f90b8bbf436b16ba22a8354a84e66b7e Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 29 Aug 2024 10:35:05 +0200 Subject: [PATCH] fix(subscriptions): ignore task subscription when the user is subscribed to the project Resolves https://community.vikunja.io/t/e-mail-notification-twice/2740/12 Resolves https://github.com/go-vikunja/vikunja/issues/316 (cherry picked from commit efde364224cf744c448a5b8e069776f18652d314) --- pkg/models/subscription.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/pkg/models/subscription.go b/pkg/models/subscription.go index 023956f36..2ad6a547f 100644 --- a/pkg/models/subscription.go +++ b/pkg/models/subscription.go @@ -234,23 +234,12 @@ func GetSubscriptions(s *xorm.Session, entityType SubscriptionEntityType, entity return nil, err } - // If the task does not have a subscription directly or from its project, get the one - // from the parent and return it instead. - var taskIDsWithoutSubscription []int64 - for _, eID := range entityIDs { - if _, has := subs[eID]; has { - continue - } - - taskIDsWithoutSubscription = append(taskIDsWithoutSubscription, eID) - } - - projects, err := GetProjectsSimplByTaskIDs(s, taskIDsWithoutSubscription) + projects, err := GetProjectsSimplByTaskIDs(s, entityIDs) if err != nil { return nil, err } - tasks, err := GetTasksSimpleByIDs(s, taskIDsWithoutSubscription) + tasks, err := GetTasksSimpleByIDs(s, entityIDs) if err != nil { return nil, err } @@ -261,9 +250,17 @@ func GetSubscriptions(s *xorm.Session, entityType SubscriptionEntityType, entity } for _, task := range tasks { - sub, has := projectSubscriptions[task.ProjectID] - if has { - subs[task.ID] = sub + // If a task is already subscribed through the parent project, + // remove the task subscription since that's a duplicate. + // But if the user is not subscribed to the task but a parent project is, add that to the subscriptions + psub, hasProjectSub := projectSubscriptions[task.ProjectID] + _, hasTaskSub := subs[task.ID] + if hasProjectSub && hasTaskSub { + delete(subs, task.ID) + } + + if !hasTaskSub { + subs[task.ID] = psub } }