mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-22 17:49:04 +02:00
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package appconfig
|
|
|
|
import "github.com/vmihailenco/msgpack/v5"
|
|
|
|
// DecodeMsgpack preserves settings stored in actor state before boolean toggles were replaced by modes
|
|
// Francis stores actor state as MessagePack keyed by Go field name, so the legacy keys are the old field names
|
|
func (m *AppConfigModel) DecodeMsgpack(dec *msgpack.Decoder) error {
|
|
type config AppConfigModel
|
|
value := struct {
|
|
*config
|
|
LegacyNotificationEnabled AppConfigValue `msgpack:"EmailLoginNotificationEnabled"`
|
|
LegacyEmailVerificationEnabled AppConfigValue `msgpack:"EmailVerificationEnabled"`
|
|
}{config: (*config)(m)}
|
|
if err := dec.Decode(&value); err != nil {
|
|
return err
|
|
}
|
|
if m.EmailLoginNotificationMode == "" && value.LegacyNotificationEnabled != "" {
|
|
m.EmailLoginNotificationMode = legacyLoginNotificationMode(value.LegacyNotificationEnabled)
|
|
}
|
|
if m.EmailVerification == "" && value.LegacyEmailVerificationEnabled != "" {
|
|
m.EmailVerification = legacyEmailVerification(value.LegacyEmailVerificationEnabled)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func legacyLoginNotificationMode(enabled AppConfigValue) AppConfigValue {
|
|
if enabled.IsTrue() {
|
|
return LoginNotificationBrowserRecognition
|
|
}
|
|
return LoginNotificationDisabled
|
|
}
|
|
|
|
func legacyEmailVerification(enabled AppConfigValue) AppConfigValue {
|
|
if enabled.IsTrue() {
|
|
return EmailVerificationOptional
|
|
}
|
|
return EmailVerificationDisabled
|
|
}
|