irc: standardize history dir to host_port; add legacy name_host_port fallback when loading
Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
22
main.lua
22
main.lua
@@ -93,6 +93,15 @@ function IrcChatView:sanitizePathPart(part)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function IrcChatView:getServerId()
|
function IrcChatView:getServerId()
|
||||||
|
-- Stable ID independent of display name
|
||||||
|
local host = self._server and (self._server.host or "") or ""
|
||||||
|
local port = self._server and tostring(self._server.port or 6667) or "6667"
|
||||||
|
local id = string.format("%s_%s", host, port)
|
||||||
|
return self:sanitizePathPart(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
function IrcChatView:getLegacyServerId()
|
||||||
|
-- Old scheme: name_host_port (used briefly); try loading history from there, if present
|
||||||
local name = self._server and (self._server.name or "") or ""
|
local name = self._server and (self._server.name or "") or ""
|
||||||
local host = self._server and (self._server.host or "") or ""
|
local host = self._server and (self._server.host or "") or ""
|
||||||
local port = self._server and tostring(self._server.port or 6667) or "6667"
|
local port = self._server and tostring(self._server.port or 6667) or "6667"
|
||||||
@@ -105,6 +114,8 @@ function IrcChatView:initHistory()
|
|||||||
lfs.mkdir(self._history_dir)
|
lfs.mkdir(self._history_dir)
|
||||||
self._history_server_dir = self._history_dir .. "/" .. self:getServerId()
|
self._history_server_dir = self._history_dir .. "/" .. self:getServerId()
|
||||||
lfs.mkdir(self._history_server_dir)
|
lfs.mkdir(self._history_server_dir)
|
||||||
|
-- Legacy path support
|
||||||
|
self._history_server_dir_legacy = self._history_dir .. "/" .. self:getLegacyServerId()
|
||||||
end
|
end
|
||||||
|
|
||||||
function IrcChatView:getLogPath(target)
|
function IrcChatView:getLogPath(target)
|
||||||
@@ -113,6 +124,12 @@ function IrcChatView:getLogPath(target)
|
|||||||
return string.format("%s/%s.log", self._history_server_dir, fname)
|
return string.format("%s/%s.log", self._history_server_dir, fname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function IrcChatView:getLegacyLogPath(target)
|
||||||
|
target = target or "*"
|
||||||
|
local fname = target == "*" and "console" or self:sanitizePathPart(target)
|
||||||
|
return string.format("%s/%s.log", self._history_server_dir_legacy, fname)
|
||||||
|
end
|
||||||
|
|
||||||
function IrcChatView:writeHistory(target, line)
|
function IrcChatView:writeHistory(target, line)
|
||||||
local path = self:getLogPath(target)
|
local path = self:getLogPath(target)
|
||||||
local f = io.open(path, "a")
|
local f = io.open(path, "a")
|
||||||
@@ -163,6 +180,11 @@ function IrcChatView:preloadHistory(target)
|
|||||||
if self._buffers[target] and #self._buffers[target] > 0 then return end
|
if self._buffers[target] and #self._buffers[target] > 0 then return end
|
||||||
local path = self:getLogPath(target)
|
local path = self:getLogPath(target)
|
||||||
local content = self:readLastLines(path, self._history_preload_lines)
|
local content = self:readLastLines(path, self._history_preload_lines)
|
||||||
|
if (not content or #content == 0) and self._history_server_dir_legacy then
|
||||||
|
-- Fallback to legacy path if it exists
|
||||||
|
local lpath = self:getLegacyLogPath(target)
|
||||||
|
content = self:readLastLines(lpath, self._history_preload_lines)
|
||||||
|
end
|
||||||
if content and #content > 0 then
|
if content and #content > 0 then
|
||||||
self._buffers[target] = content
|
self._buffers[target] = content
|
||||||
if target == (self._current_target or "*") and self.scroll_text_w and self.scroll_text_w.text_widget then
|
if target == (self._current_target or "*") and self.scroll_text_w and self.scroll_text_w.text_widget then
|
||||||
|
|||||||
Reference in New Issue
Block a user