2016-02-03 10:58:42 +00:00
|
|
|
package protocol
|
2015-10-16 10:03:22 +00:00
|
|
|
|
2017-04-08 23:43:25 +00:00
|
|
|
import "time"
|
2015-10-30 23:38:31 +00:00
|
|
|
|
2017-08-24 20:56:31 +00:00
|
|
|
func (u *User) GetTypedAccount() (Account, error) {
|
|
|
|
if u.GetAccount() == nil {
|
|
|
|
return nil, newError("Account missing").AtWarning()
|
2016-01-15 11:43:06 +00:00
|
|
|
}
|
2016-10-16 12:22:21 +00:00
|
|
|
|
2017-08-24 20:56:31 +00:00
|
|
|
rawAccount, err := u.Account.GetInstance()
|
2016-09-17 22:41:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-16 12:22:21 +00:00
|
|
|
if asAccount, ok := rawAccount.(AsAccount); ok {
|
|
|
|
return asAccount.AsAccount()
|
|
|
|
}
|
|
|
|
if account, ok := rawAccount.(Account); ok {
|
|
|
|
return account, nil
|
|
|
|
}
|
2017-08-24 20:56:31 +00:00
|
|
|
return nil, newError("Unknown account type: ", u.Account.Type)
|
2015-12-12 23:10:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 20:56:31 +00:00
|
|
|
func (u *User) GetSettings() UserSettings {
|
2017-01-31 16:46:39 +00:00
|
|
|
settings := UserSettings{}
|
2017-08-24 20:56:31 +00:00
|
|
|
switch u.Level {
|
2017-01-31 16:46:39 +00:00
|
|
|
case 0:
|
|
|
|
settings.PayloadTimeout = time.Second * 30
|
|
|
|
case 1:
|
|
|
|
settings.PayloadTimeout = time.Minute * 2
|
|
|
|
default:
|
|
|
|
settings.PayloadTimeout = time.Minute * 5
|
2015-10-31 13:08:13 +00:00
|
|
|
}
|
|
|
|
return settings
|
2015-10-16 10:03:22 +00:00
|
|
|
}
|
2016-09-17 22:41:21 +00:00
|
|
|
|
|
|
|
type UserSettings struct {
|
2017-01-31 16:46:39 +00:00
|
|
|
PayloadTimeout time.Duration
|
2016-09-17 22:41:21 +00:00
|
|
|
}
|