Send notification when a list was created
This commit is contained in:
parent
ba5b8ff182
commit
4c88c91b85
|
@ -41,6 +41,7 @@ func RegisterListeners() {
|
|||
events.RegisterListener((&TaskCommentCreatedEvent{}).Name(), &SendTaskCommentNotification{})
|
||||
events.RegisterListener((&TaskAssigneeCreatedEvent{}).Name(), &SendTaskAssignedNotification{})
|
||||
events.RegisterListener((&TaskDeletedEvent{}).Name(), &SendTaskDeletedNotification{})
|
||||
events.RegisterListener((&ListCreatedEvent{}).Name(), &SendListCreatedNotification{})
|
||||
}
|
||||
|
||||
//////
|
||||
|
@ -251,6 +252,56 @@ func (s *DecreaseListCounter) Handle(payload message.Payload) (err error) {
|
|||
return keyvalue.DecrBy(metrics.ListCountKey, 1)
|
||||
}
|
||||
|
||||
// SendListCreatedNotification represents a listener
|
||||
type SendListCreatedNotification struct {
|
||||
}
|
||||
|
||||
// Name defines the name for the SendListCreatedNotification listener
|
||||
func (s *SendListCreatedNotification) Name() string {
|
||||
return "send.list.created.notification"
|
||||
}
|
||||
|
||||
// Handle is executed when the event SendListCreatedNotification listens on is fired
|
||||
func (s *SendListCreatedNotification) Handle(payload message.Payload) (err error) {
|
||||
event := &ListCreatedEvent{}
|
||||
err = json.Unmarshal(payload, event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
doer, is := event.Doer.(*user.User)
|
||||
if !is {
|
||||
return
|
||||
}
|
||||
|
||||
sess := db.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
subscribers, err := getSubscribersForEntity(sess, SubscriptionEntityList, event.List.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("Sending list created notifications to %d subscribers for list %d", len(subscribers), event.List.ID)
|
||||
|
||||
for _, subscriber := range subscribers {
|
||||
if subscriber.UserID == doer.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
n := &ListCreatedNotification{
|
||||
Doer: doer,
|
||||
List: event.List,
|
||||
}
|
||||
err = notifications.Notify(subscriber.User, n)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//////
|
||||
// Namespace events
|
||||
|
||||
|
|
|
@ -112,3 +112,22 @@ func (n *TaskDeletedNotification) ToMail() *notifications.Mail {
|
|||
func (n *TaskDeletedNotification) ToDB() interface{} {
|
||||
return n
|
||||
}
|
||||
|
||||
// ListCreatedNotification represents a ListCreatedNotification notification
|
||||
type ListCreatedNotification struct {
|
||||
Doer *user.User
|
||||
List *List
|
||||
}
|
||||
|
||||
// ToMail returns the mail notification for ListCreatedNotification
|
||||
func (n *ListCreatedNotification) ToMail() *notifications.Mail {
|
||||
return notifications.NewMail().
|
||||
Subject(n.Doer.GetName()+` created the list "`+n.List.Title+`"`).
|
||||
Line(n.Doer.GetName()+` created the list "`+n.List.Title+`"`).
|
||||
Action("View List", config.ServiceFrontendurl.GetString()+"lists/")
|
||||
}
|
||||
|
||||
// ToDB returns the ListCreatedNotification notification in a format which can be saved in the db
|
||||
func (n *ListCreatedNotification) ToDB() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue