diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 978a0f850..4c5e2a8aa 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -1012,6 +1012,17 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool, setB t.CreatedBy = createdBy + // Auto-subscribe the creator to the task so they receive + // notifications on comments and changes. + sub := &Subscription{ + UserID: createdBy.ID, + EntityType: SubscriptionEntityTask, + EntityID: t.ID, + } + if err := sub.Create(s, a); err != nil && !IsErrSubscriptionAlreadyExists(err) { + return err + } + // Update the assignees if updateAssignees { if err := t.updateTaskAssignees(s, t.Assignees, a); err != nil { diff --git a/pkg/models/tasks_test.go b/pkg/models/tasks_test.go index 433bee18a..c2f18aa4c 100644 --- a/pkg/models/tasks_test.go +++ b/pkg/models/tasks_test.go @@ -70,6 +70,12 @@ func TestTask_Create(t *testing.T) { "task_id": task.ID, "bucket_id": 1, }, false) + // Assert the creator is auto-subscribed to the task + db.AssertExists(t, "subscriptions", map[string]interface{}{ + "user_id": usr.ID, + "entity_type": SubscriptionEntityTask, + "entity_id": task.ID, + }, false) events.DispatchPending(context.Background(), s) events.AssertDispatched(t, &TaskCreatedEvent{})