Compare commits
10 Commits
3051a31136
...
fa63af7c30
| Author | SHA1 | Date | |
|---|---|---|---|
| fa63af7c30 | |||
| 149f930ef9 | |||
| 5cec4d8bb1 | |||
| 36dd81ce1c | |||
| d79377a712 | |||
| 2f061e20dc | |||
| 8a38e51e20 | |||
| bdb131cbfa | |||
| ef3db25cd0 | |||
| ed22622ecd |
124
main.lua
124
main.lua
@@ -23,7 +23,7 @@ local lfs = require("libs/libkoreader-lfs")
|
|||||||
local IrcChatView = TextViewer:extend{
|
local IrcChatView = TextViewer:extend{
|
||||||
title = _("IRC Chat"),
|
title = _("IRC Chat"),
|
||||||
text = "",
|
text = "",
|
||||||
add_default_buttons = false,
|
add_default_buttons = true,
|
||||||
monospace_font = true,
|
monospace_font = true,
|
||||||
text_type = "code",
|
text_type = "code",
|
||||||
keep_running = true, -- keep connection alive when UI is closed
|
keep_running = true, -- keep connection alive when UI is closed
|
||||||
@@ -48,23 +48,67 @@ local IrcChatView = TextViewer:extend{
|
|||||||
}
|
}
|
||||||
|
|
||||||
function IrcChatView:init(reinit)
|
function IrcChatView:init(reinit)
|
||||||
-- Buttons: Send, Close
|
-- Mark UI as open so append/refresh paths repaint immediately
|
||||||
self.buttons_table = {
|
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"),
|
||||||
text = _("Send"),
|
callback = function()
|
||||||
callback = function()
|
self:promptSendMessage()
|
||||||
self:promptSendMessage()
|
end,
|
||||||
end,
|
},
|
||||||
},
|
|
||||||
{
|
|
||||||
text = _("Close"),
|
|
||||||
callback = function()
|
|
||||||
self:onClose()
|
|
||||||
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
|
-- Buffers & title
|
||||||
if not reinit then
|
if not reinit then
|
||||||
self._buffers = {}
|
self._buffers = {}
|
||||||
@@ -267,12 +311,9 @@ function IrcChatView:appendLine(line, target)
|
|||||||
-- Persist to history
|
-- Persist to history
|
||||||
self:writeHistory(target, prefix .. line)
|
self:writeHistory(target, prefix .. line)
|
||||||
if target == (self._current_target or "*") then
|
if target == (self._current_target or "*") then
|
||||||
if self._ui_open and self.scroll_text_w and self.scroll_text_w.text_widget then
|
if self._ui_open then
|
||||||
self.scroll_text_w.text_widget:setText(buf)
|
-- Reuse the same refresh path as the channel switcher
|
||||||
self.scroll_text_w:scrollToBottom()
|
self:refreshView(target)
|
||||||
if UIManager and self.frame and self.frame.dimen then
|
|
||||||
UIManager:setDirty(self, function() return "ui", self.frame.dimen end)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- increment unread counter for background target
|
-- increment unread counter for background target
|
||||||
@@ -416,15 +457,26 @@ function IrcChatView:promptSendMessage()
|
|||||||
dialog = InputDialog:new{
|
dialog = InputDialog:new{
|
||||||
title = _("Send message"),
|
title = _("Send message"),
|
||||||
input = "",
|
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 = {
|
buttons = {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
text = _("Send"),
|
text = _("Send"),
|
||||||
is_default = true,
|
is_default = true,
|
||||||
|
is_enter_default = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
local txt = dialog:getInputText()
|
local txt = dialog:getInputText()
|
||||||
UIManager:close(dialog)
|
-- Update buffer/UI before closing dialog to ensure immediate repaint
|
||||||
self:sendMessage(txt)
|
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,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -440,6 +492,24 @@ function IrcChatView:promptSendMessage()
|
|||||||
dialog:onShowKeyboard(true)
|
dialog:onShowKeyboard(true)
|
||||||
end
|
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()
|
function IrcChatView:receiveLoop()
|
||||||
if self._closing then return end
|
if self._closing then return end
|
||||||
if not self._sock then return end
|
if not self._sock then return end
|
||||||
@@ -590,14 +660,6 @@ function IrcChatView:handleLine(line)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return
|
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
|
elseif command == "376" or command == "422" then
|
||||||
-- End of MOTD / No MOTD: safe to join if not yet joined
|
-- End of MOTD / No MOTD: safe to join if not yet joined
|
||||||
if not self._registered then self._registered = true end
|
if not self._registered then self._registered = true end
|
||||||
|
|||||||
Reference in New Issue
Block a user