* modify Get method in preference_store * modify interface to match changes on preference store Get method * modify variable initialization * fix behavior on GetPreferenceByCategoryAndNameForUser
Этот коммит содержится в:
коммит произвёл
Miguel de la Cruz
родитель
b3e09715df
Коммит
a68ad55151
@@ -171,13 +171,11 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
|
||||
|
||||
// get how long we need to wait to send notifications to the user
|
||||
var interval int64
|
||||
pchan := job.server.Store.Preference().Get(userId, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL)
|
||||
if result := <-pchan; result.Err != nil {
|
||||
preference, err := job.server.Store.Preference().Get(userId, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL)
|
||||
if err != nil {
|
||||
// use the default batching interval if an error ocurrs while fetching user preferences
|
||||
interval, _ = strconv.ParseInt(model.PREFERENCE_EMAIL_INTERVAL_BATCHING_SECONDS, 10, 64)
|
||||
} else {
|
||||
preference := result.Data.(model.Preference)
|
||||
|
||||
if value, err := strconv.ParseInt(preference.Value, 10, 64); err != nil {
|
||||
// // use the default batching interval if an error ocurrs while deserializing user preferences
|
||||
interval, _ = strconv.ParseInt(model.PREFERENCE_EMAIL_INTERVAL_BATCHING_SECONDS, 10, 64)
|
||||
|
||||
@@ -48,12 +48,12 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
||||
|
||||
if *a.Config().EmailSettings.EnableEmailBatching {
|
||||
var sendBatched bool
|
||||
if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL); result.Err != nil {
|
||||
if data, err := a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_NOTIFICATIONS, model.PREFERENCE_NAME_EMAIL_INTERVAL); err != nil {
|
||||
// if the call fails, assume that the interval has not been explicitly set and batch the notifications
|
||||
sendBatched = true
|
||||
} else {
|
||||
// if the user has chosen to receive notifications immediately, don't batch them
|
||||
sendBatched = result.Data.(model.Preference).Value != model.PREFERENCE_EMAIL_INTERVAL_NO_BATCHING_SECONDS
|
||||
sendBatched = data.Value != model.PREFERENCE_EMAIL_INTERVAL_NO_BATCHING_SECONDS
|
||||
}
|
||||
|
||||
if sendBatched {
|
||||
@@ -68,17 +68,17 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
||||
translateFunc := utils.GetUserTranslations(user.Locale)
|
||||
|
||||
var useMilitaryTime bool
|
||||
if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_USE_MILITARY_TIME); result.Err != nil {
|
||||
if data, err := a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_USE_MILITARY_TIME); err != nil {
|
||||
useMilitaryTime = true
|
||||
} else {
|
||||
useMilitaryTime = result.Data.(model.Preference).Value == "true"
|
||||
useMilitaryTime = data.Value == "true"
|
||||
}
|
||||
|
||||
var nameFormat string
|
||||
if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_NAME_FORMAT); result.Err != nil {
|
||||
if data, err := a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_NAME_FORMAT); err != nil {
|
||||
nameFormat = *a.Config().TeamSettings.TeammateNameDisplay
|
||||
} else {
|
||||
nameFormat = result.Data.(model.Preference).Value
|
||||
nameFormat = data.Value
|
||||
}
|
||||
|
||||
channelName := notification.GetChannelName(nameFormat, "")
|
||||
|
||||
@@ -5,11 +5,12 @@ package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"hash/fnv"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/go-i18n/i18n"
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
@@ -151,10 +152,10 @@ func (a *App) sendPushNotification(notification *postNotification, user *model.U
|
||||
post := notification.post
|
||||
|
||||
var nameFormat string
|
||||
if result := <-a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_NAME_FORMAT); result.Err != nil {
|
||||
if data, err := a.Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_NAME_FORMAT); err != nil {
|
||||
nameFormat = *a.Config().TeamSettings.TeammateNameDisplay
|
||||
} else {
|
||||
nameFormat = result.Data.(model.Preference).Value
|
||||
nameFormat = data.Value
|
||||
}
|
||||
|
||||
channelName := notification.GetChannelName(nameFormat, user.Id)
|
||||
|
||||
@@ -32,13 +32,12 @@ func (a *App) GetPreferenceByCategoryForUser(userId string, category string) (mo
|
||||
}
|
||||
|
||||
func (a *App) GetPreferenceByCategoryAndNameForUser(userId string, category string, preferenceName string) (*model.Preference, *model.AppError) {
|
||||
result := <-a.Srv.Store.Preference().Get(userId, category, preferenceName)
|
||||
if result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusBadRequest
|
||||
return nil, result.Err
|
||||
res, err := a.Srv.Store.Preference().Get(userId, category, preferenceName)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
return nil, err
|
||||
}
|
||||
data := result.Data.(model.Preference)
|
||||
return &data, nil
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdatePreferences(userId string, preferences model.Preferences) *model.AppError {
|
||||
|
||||
Ссылка в новой задаче
Block a user