1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-22 19:33:27 +01:00

Do not panic when changing tiers, and user is nil

This commit is contained in:
binwiederhier 2023-02-20 21:46:25 -05:00
parent d92d1ad974
commit 67b45455b8

View file

@ -330,9 +330,13 @@ func (v *visitor) SetUser(u *user.User) {
v.mu.Lock() v.mu.Lock()
defer v.mu.Unlock() defer v.mu.Unlock()
shouldResetLimiters := v.user.TierID() != u.TierID() // TierID works with nil receiver shouldResetLimiters := v.user.TierID() != u.TierID() // TierID works with nil receiver
v.user = u v.user = u // u may be nil!
if shouldResetLimiters { if shouldResetLimiters {
v.resetLimitersNoLock(u.Stats.Messages, u.Stats.Emails, true) var messages, emails int64
if u != nil {
messages, emails = u.Stats.Messages, u.Stats.Emails
}
v.resetLimitersNoLock(messages, emails, true)
} }
} }