fix: item list

This commit is contained in:
Salikh Gurgenidze
2025-12-27 18:13:04 +04:00
parent 5f0ade6013
commit a62d949f30
3 changed files with 152 additions and 49 deletions
+49 -17
View File
@@ -19,20 +19,25 @@ function MailboxScanner:ScanMailbox()
local numItems = GetInboxNumItems()
for i = 1, numItems do
mailboxData[i] = self:ScanMailItem(i)
local mailRows = self:ScanMailItemRows(i)
for _, row in ipairs(mailRows) do
table.insert(mailboxData, row)
end
end
return mailboxData
end
-- Scan a single mail item
function MailboxScanner:ScanMailItem(index)
-- Scan a single mail into one or more rows (flattened)
function MailboxScanner:ScanMailItemRows(index)
-- GetInboxHeaderInfo(index) returns: packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM
local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM = GetInboxHeaderInfo(index)
local items = {}
local rows = {}
if hasItem then
-- Turtle WoW supports up to 12 attachments per mail
-- GetInboxItem(index, itemIndex) returns: name, texture, count, quality, canUse
local name, texture, count, quality, canUse = GetInboxItem(index, itemIndex)
if name then
@@ -60,22 +65,41 @@ function MailboxScanner:ScanMailItem(index)
if itemTexture then itemData.texture = itemTexture end
end
end
table.insert(items, itemData)
table.insert(rows, {
sender = sender,
subject = subject,
money = (itemIndex == 1) and money or 0, -- Attach money only to the first row of this mail
CODAmount = (itemIndex == 1) and CODAmount or 0,
daysLeft = daysLeft,
hasItem = true,
item = itemData,
mailIndex = index,
itemIndex = itemIndex,
wasRead = wasRead,
packageIcon = packageIcon,
})
end
end
return {
sender = sender,
subject = subject,
money = money,
CODAmount = CODAmount,
daysLeft = daysLeft,
hasItem = (table.getn(items) > 0),
item = items[1],
items = items,
wasRead = wasRead,
packageIcon = packageIcon,
}
-- If no items found but there is money or it's just a letter
if table.getn(rows) == 0 then
table.insert(rows, {
sender = sender,
subject = subject,
money = money,
CODAmount = CODAmount,
daysLeft = daysLeft,
hasItem = false,
item = nil,
mailIndex = index,
itemIndex = 1,
wasRead = wasRead,
packageIcon = packageIcon,
})
end
return rows
end
-- Save current mailbox to database
@@ -118,6 +142,14 @@ function MailboxScanner:Initialize()
end
end, "MailboxScanner")
-- Register for MAIL_INBOX_UPDATE to detect when mail content changes
addon.Modules.Events:Register("MAIL_INBOX_UPDATE", function()
if mailboxOpen then
addon:Debug("MAIL_INBOX_UPDATE: Refreshing mailbox")
MailboxScanner:SaveToDatabase()
end
end, "MailboxScanner")
-- Register for UI_ERROR_MESSAGE to handle "item not found" situations if needed
-- (Some items might not be in cache and fail silently otherwise)