Compare commits
10 Commits
3051a31136
...
fa63af7c30
| Author | SHA1 | Date | |
|---|---|---|---|
| fa63af7c30 | |||
| 149f930ef9 | |||
| 5cec4d8bb1 | |||
| 36dd81ce1c | |||
| d79377a712 | |||
| 2f061e20dc | |||
| 8a38e51e20 | |||
| bdb131cbfa | |||
| ef3db25cd0 | |||
| ed22622ecd |
102
main.lua
102
main.lua
@@ -23,7 +23,7 @@ local lfs = require("libs/libkoreader-lfs")
|
||||
local IrcChatView = TextViewer:extend{
|
||||
title = _("IRC Chat"),
|
||||
text = "",
|
||||
add_default_buttons = false,
|
||||
add_default_buttons = true,
|
||||
monospace_font = true,
|
||||
text_type = "code",
|
||||
keep_running = true, -- keep connection alive when UI is closed
|
||||
@@ -48,23 +48,67 @@ local IrcChatView = TextViewer:extend{
|
||||
}
|
||||
|
||||
function IrcChatView:init(reinit)
|
||||
-- Buttons: Send, Close
|
||||
self.buttons_table = {
|
||||
{
|
||||
-- Mark UI as open so append/refresh paths repaint immediately
|
||||
self._ui_open = true
|
||||
-- Build buttons: first our Send row, then TextViewer's default row
|
||||
-- Disable TextViewer's automatic default buttons to avoid duplication
|
||||
self.add_default_buttons = false
|
||||
local send_row = {
|
||||
{
|
||||
text = _("Send"),
|
||||
callback = function()
|
||||
self:promptSendMessage()
|
||||
end,
|
||||
},
|
||||
}
|
||||
local default_row = {
|
||||
{
|
||||
text = _("Find"),
|
||||
id = "find",
|
||||
callback = function()
|
||||
if self._find_next then
|
||||
self:findCallback()
|
||||
else
|
||||
self:findDialog()
|
||||
end
|
||||
end,
|
||||
hold_callback = function()
|
||||
if self._find_next then
|
||||
self:findDialog()
|
||||
else
|
||||
if self.default_hold_callback then
|
||||
self.default_hold_callback()
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = "⇱",
|
||||
id = "top",
|
||||
callback = function()
|
||||
if self.scroll_text_w then self.scroll_text_w:scrollToTop() end
|
||||
end,
|
||||
hold_callback = self.default_hold_callback,
|
||||
allow_hold_when_disabled = true,
|
||||
},
|
||||
{
|
||||
text = "⇲",
|
||||
id = "bottom",
|
||||
callback = function()
|
||||
if self.scroll_text_w then self.scroll_text_w:scrollToBottom() end
|
||||
end,
|
||||
hold_callback = self.default_hold_callback,
|
||||
allow_hold_when_disabled = true,
|
||||
},
|
||||
{
|
||||
text = _("Close"),
|
||||
callback = function()
|
||||
self:onClose()
|
||||
end,
|
||||
hold_callback = self.default_hold_callback,
|
||||
},
|
||||
}
|
||||
}
|
||||
self.buttons_table = { send_row, default_row }
|
||||
-- Buffers & title
|
||||
if not reinit then
|
||||
self._buffers = {}
|
||||
@@ -267,12 +311,9 @@ function IrcChatView:appendLine(line, target)
|
||||
-- Persist to history
|
||||
self:writeHistory(target, prefix .. line)
|
||||
if target == (self._current_target or "*") then
|
||||
if self._ui_open and self.scroll_text_w and self.scroll_text_w.text_widget then
|
||||
self.scroll_text_w.text_widget:setText(buf)
|
||||
self.scroll_text_w:scrollToBottom()
|
||||
if UIManager and self.frame and self.frame.dimen then
|
||||
UIManager:setDirty(self, function() return "ui", self.frame.dimen end)
|
||||
end
|
||||
if self._ui_open then
|
||||
-- Reuse the same refresh path as the channel switcher
|
||||
self:refreshView(target)
|
||||
end
|
||||
else
|
||||
-- increment unread counter for background target
|
||||
@@ -416,15 +457,26 @@ function IrcChatView:promptSendMessage()
|
||||
dialog = InputDialog:new{
|
||||
title = _("Send message"),
|
||||
input = "",
|
||||
-- Keep single-line input semantics on Enter, but expand the box
|
||||
use_available_height = true, -- expand input to available height
|
||||
condensed = true, -- reduce extra padding to maximize text area
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Send"),
|
||||
is_default = true,
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
local txt = dialog:getInputText()
|
||||
UIManager:close(dialog)
|
||||
-- Update buffer/UI before closing dialog to ensure immediate repaint
|
||||
self:sendMessage(txt)
|
||||
UIManager:close(dialog)
|
||||
-- And schedule a focused refresh after the dialog is gone
|
||||
if UIManager and self._ui_open then
|
||||
UIManager:nextTick(function()
|
||||
self:refreshView(self._current_target or "*")
|
||||
end)
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -440,6 +492,24 @@ function IrcChatView:promptSendMessage()
|
||||
dialog:onShowKeyboard(true)
|
||||
end
|
||||
|
||||
function IrcChatView:refreshView(target)
|
||||
target = target or self._current_target or "*"
|
||||
if not self._ui_open then return end
|
||||
self:preloadHistory(target)
|
||||
if self.scroll_text_w and self.scroll_text_w.text_widget then
|
||||
local s = self._buffers[target] or ""
|
||||
self.text = s
|
||||
self.scroll_text_w.text_widget:setText(s)
|
||||
self.scroll_text_w:scrollToBottom()
|
||||
if self.scroll_text_w.updateScrollBar then
|
||||
self.scroll_text_w:updateScrollBar(true)
|
||||
end
|
||||
end
|
||||
if UIManager and self.frame and self.frame.dimen then
|
||||
UIManager:setDirty(self, function() return "ui", self.frame.dimen end)
|
||||
end
|
||||
end
|
||||
|
||||
function IrcChatView:receiveLoop()
|
||||
if self._closing then return end
|
||||
if not self._sock then return end
|
||||
@@ -590,14 +660,6 @@ function IrcChatView:handleLine(line)
|
||||
end
|
||||
end
|
||||
return
|
||||
elseif command == "NICK" then -- someone changed nick; update ours if it's us
|
||||
local newnick = rest:match("^:(.+)$") or rest
|
||||
local oldnick = prefix:match("^([^!]+)!") or prefix
|
||||
if oldnick == self._nick and newnick and #newnick > 0 then
|
||||
self._nick = newnick
|
||||
self:appendLine(T(_("You are now known as %1"), newnick))
|
||||
end
|
||||
return
|
||||
elseif command == "376" or command == "422" then
|
||||
-- End of MOTD / No MOTD: safe to join if not yet joined
|
||||
if not self._registered then self._registered = true end
|
||||
|
||||
Reference in New Issue
Block a user