This commit is contained in:
zenith 2026-05-14 17:53:51 -04:00
parent 2977d9ed71
commit 5c76d509d7
3 changed files with 83 additions and 30 deletions

View file

@ -372,6 +372,7 @@ class RoomWidget(urwid.WidgetWrap):
editor = RoomMessageEdit(caption="", edit_text="", multiline=True)
editor.delegate = self
self.editor = editor
urwid.connect_signal(editor, "postchange", self._on_editor_change)
editor_attr = urwid.AttrMap(editor, "msg_editor")
self.link_delegate = _ChatLinkDelegate(self.display, self.hub)
@ -474,6 +475,10 @@ class RoomWidget(urwid.WidgetWrap):
self.messagelist = IndicativeListBox(widgets, position=len(widgets)-1)
self.messagelist.name = "messagelist"
try:
self.messagelist._listbox.set_focus_valign("bottom")
except Exception:
pass
if replace and hasattr(self, "frame"):
self.frame.contents["body"] = (self.messagelist, None)
if hasattr(self, "users_pile"):
@ -495,6 +500,7 @@ class RoomWidget(urwid.WidgetWrap):
del body[0]
try:
self.messagelist._listbox.set_focus(len(body)-1)
self.messagelist._listbox.set_focus_valign("bottom")
except Exception:
pass
except Exception as e:
@ -503,6 +509,17 @@ class RoomWidget(urwid.WidgetWrap):
if hasattr(self, "users_pile"):
self._refresh_users_pane()
def _on_editor_change(self, editor, old_text):
if self.messagelist is None:
return
try:
body = self.messagelist._listbox.body
if len(body) > 0:
self.messagelist._listbox.set_focus(len(body)-1)
self.messagelist._listbox.set_focus_valign("bottom")
except Exception:
pass
def send_message(self):
text = self.editor.get_edit_text()
if not text.strip():

View file

@ -1798,32 +1798,34 @@ class ClickableAttachment(urwid.Text):
self.set_text(" "+g["cross"]+" Save failed: "+str(e))
def _copy_attachment_to_dest(filename, src_path):
def _resolve_attachment_save_path(filename):
app = nomadnet.NomadNetworkApp.get_shared_instance()
save_dir = app.attachment_save_path if app.attachment_save_path else app.downloads_path
if not os.path.isdir(save_dir):
os.makedirs(save_dir)
save_path = os.path.join(save_dir, filename)
safe_name = ConversationMessage.safe_attachment_name(filename)
base_dir = os.path.realpath(save_dir) + os.sep
candidate = os.path.realpath(os.path.join(save_dir, safe_name))
if not (candidate + os.sep).startswith(base_dir):
raise OSError(13, os.strerror(13))
counter = 0
base, ext = os.path.splitext(filename)
while os.path.isfile(save_path):
base, ext = os.path.splitext(safe_name)
while os.path.isfile(candidate):
counter += 1
save_path = os.path.join(save_dir, base+"_"+str(counter)+ext)
candidate = os.path.realpath(os.path.join(save_dir, base+"_"+str(counter)+ext))
if not (candidate + os.sep).startswith(base_dir):
raise OSError(13, os.strerror(13))
return candidate
def _copy_attachment_to_dest(filename, src_path):
save_path = _resolve_attachment_save_path(filename)
shutil.copy2(src_path, save_path)
return save_path
def _save_attachment_to_disk(filename, data):
app = nomadnet.NomadNetworkApp.get_shared_instance()
save_dir = app.attachment_save_path if app.attachment_save_path else app.downloads_path
if not os.path.isdir(save_dir):
os.makedirs(save_dir)
save_path = os.path.join(save_dir, filename)
counter = 0
base, ext = os.path.splitext(filename)
while os.path.isfile(save_path):
counter += 1
save_path = os.path.join(save_dir, base+"_"+str(counter)+ext)
save_path = _resolve_attachment_save_path(filename)
with open(save_path, "wb") as f:
f.write(data)
return save_path