fix(assignees): subscribe assigned users directly to the task, not async
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Resolves https://community.vikunja.io/t/richer-email-notifications/1891
This commit is contained in:
parent
b2970c6c04
commit
e4fec01d52
@ -52,7 +52,6 @@ func RegisterListeners() {
|
||||
events.RegisterListener((&TaskAssigneeCreatedEvent{}).Name(), &SendTaskAssignedNotification{})
|
||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &SendTaskDeletedNotification{})
|
||||
events.RegisterListener((&ProjectCreatedEvent{}).Name(), &SendProjectCreatedNotification{})
|
||||
events.RegisterListener((&TaskAssigneeCreatedEvent{}).Name(), &SubscribeAssigneeToTask{})
|
||||
events.RegisterListener((&TeamMemberAddedEvent{}).Name(), &SendTeamMemberAddedNotification{})
|
||||
events.RegisterListener((&TaskCommentUpdatedEvent{}).Name(), &HandleTaskCommentEditMentions{})
|
||||
events.RegisterListener((&TaskCreatedEvent{}).Name(), &HandleTaskCreateMentions{})
|
||||
@ -371,39 +370,6 @@ func (s *SendTaskDeletedNotification) Handle(msg *message.Message) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
type SubscribeAssigneeToTask struct {
|
||||
}
|
||||
|
||||
// Name defines the name for the SubscribeAssigneeToTask listener
|
||||
func (s *SubscribeAssigneeToTask) Name() string {
|
||||
return "task.assignee.subscribe"
|
||||
}
|
||||
|
||||
// Handle is executed when the event SubscribeAssigneeToTask listens on is fired
|
||||
func (s *SubscribeAssigneeToTask) Handle(msg *message.Message) (err error) {
|
||||
event := &TaskAssigneeCreatedEvent{}
|
||||
err = json.Unmarshal(msg.Payload, event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sub := &Subscription{
|
||||
UserID: event.Assignee.ID,
|
||||
EntityType: SubscriptionEntityTask,
|
||||
EntityID: event.Task.ID,
|
||||
}
|
||||
|
||||
sess := db.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
err = sub.Create(sess, event.Assignee)
|
||||
if err != nil && !IsErrSubscriptionAlreadyExists(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// HandleTaskCreateMentions represents a listener
|
||||
type HandleTaskCreateMentions struct {
|
||||
}
|
||||
|
@ -256,6 +256,17 @@ func (t *Task) addNewAssigneeByID(s *xorm.Session, newAssigneeID int64, project
|
||||
return err
|
||||
}
|
||||
|
||||
sub := &Subscription{
|
||||
UserID: newAssigneeID,
|
||||
EntityType: SubscriptionEntityTask,
|
||||
EntityID: t.ID,
|
||||
}
|
||||
|
||||
err = sub.Create(s, newAssignee)
|
||||
if err != nil && !IsErrSubscriptionAlreadyExists(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
doer, _ := user.GetFromAuth(auth)
|
||||
err = events.Dispatch(&TaskAssigneeCreatedEvent{
|
||||
Task: t,
|
||||
|
Loading…
x
Reference in New Issue
Block a user