@@ -8,6 +8,7 @@ local select, pairs, ipairs = select, pairs, ipairs
88local tinsert = table.insert
99local tonumber = tonumber
1010local strsplit = strsplit
11+ local time = time
1112local tDeleteItem = tDeleteItem
1213
1314---- WOW
@@ -25,20 +26,24 @@ local UnitFactionGroup = UnitFactionGroup
2526local UnitFullName = UnitFullName
2627local UnitRace = UnitRace
2728local UnitSex = UnitSex
29+ local GetInboxNumItems = GetInboxNumItems
30+ local GetInboxHeaderInfo = GetInboxHeaderInfo
31+ local GetInboxItemLink = GetInboxItemLink
32+ local GetInboxItem = GetInboxItem
2833
2934---- G
3035local NUM_BAG_SLOTS = NUM_BAG_SLOTS
3136local INVSLOT_LAST_EQUIPPED = INVSLOT_LAST_EQUIPPED
37+ local ATTACHMENTS_MAX_RECEIVE = ATTACHMENTS_MAX_RECEIVE
3238
3339--- @type ns
3440local ns = select (2 , ... )
3541
36- local REALM = ns .REALM
37- local PLAYER = ns .PLAYER
3842local BAGS = ns .GetBags (ns .BAG_ID .BAG )
3943local BANKS = ns .GetBags (ns .BAG_ID .BANK )
4044local MAIL_CONTAINER = ns .MAIL_CONTAINER
4145local EQUIP_CONTAINER = ns .EQUIP_CONTAINER
46+ local COD_CONTAINER = ns .COD_CONTAINER
4247
4348local NO_RESULT = {cached = true }
4449
@@ -62,15 +67,9 @@ local Forever = ns.Addon:NewModule('Forever', 'AceEvent-3.0')
6267function 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
7170end
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' )
129128
130129function 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' )
134133end
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' )
145144end
146145
147146function Forever :MAIL_SHOW ()
148147 self .atMail = true
149- self .Cacher :RemoveCache (REALM , PLAYER , MAIL_CONTAINER )
148+ self .Cacher :RemoveCache (ns . REALM , ns . PLAYER )
150149end
151150
152151function 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
175182end
176183
177184function Forever :BAG_UPDATE (_ , bag )
188195
189196function 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 )
192199end
193200
194201function Forever :ParseItem (link , count , timeout )
0 commit comments