From 0f80a2b3520891e21d9082fb46849ce78c062e8b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 10 May 2024 17:49:46 +0800 Subject: [PATCH] 1 --- server/mailserver/mail/mailmgr.go | 37 ++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/server/mailserver/mail/mailmgr.go b/server/mailserver/mail/mailmgr.go index 17ddace3..f19726ae 100644 --- a/server/mailserver/mail/mailmgr.go +++ b/server/mailserver/mail/mailmgr.go @@ -250,6 +250,26 @@ func (this *mailMgr) traversePlayerMail(hum common.Player, cb func(*mail) bool) } } +func (this *mailMgr) removeMail(m *mail) { + this.idHash.Delete(m.mailId) + if m.isType(constant.MAIL_TYPE_ALL) { + this.wholeMails.Delete(m.mailId) + } else if m.isType(constant.MAIL_TYPE_GROUP) { + m.traverseUserGroup( + func (int64, *userGroup) bool { + this.groupMails.Delete(m.mailId) + return false + }) + m.traverseRecipients( + func (accountId string) bool { + if p, ok := this.personalMails.Load(accountId); ok { + (p.(*sync.Map)).Delete(m.mailId) + } + return true + }) + } +} + func (this *mailMgr) addMail(m *mail) { this.idHash.Store(m.mailId, m) if m.isType(constant.MAIL_TYPE_ALL) { @@ -275,6 +295,17 @@ func (this *mailMgr) addMail(m *mail) { } func (this *mailMgr) updateMail(m *mail) { + oldM := this.internalGetMail(m.mailId) + if oldM == nil { + this.addMail(m) + return + } + if oldM.mailType != m.mailType { + panic(fmt.Sprintf("updateMail mailType error")); + return + } + this.removeMail(oldM) + this.addMail(m) } func (this *mailMgr) addGroup(g *userGroup) { @@ -290,15 +321,15 @@ func (this *mailMgr) getGroup(groupId int64) *userGroup { } func (this *mailMgr) getMail(mailId string) common.Mail { - if m := this.internalGetMail(mailId); m != nil { + if m := this.internalGetMail(q5.ToInt64(mailId)); m != nil { return m } else { return nil } } -func (this *mailMgr) internalGetMail(mailId string) *mail { - if p, ok := this.idHash.Load(q5.ToInt64(mailId)); ok { +func (this *mailMgr) internalGetMail(mailId int64) *mail { + if p, ok := this.idHash.Load(mailId); ok { return p.(*mail) } else { return nil