diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index b7515b40a..13d64dbc2 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -992,6 +992,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 caa897740..89676c7fe 100644 --- a/pkg/models/tasks_test.go +++ b/pkg/models/tasks_test.go @@ -69,6 +69,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(s) events.AssertDispatched(t, &TaskCreatedEvent{})