From 60db4a97c1b07287df7ee36804c8302f5fa736ef Mon Sep 17 00:00:00 2001 From: Slendi Date: Sat, 20 Sep 2025 02:00:00 +0300 Subject: [PATCH] irc: standardize history dir to host_port; add legacy name_host_port fallback when loading Signed-off-by: Slendi --- main.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/main.lua b/main.lua index eae864c..53f010a 100644 --- a/main.lua +++ b/main.lua @@ -93,6 +93,15 @@ function IrcChatView:sanitizePathPart(part) end 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 host = self._server and (self._server.host or "") or "" 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) self._history_server_dir = self._history_dir .. "/" .. self:getServerId() lfs.mkdir(self._history_server_dir) + -- Legacy path support + self._history_server_dir_legacy = self._history_dir .. "/" .. self:getLegacyServerId() end function IrcChatView:getLogPath(target) @@ -113,6 +124,12 @@ function IrcChatView:getLogPath(target) return string.format("%s/%s.log", self._history_server_dir, fname) 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) local path = self:getLogPath(target) 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 local path = self:getLogPath(target) 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 self._buffers[target] = content if target == (self._current_target or "*") and self.scroll_text_w and self.scroll_text_w.text_widget then