Migrate to idiomatic error handling in app/notification_email.go (#9676)
Этот коммит содержится в:
коммит произвёл
Saturnino Abril
родитель
050c9de0f0
Коммит
1befeb61d0
@@ -151,26 +151,17 @@ func getNotificationEmailSubject(user *model.User, post *model.Post, translateFu
|
|||||||
*/
|
*/
|
||||||
func getGroupMessageNotificationEmailSubject(user *model.User, post *model.Post, translateFunc i18n.TranslateFunc, siteName string, channelName string, emailNotificationContentsType string, useMilitaryTime bool) string {
|
func getGroupMessageNotificationEmailSubject(user *model.User, post *model.Post, translateFunc i18n.TranslateFunc, siteName string, channelName string, emailNotificationContentsType string, useMilitaryTime bool) string {
|
||||||
t := getFormattedPostTime(user, post, useMilitaryTime, translateFunc)
|
t := getFormattedPostTime(user, post, useMilitaryTime, translateFunc)
|
||||||
var subjectText string
|
var subjectParameters = map[string]interface{}{
|
||||||
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
"SiteName": siteName,
|
||||||
var subjectParameters = map[string]interface{}{
|
"Month": t.Month,
|
||||||
"SiteName": siteName,
|
"Day": t.Day,
|
||||||
"ChannelName": channelName,
|
"Year": t.Year,
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
"Year": t.Year,
|
|
||||||
}
|
|
||||||
subjectText = translateFunc("app.notification.subject.group_message.full", subjectParameters)
|
|
||||||
} else {
|
|
||||||
var subjectParameters = map[string]interface{}{
|
|
||||||
"SiteName": siteName,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
"Year": t.Year,
|
|
||||||
}
|
|
||||||
subjectText = translateFunc("app.notification.subject.group_message.generic", subjectParameters)
|
|
||||||
}
|
}
|
||||||
return subjectText
|
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
||||||
|
subjectParameters["ChannelName"] = channelName
|
||||||
|
return translateFunc("app.notification.subject.group_message.full", subjectParameters)
|
||||||
|
}
|
||||||
|
return translateFunc("app.notification.subject.group_message.generic", subjectParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,31 +186,24 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post,
|
|||||||
|
|
||||||
t := getFormattedPostTime(recipient, post, useMilitaryTime, translateFunc)
|
t := getFormattedPostTime(recipient, post, useMilitaryTime, translateFunc)
|
||||||
|
|
||||||
|
info := map[string]interface{}{
|
||||||
|
"Hour": t.Hour,
|
||||||
|
"Minute": t.Minute,
|
||||||
|
"TimeZone": t.TimeZone,
|
||||||
|
"Month": t.Month,
|
||||||
|
"Day": t.Day,
|
||||||
|
}
|
||||||
if channel.Type == model.CHANNEL_DIRECT {
|
if channel.Type == model.CHANNEL_DIRECT {
|
||||||
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
||||||
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.direct.full")
|
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.direct.full")
|
||||||
bodyPage.Props["Info1"] = ""
|
bodyPage.Props["Info1"] = ""
|
||||||
bodyPage.Props["Info2"] = translateFunc("app.notification.body.text.direct.full",
|
info["SenderName"] = senderName
|
||||||
map[string]interface{}{
|
bodyPage.Props["Info2"] = translateFunc("app.notification.body.text.direct.full", info)
|
||||||
"SenderName": senderName,
|
|
||||||
"Hour": t.Hour,
|
|
||||||
"Minute": t.Minute,
|
|
||||||
"TimeZone": t.TimeZone,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.direct.generic", map[string]interface{}{
|
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.direct.generic", map[string]interface{}{
|
||||||
"SenderName": senderName,
|
"SenderName": senderName,
|
||||||
})
|
})
|
||||||
bodyPage.Props["Info"] = translateFunc("app.notification.body.text.direct.generic",
|
bodyPage.Props["Info"] = translateFunc("app.notification.body.text.direct.generic", info)
|
||||||
map[string]interface{}{
|
|
||||||
"Hour": t.Hour,
|
|
||||||
"Minute": t.Minute,
|
|
||||||
"TimeZone": t.TimeZone,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else if channel.Type == model.CHANNEL_GROUP {
|
} else if channel.Type == model.CHANNEL_GROUP {
|
||||||
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
||||||
@@ -228,27 +212,13 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post,
|
|||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"ChannelName": channelName,
|
"ChannelName": channelName,
|
||||||
})
|
})
|
||||||
bodyPage.Props["Info2"] = translateFunc("app.notification.body.text.group_message.full2",
|
info["SenderName"] = senderName
|
||||||
map[string]interface{}{
|
bodyPage.Props["Info2"] = translateFunc("app.notification.body.text.group_message.full2", info)
|
||||||
"SenderName": senderName,
|
|
||||||
"Hour": t.Hour,
|
|
||||||
"Minute": t.Minute,
|
|
||||||
"TimeZone": t.TimeZone,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.group_message.generic", map[string]interface{}{
|
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.group_message.generic", map[string]interface{}{
|
||||||
"SenderName": senderName,
|
"SenderName": senderName,
|
||||||
})
|
})
|
||||||
bodyPage.Props["Info"] = translateFunc("app.notification.body.text.group_message.generic",
|
bodyPage.Props["Info"] = translateFunc("app.notification.body.text.group_message.generic", info)
|
||||||
map[string]interface{}{
|
|
||||||
"Hour": t.Hour,
|
|
||||||
"Minute": t.Minute,
|
|
||||||
"TimeZone": t.TimeZone,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
if emailNotificationContentsType == model.EMAIL_NOTIFICATION_CONTENTS_FULL {
|
||||||
@@ -257,27 +227,13 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post,
|
|||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"ChannelName": channelName,
|
"ChannelName": channelName,
|
||||||
})
|
})
|
||||||
bodyPage.Props["Info2"] = translateFunc("app.notification.body.text.notification.full2",
|
info["SenderName"] = senderName
|
||||||
map[string]interface{}{
|
bodyPage.Props["Info2"] = translateFunc("app.notification.body.text.notification.full2", info)
|
||||||
"SenderName": senderName,
|
|
||||||
"Hour": t.Hour,
|
|
||||||
"Minute": t.Minute,
|
|
||||||
"TimeZone": t.TimeZone,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.notification.generic", map[string]interface{}{
|
bodyPage.Props["BodyText"] = translateFunc("app.notification.body.intro.notification.generic", map[string]interface{}{
|
||||||
"SenderName": senderName,
|
"SenderName": senderName,
|
||||||
})
|
})
|
||||||
bodyPage.Props["Info"] = translateFunc("app.notification.body.text.notification.generic",
|
bodyPage.Props["Info"] = translateFunc("app.notification.body.text.notification.generic", info)
|
||||||
map[string]interface{}{
|
|
||||||
"Hour": t.Hour,
|
|
||||||
"Minute": t.Minute,
|
|
||||||
"TimeZone": t.TimeZone,
|
|
||||||
"Month": t.Month,
|
|
||||||
"Day": t.Day,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,12 +290,11 @@ func (a *App) GetMessageForNotification(post *model.Post, translateFunc i18n.Tra
|
|||||||
}
|
}
|
||||||
|
|
||||||
// extract the filenames from their paths and determine what type of files are attached
|
// extract the filenames from their paths and determine what type of files are attached
|
||||||
var infos []*model.FileInfo
|
result := <-a.Srv.Store.FileInfo().GetForPost(post.Id, true, true)
|
||||||
if result := <-a.Srv.Store.FileInfo().GetForPost(post.Id, true, true); result.Err != nil {
|
if result.Err != nil {
|
||||||
mlog.Warn(fmt.Sprintf("Encountered error when getting files for notification message, post_id=%v, err=%v", post.Id, result.Err), mlog.String("post_id", post.Id))
|
mlog.Warn(fmt.Sprintf("Encountered error when getting files for notification message, post_id=%v, err=%v", post.Id, result.Err), mlog.String("post_id", post.Id))
|
||||||
} else {
|
|
||||||
infos = result.Data.([]*model.FileInfo)
|
|
||||||
}
|
}
|
||||||
|
infos := result.Data.([]*model.FileInfo)
|
||||||
|
|
||||||
filenames := make([]string, len(infos))
|
filenames := make([]string, len(infos))
|
||||||
onlyImages := true
|
onlyImages := true
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user