aboutsummaryrefslogtreecommitdiffstats
path: root/internal/notifier/service
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-17 01:09:47 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-17 01:09:47 -0400
commitc7b29fa19510daf4e766b689c7bc105742f35119 (patch)
tree2dd135aa2269531be353ff40446c740e6ee5f6ee /internal/notifier/service
parent12aaa903878958505d29284ac4d0d6605ba71c48 (diff)
downloaddonetick-c7b29fa19510daf4e766b689c7bc105742f35119.tar.gz
donetick-c7b29fa19510daf4e766b689c7bc105742f35119.tar.bz2
donetick-c7b29fa19510daf4e766b689c7bc105742f35119.zip
Add CircleGroup notifications to chore notifications
Diffstat (limited to '')
-rw-r--r--internal/notifier/service/planner.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/internal/notifier/service/planner.go b/internal/notifier/service/planner.go
index 05d600d..2f7f207 100644
--- a/internal/notifier/service/planner.go
+++ b/internal/notifier/service/planner.go
@@ -62,6 +62,9 @@ func (n *NotificationPlanner) GenerateNotifications(c context.Context, chore *ch
if mt.Nagging {
notifications = append(notifications, generateOverdueNotifications(chore, assignees)...)
}
+ if mt.CircleGroup {
+ notifications = append(notifications, generateCircleGroupNotifications(chore, mt)...)
+ }
n.nRepo.BatchInsertNotifications(notifications)
return true
@@ -150,3 +153,48 @@ func generateOverdueNotifications(chore *chModel.Chore, users []*cModel.UserCirc
return notifications
}
+
+func generateCircleGroupNotifications(chore *chModel.Chore, mt *chModel.NotificationMetadata) []*nModel.Notification {
+ var notifications []*nModel.Notification
+ if !mt.CircleGroup || mt.CircleGroupID == nil || *mt.CircleGroupID == 0 {
+ return notifications
+ }
+ if mt.DueDate {
+ notifications = append(notifications, &nModel.Notification{
+ ChoreID: chore.ID,
+ IsSent: false,
+ ScheduledFor: *chore.NextDueDate,
+ CreatedAt: time.Now().UTC(),
+ TypeID: 1,
+ TargetID: fmt.Sprint(*mt.CircleGroupID),
+ Text: fmt.Sprintf("📅 Reminder: *%s* is due today.", chore.Name),
+ })
+ }
+ if mt.PreDue {
+ notifications = append(notifications, &nModel.Notification{
+ ChoreID: chore.ID,
+ IsSent: false,
+ ScheduledFor: *chore.NextDueDate,
+ CreatedAt: time.Now().UTC().Add(-time.Hour * 3),
+ TypeID: 3,
+ TargetID: fmt.Sprint(*mt.CircleGroupID),
+ Text: fmt.Sprintf("📢 Heads up! *%s* is due soon (on %s).", chore.Name, chore.NextDueDate.Format("January 2nd")),
+ })
+ }
+ if mt.Nagging {
+ for _, hours := range []int{24, 48, 72} {
+ scheduleTime := chore.NextDueDate.Add(time.Hour * time.Duration(hours))
+ notifications = append(notifications, &nModel.Notification{
+ ChoreID: chore.ID,
+ IsSent: false,
+ ScheduledFor: scheduleTime,
+ CreatedAt: time.Now().UTC(),
+ TypeID: 2,
+ TargetID: fmt.Sprint(*mt.CircleGroupID),
+ Text: fmt.Sprintf("🚨 *%s* is now %d hours overdue. Please complete it as soon as possible.", chore.Name, hours),
+ })
+ }
+ }
+
+ return notifications
+}