Skip to content

Commit ec568ea

Browse files
committed
feat: Distinguish between COD and mails
1 parent 5e69f4c commit ec568ea

5 files changed

Lines changed: 32 additions & 21 deletions

File tree

Cache/Forever.lua

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local select, pairs, ipairs = select, pairs, ipairs
88
local tinsert = table.insert
99
local tonumber = tonumber
1010
local strsplit = strsplit
11+
local time = time
1112
local tDeleteItem = tDeleteItem
1213

1314
---- WOW
@@ -25,20 +26,24 @@ local UnitFactionGroup = UnitFactionGroup
2526
local UnitFullName = UnitFullName
2627
local UnitRace = UnitRace
2728
local UnitSex = UnitSex
29+
local GetInboxNumItems = GetInboxNumItems
30+
local GetInboxHeaderInfo = GetInboxHeaderInfo
31+
local GetInboxItemLink = GetInboxItemLink
32+
local GetInboxItem = GetInboxItem
2833

2934
---- G
3035
local NUM_BAG_SLOTS = NUM_BAG_SLOTS
3136
local INVSLOT_LAST_EQUIPPED = INVSLOT_LAST_EQUIPPED
37+
local ATTACHMENTS_MAX_RECEIVE = ATTACHMENTS_MAX_RECEIVE
3238

3339
---@type ns
3440
local ns = select(2, ...)
3541

36-
local REALM = ns.REALM
37-
local PLAYER = ns.PLAYER
3842
local BAGS = ns.GetBags(ns.BAG_ID.BAG)
3943
local BANKS = ns.GetBags(ns.BAG_ID.BANK)
4044
local MAIL_CONTAINER = ns.MAIL_CONTAINER
4145
local EQUIP_CONTAINER = ns.EQUIP_CONTAINER
46+
local COD_CONTAINER = ns.COD_CONTAINER
4247

4348
local NO_RESULT = {cached = true}
4449

@@ -62,15 +67,9 @@ local Forever = ns.Addon:NewModule('Forever', 'AceEvent-3.0')
6267
function Forever:OnInitialize()
6368
self.Cacher = ns.Cacher:New()
6469
self.Cacher:Patch(self, 'GetBagInfo', 'GetOwnerInfo', 'GetItemInfo')
65-
66-
if IsLoggedIn() then
67-
self:PLAYER_LOGIN()
68-
else
69-
self:RegisterEvent('PLAYER_LOGIN')
70-
end
7170
end
7271

73-
function Forever:PLAYER_LOGIN()
72+
function Forever:OnEnable()
7473
self:SetupCache()
7574
self:SetupEvents()
7675
self:UpdateData()
@@ -84,8 +83,8 @@ function Forever:SetupCache()
8483
self.realm = self.db[realm]
8584
self.realm[player] = self.realm[player] or {}
8685
self.player = self.realm[player]
86+
8787
self.player[EQUIP_CONTAINER] = self.player[EQUIP_CONTAINER] or {}
88-
self.player[MAIL_CONTAINER] = self.player[MAIL_CONTAINER] or {}
8988

9089
self.player.faction = UnitFactionGroup('player')
9190
self.player.class = UnitClassBase('player')
@@ -129,7 +128,7 @@ end
129128

130129
function Forever:BANKFRAME_OPENED()
131130
self.atBank = true
132-
self.Cacher:RemoveCache(REALM, PLAYER)
131+
self.Cacher:RemoveCache(ns.REALM, ns.PLAYER)
133132
self:SendMessage('BANK_OPENED')
134133
end
135134

@@ -138,40 +137,48 @@ function Forever:BANKFRAME_CLOSED()
138137
for _, bag in ipairs(ns.GetBags(ns.BAG_ID.BANK)) do
139138
self:SaveBag(bag)
140139
end
141-
self.Cacher:RemoveCache(REALM, PLAYER)
140+
self.Cacher:RemoveCache(ns.REALM, ns.PLAYER)
142141
self.atBank = nil
143142
end
144143
self:SendMessage('BANK_CLOSED')
145144
end
146145

147146
function Forever:MAIL_SHOW()
148147
self.atMail = true
149-
self.Cacher:RemoveCache(REALM, PLAYER, MAIL_CONTAINER)
148+
self.Cacher:RemoveCache(ns.REALM, ns.PLAYER)
150149
end
151150

152151
function Forever:MAIL_CLOSED()
153152
if self.atMail then
154-
local db = wipe(self.player[MAIL_CONTAINER])
153+
local mails = {}
154+
local cods = {}
155155
local now = time()
156156

157157
local num, total = GetInboxNumItems()
158158
for i = 1, num do
159-
local daysLeft = select(7, GetInboxHeaderInfo(i))
159+
local codAmount, daysLeft = select(6, GetInboxHeaderInfo(i))
160160
local timeout = now + daysLeft * 86400
161+
local isCod = codAmount > 0
162+
161163
for j = 1, ATTACHMENTS_MAX_RECEIVE do
162164
local link = GetInboxItemLink(i, j)
163165
if link then
164166
local count = select(4, GetInboxItem(i, j))
165167

166-
tinsert(db, self:ParseItem(link, count, timeout))
168+
tinsert(isCod and cods or mails, self:ParseItem(link, count, timeout))
167169
end
168170
end
169171
end
170172

171-
db.size = #db
172-
self.Cacher:RemoveCache(REALM, PLAYER, MAIL_CONTAINER)
173-
self.atMail = nil
173+
mails.size = #mails
174+
cods.size = #cods
175+
176+
self.player[MAIL_CONTAINER] = mails
177+
self.player[COD_CONTAINER] = mails
178+
179+
self.Cacher:RemoveCache(ns.REALM, ns.PLAYER)
174180
end
181+
self.atMail = nil
175182
end
176183

177184
function Forever:BAG_UPDATE(_, bag)
@@ -188,7 +195,7 @@ end
188195

189196
function Forever:PLAYER_EQUIPMENT_CHANGED(_, slot)
190197
self:SaveEquip(slot)
191-
self.Cacher:RemoveCache(REALM, PLAYER, EQUIP_CONTAINER, slot)
198+
self.Cacher:RemoveCache(ns.REALM, ns.PLAYER, EQUIP_CONTAINER, slot)
192199
end
193200

194201
function Forever:ParseItem(link, count, timeout)

Core/Counter.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ end
4141
function Counter:GetOwnerItemCount(owner, itemId)
4242
local info = Cache:GetOwnerInfo(owner)
4343
local mails = self:GetBagItemCount(owner, ns.MAIL_CONTAINER, itemId)
44+
local cods = self:GetBagItemCount(owner, ns.COD_CONTAINER, itemId)
4445
local equipInBag = self:GetEquippedBagCount(owner, ns.BAG_ID.BAG, itemId)
4546
local equipInBank = self:GetEquippedBagCount(owner, ns.BAG_ID.BANK, itemId)
4647
local equip = self:GetBagItemCount(owner, ns.EQUIP_CONTAINER, itemId)
@@ -63,7 +64,7 @@ function Counter:GetOwnerItemCount(owner, itemId)
6364

6465
equip = equip + equipInBag + equipInBank
6566

66-
return {equip, bags, banks, mails, cached = info.cached}
67+
return {equip, bags, banks, mails, cods, cached = info.cached}
6768
end
6869

6970
function Counter:GetOwnerItemTotal(owner, itemId)

Core/Tooltip.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Tooltip.SPACES = {
3939
L['Inventory'], --
4040
L['Bank'], --
4141
L['Mail'], --
42+
L['COD'],
4243
}
4344

4445
function Tooltip:OnInitialize()

Localization/enUS.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ L['Equipped'] = true
1919
L['Inventory'] = true
2020
L['Bank'] = true
2121
L['Mail'] = true
22+
L['COD'] = true
2223

2324
L.TOOLTIP_CHANGE_PLAYER = 'View another character\'s items.'
2425
L.TOOLTIP_RETURN_TO_SELF = 'Return to the current character.'

Localization/zhCN.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ L['Equipped'] = '装备'
1717
L['Inventory'] = '背包'
1818
L['Bank'] = '银行'
1919
L['Mail'] = '邮箱'
20+
L['COD'] = true
2021

2122
L.TOOLTIP_CHANGE_PLAYER = '查看其他角色的物品'
2223
L.TOOLTIP_RETURN_TO_SELF = '返回到当前角色'

0 commit comments

Comments
 (0)