summaryrefslogtreecommitdiffstats
path: root/app/email_batching.go
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-09-24 09:22:29 +0200
committerSudheer <sudheer.105@gmail.com>2018-09-24 12:52:29 +0530
commit8898d7aab9565c48162c5cf16bfdf2f6f74cdb1e (patch)
tree33badb2352d3917cb40ec5cac402768e2b15cff8 /app/email_batching.go
parent74c92237c04ff290770469be516102c896710e12 (diff)
downloadchat-8898d7aab9565c48162c5cf16bfdf2f6f74cdb1e.tar.gz
chat-8898d7aab9565c48162c5cf16bfdf2f6f74cdb1e.tar.bz2
chat-8898d7aab9565c48162c5cf16bfdf2f6f74cdb1e.zip
Idiomatic error handling for app/e*.go (#9426)
Diffstat (limited to 'app/email_batching.go')
-rw-r--r--app/email_batching.go42
1 files changed, 20 insertions, 22 deletions
diff --git a/app/email_batching.go b/app/email_batching.go
index aad1eb8cb..ceee47f32 100644
--- a/app/email_batching.go
+++ b/app/email_batching.go
@@ -139,21 +139,26 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
if inspectedTeamNames[notification.teamName] != "" {
continue
}
- tchan := job.app.Srv.Store.Team().GetByName(notifications[0].teamName)
- if result := <-tchan; result.Err != nil {
+
+ result := <-job.app.Srv.Store.Team().GetByName(notifications[0].teamName)
+ if result.Err != nil {
mlog.Error(fmt.Sprint("Unable to find Team id for notification", result.Err))
continue
- } else if team, ok := result.Data.(*model.Team); ok {
+ }
+
+ if team, ok := result.Data.(*model.Team); ok {
inspectedTeamNames[notification.teamName] = team.Id
}
// if the user has viewed any channels in this team since the notification was queued, delete
// all queued notifications
- mchan := job.app.Srv.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
- if result := <-mchan; result.Err != nil {
+ result = <-job.app.Srv.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
+ if result.Err != nil {
mlog.Error(fmt.Sprint("Unable to find ChannelMembers for user", result.Err))
continue
- } else if channelMembers, ok := result.Data.(*model.ChannelMembers); ok {
+ }
+
+ if channelMembers, ok := result.Data.(*model.ChannelMembers); ok {
for _, channelMember := range *channelMembers {
if channelMember.LastViewedAt >= batchStartTime {
mlog.Debug(fmt.Sprintf("Deleted notifications for user %s", userId), mlog.String("user_id", userId))
@@ -194,38 +199,31 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
}
func (a *App) sendBatchedEmailNotification(userId string, notifications []*batchedNotification) {
- uchan := a.Srv.Store.User().Get(userId)
-
- var user *model.User
- if result := <-uchan; result.Err != nil {
+ result := <-a.Srv.Store.User().Get(userId)
+ if result.Err != nil {
mlog.Warn("Unable to find recipient for batched email notification")
return
- } else {
- user = result.Data.(*model.User)
}
+ user := result.Data.(*model.User)
translateFunc := utils.GetUserTranslations(user.Locale)
displayNameFormat := *a.Config().TeamSettings.TeammateNameDisplay
var contents string
for _, notification := range notifications {
- var sender *model.User
- schan := a.Srv.Store.User().Get(notification.post.UserId)
- if result := <-schan; result.Err != nil {
+ result := <-a.Srv.Store.User().Get(notification.post.UserId)
+ if result.Err != nil {
mlog.Warn("Unable to find sender of post for batched email notification")
continue
- } else {
- sender = result.Data.(*model.User)
}
+ sender := result.Data.(*model.User)
- var channel *model.Channel
- cchan := a.Srv.Store.Channel().Get(notification.post.ChannelId, true)
- if result := <-cchan; result.Err != nil {
+ result = <-a.Srv.Store.Channel().Get(notification.post.ChannelId, true)
+ if result.Err != nil {
mlog.Warn("Unable to find channel of post for batched email notification")
continue
- } else {
- channel = result.Data.(*model.Channel)
}
+ channel := result.Data.(*model.Channel)
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
if license := a.License(); license != nil && *license.Features.EmailNotificationContents {