summaryrefslogtreecommitdiff
path: root/owner
diff options
context:
space:
mode:
authorVitaly Minko <vitaly.minko@gmail.com>2018-10-30 20:07:08 +0300
committerVitaly Minko <vitaly.minko@gmail.com>2018-10-30 20:07:08 +0300
commit8dd637f6ef7e8600724b4e616f6fb63a54f73159 (patch)
treee21741cd4c4c47d3e8ed0b35ba02956f02c71628 /owner
parentfd2a2efc6635a278d5ff678e6d633bc6b52f77fd (diff)
Fixed several bugs related to moderation.
Diffstat (limited to 'owner')
-rw-r--r--owner/profile.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/owner/profile.go b/owner/profile.go
index cfb7f42..2a5d194 100644
--- a/owner/profile.go
+++ b/owner/profile.go
@@ -65,16 +65,11 @@ func (p *Profile) HasModerator(id *entity.ID) (bool, error) {
if *id == *p.self {
return true, nil
}
- p.modersMx.Lock()
- defer p.modersMx.Unlock()
- if p.moderators != nil {
- var err error
- p.moderators, err = p.db.GetModerators()
- if err != nil {
- return false, err
- }
+ mm, err := p.GetModerators()
+ if err != nil {
+ return false, err
}
- for _, m := range p.moderators {
+ for _, m := range mm {
if *m == *id {
return true, nil
}
@@ -85,12 +80,15 @@ func (p *Profile) HasModerator(id *entity.ID) (bool, error) {
func (p *Profile) GetModerators() ([]*entity.ID, error) {
p.modersMx.Lock()
defer p.modersMx.Unlock()
- if p.moderators != nil {
+ if p.moderators == nil {
var err error
p.moderators, err = p.db.GetModerators()
if err != nil {
return nil, err
}
+ p.moderators = append(p.moderators, p.self)
}
- return append(p.moderators, p.self), nil
+ res := make([]*entity.ID, len(p.moderators))
+ copy(res, p.moderators)
+ return res, nil
}