This commit is contained in:
aozhiwei 2024-05-09 16:05:52 +08:00
parent 72ec085dff
commit e2b1c1411b
2 changed files with 45 additions and 16 deletions

View File

@ -23,13 +23,12 @@ type mail struct {
userRegStartTime int32
userRegEndTime int32
attachments []*attachment
recipients map[string]int32
userGroups *sync.Map
recipients *sync.Map //account_id, int
userGroups *sync.Map //group_id, *userGroup
}
func (this *mail) init() {
this.attachments = []*attachment{}
this.recipients = map[string]int32{}
}
func (this *mail) loadFromDb(ds *f5.DataSet) {
@ -56,9 +55,10 @@ func (this *mail) loadFromDb(ds *f5.DataSet) {
if err := q5.DecodeJson(recipientsStr, recipientsList); err != nil {
panic("mail.loadFromDb parse recipients error " + q5.ToString(this.mailId))
}
/*
for _, recipient := range(recipientsList) {
this.recipients[recipient] = 1
}
//this.recipients[recipient] = 1
}*/
}
}
}
@ -108,6 +108,24 @@ func (this *mail) fillMailDto(p *common.MailDto) bool {
return true
}
func (this *mail) traverseRecipients(cb func(string) bool) {
p := this.recipients
if p != nil {
p.Range(func (k, v interface{}) bool {
return cb(k.(string))
})
}
}
func (this *mail) traverseUserGroup(cb func(int64) bool) {
p := this.userGroups
if p != nil {
p.Range(func (k, v interface{}) bool {
return cb(k.(int64))
})
}
}
func newMail() *mail {
p := new(mail)
p.init()

View File

@ -200,13 +200,18 @@ func (this *mailMgr) CaDeleteMails(c *gin.Context) {
func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) {
stop := false
traversedMails := make(map[int64]*mail, 10)
traversFunc := func (k, v interface{}) bool {
m := v.(*mail)
if m.IsValid(hum) {
if _, ok := traversedMails[m.mailId]; ok {
return true
}
if !(cb(m)) {
stop = true
return false
}
traversedMails[m.mailId] = m
}
return true
}
@ -224,21 +229,27 @@ func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool)
}
func (this *mailMgr) addMail(m *mail) {
/*
this.idHash.Store(m.mailId, m)
if m.isType(constant.MAIL_TYPE_ALL) {
this.wholeMails.Store(m.mailId, m)
} else if m.isType(constant.MAIL_TYPE_GROUP) {
this.groupMails.Store(m.mailId, m)
} else if m.isType(constant.MAIL_TYPE_PERSONAL) {
if p, ok := this.personalMails.Load(m.reciver); ok {
(p.(*sync.Map)).Store(m.mailId, m)
} else {
p := new(sync.Map)
p.Store(m.mailId, m)
this.personalMails.Store(m.reciver, p)
}
}*/
m.traverseUserGroup(
func (int64) bool {
this.groupMails.Store(m.mailId, m)
return false
})
m.traverseRecipients(
func (accountId string) bool {
if p, ok := this.personalMails.Load(accountId); ok {
(p.(*sync.Map)).Store(m.mailId, m)
} else {
p := new(sync.Map)
p.Store(m.mailId, m)
this.personalMails.Store(accountId, p)
}
return true
})
}
}
func (this *mailMgr) addGroup(g *userGroup) {