Quantcast

Add an option to not display 'old' messages

James Whitehead II [01-13-11 - 17:48]
Add an option to not display 'old' messages
Filename
CaptainsLog.lua
diff --git a/CaptainsLog.lua b/CaptainsLog.lua
index 5ffd31e..501e590 100644
--- a/CaptainsLog.lua
+++ b/CaptainsLog.lua
@@ -15,6 +15,9 @@ local C = {
     raid = RAID,
 }

+local MINUTE = 60
+local HOUR = MINUTE * 60
+
 function addon:Initialize()
     self.db = LibStub("AceDB-3.0"):New("CaptainsLogDB", {
         char = {
@@ -25,8 +28,9 @@ function addon:Initialize()
         profile = {
             timestamp = true,
             timestamp_format = "%H:%M ",
+            msg_life = 6 * HOUR,
             buffersize = {
-                ["*"] = 10,
+                ["*"] = 15,
             },
             ignoreself = {
                 ["*"] = true,
@@ -135,6 +139,8 @@ function addon:PopulateTooltip(tooltip)
     end
     table.sort(sort)

+    local now = time()
+
     for idx, mtype in ipairs(sort) do
         if addon.db.profile.showintooltip[mtype] then
             local color = ChatTypeInfo[colorMap[mtype]] or {}
@@ -145,19 +151,25 @@ function addon:PopulateTooltip(tooltip)

             tooltip:AddLine(C[mtype] or mtype)

+            local msgShown = false
             if #self.messages[mtype] > 0 then
-                for idx, msg in ipairs(self.messages[mtype]) do
-                    local timestamp = " "
-                    if addon.db.profile.timestamp then
-                        timestamp = date(addon.db.profile.timestamp_format, msg[1])
+                for idx = 1, #self.messages[mtype], 1 do
+                    local msg = self.messages[mtype][idx]
+                    if now <= msg[1] + addon.db.profile.msg_life then
+                        msgShown = true
+                        local timestamp = " "
+                        if addon.db.profile.timestamp then
+                            timestamp = date(addon.db.profile.timestamp_format, msg[1])
+                        end
+
+                        tooltip:AddLine(
+                        string.format("%s[%s]: %s", timestamp, msg[2], msg[3]),
+                        color.r, color.g, color.b
+                        )
                     end
-
-                    tooltip:AddLine(
-                    string.format("%s[%s]: %s", timestamp, msg[2], msg[3]),
-                    color.r, color.g, color.b
-                    )
                 end
-            else
+            end
+            if not msgShown then
                 tooltip:AddLine(L["No messages"])
             end
         end