miduo_client/Assets/ManagedResources/~Lua/Modules/Mail/MailManager.lua

141 lines
4.6 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

MailManager = {};
local this = MailManager
this.mialDataList = {}
function this.Initialize()
end
function this.InitMailDataList(_mialList)
this.mialDataList = {}
for i = 1, #_mialList do
this.UpdateMialData(_mialList[i],true)
end
table.sort(this.mialDataList, function(a, b)
if a.state == b.state then
return a.sendTime > b.sendTime
else
return a.state < b.state
end
end)
end
function this.UpdateSingleMialData(_mial)
this.UpdateMialData(_mial,false)
end
function this.UpdateMialData(_mial,isAdd)
local singleMail = {}
--Log("添加邮件 " .. _mial.mailId)
singleMail.mailId = _mial.mailId--
singleMail.state = _mial.state--0:未读 1:已读取 2: 未领取 3 已领取
local title = string.split(_mial.head,"|")
singleMail.head = title[GetCurLanguage()+1] or title[1]
singleMail.head = this.GetStringByStringformat(singleMail.head)
local content = string.split(_mial.content,"|")
singleMail.content = content[GetCurLanguage()+1] or content[1]--详情
singleMail.content = this.GetStringByStringformat(singleMail.content)
-- --LogGreen("singleMail.content:"..singleMail.content)
singleMail.mailItem = _mial.mailItem--附件 奖励
singleMail.sendTime = _mial.sendTime--
singleMail.effectiveTime = _mial.effectiveTime--秒 0:永久有效
singleMail.sendName = _mial.sendName--发送者名字
singleMail.mailType = _mial.mailType--邮件类型 1:系统邮件 2:idip 业务邮件
singleMail.isTop = _mial.isTop --是否置顶0不置顶1置顶
singleMail.markType = _mial.markType --特殊类型0无类型1站内信
if isAdd then
table.insert(this.mialDataList, singleMail)
else
if this.mialDataList and #this.mialDataList > 0 then
for i = 1, #this.mialDataList do
if this.mialDataList[i].mailId == singleMail.mailId then
this.mialDataList[i] = singleMail
end
end
end
end
end
function this.GetSingleMail(mailId)
if this.mialDataList and #this.mialDataList > 0 then
for i = 1, #this.mialDataList do
if this.mialDataList[i].mailId == mailId then
return this.mialDataList[i]
end
end
end
end
function this.GetStringByStringformat(inputStr)
local msgStr = string.split(inputStr,"#")
--LogGreen("inputStr:"..inputStr)
if #msgStr == 1 then
return GetLanguageStrById(msgStr[1])
end
for i = 2, #msgStr do
--1 需要翻译
local oneStr = string.sub(msgStr[i],1,1)
if tonumber(oneStr) == 1 then
msgStr[i] = tostring(string.sub(msgStr[i],2))
msgStr[i] = GetLanguageStrById(msgStr[i])
else
msgStr[i] = tostring(string.sub(msgStr[i],2))
end
end
local returnStr = string.format(
GetLanguageStrById(msgStr[1]),
tostring(msgStr[2]),
tostring(msgStr[3]),
tostring(msgStr[4]),
tostring(msgStr[5]),
tostring(msgStr[6])
)
-- LogPink("returnStr:"..returnStr)
return returnStr
end
--更新邮件状态
function this.UpdataMialIsReadState(_mailId, _state)
for i = 1, #this.mialDataList do
--Log("_mailId " .. _mailId)
if this.mialDataList[i].mailId == _mailId then
--Log("this.mialDataList[i].mailId " .. this.mialDataList[i].mailId .. " " .. _state)
this.mialDataList[i].state = _state
break
end
end
CheckRedPointStatus(RedPointType.Mail_Local)
end
--删除邮件状态
function this.DelSingleMial(_mailId)
local curmialDataList = {}
for i = 1, #this.mialDataList do
table.insert(curmialDataList,this.mialDataList[i])
end
for i = 1, #curmialDataList do
if curmialDataList[i].mailId == _mailId then
curmialDataList[i] = nil
end
end
this.mialDataList = {}
for i, v in pairs(curmialDataList) do
this.mialDataList[#this.mialDataList+1] = v
end
--CheckRedPointStatus(RedPointType.Mail_Local)
end
--检测邮件红点
function this.GetMailRedPointState()
local isShowRedPoint = false
for i = 1, #this.mialDataList do
if this.mialDataList[i].state == 0 then
isShowRedPoint = true
break
end
end
--LogGreen("检测邮件红点---------"..#this.mialDataList.." 红点状态 "..tostring(isShowRedPoint))
-- 无红点可显示,重置服务器邮件红点
if not isShowRedPoint then
ResetServerRedPointStatus(RedPointType.Mail_Server)
isShowRedPoint = false
end
return isShowRedPoint
end
return this