[network/neochat] src/libneochat: Allow entering custom image attachment text again

Joshua Goins <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 774bcad30b32d6412abf429f39f2b41b30b83faf by Joshua Goins.
Committed on 03/08/2026 at 20:30.
Pushed by redstrate into branch 'master'.

Allow entering custom image attachment text again

This was caused by a regression related to the image optimization
update, it should now be smarter when to override the name.

BUG: 523671

M  +11   -5    src/libneochat/chatbarcache.cpp

https://invent.kde.org/network/neochat/-/commit/774bcad30b32d6412abf429f39f2b41b30b83faf

diff --git a/src/libneochat/chatbarcache.cpp b/src/libneochat/chatbarcache.cpp
index a8f8231f9..ab853985b 100644
--- a/src/libneochat/chatbarcache.cpp
+++ b/src/libneochat/chatbarcache.cpp
@@ -195,21 +195,27 @@ void ChatBarCache::postMessage(const QString &threadRootId)
                 if (!QDir().exists(imageDir)) {
                     QDir().mkdir(imageDir);
                 }
-                filename = u"%1.%3"_s.arg(QDateTime::currentDateTime().toString(u"yyyy-MM-dd-hh-mm-ss"_s), fileExtension);
-                source = QUrl(u"file://%1/%2"_s.arg(imageDir, filename));
+                QString newFilename = u"%1.%3"_s.arg(QDateTime::currentDateTime().toString(u"yyyy-MM-dd-hh-mm-ss"_s), fileExtension);
+                source = QUrl(u"file://%1/%2"_s.arg(imageDir, newFilename));
+                // Only override if the old filename was the actual filename, and not custom text entered by the user.
+                if (imageItem->source.fileName() == m_cache.toString()) {
+                    filename = newFilename;
+                } else {
+                    filename = m_cache.toString();
+                }
                 if (!image.save(source.toLocalFile())) {
                     qCWarning(ChatBar) << "Failed to save optimized image to" << source << "falling back to the actual source file";
                     source = imageItem->source;
-                    filename = imageItem->filename;
+                    filename = m_cache.toString();
                 }
             } else {
                 source = imageItem->source;
-                filename = imageItem->toString();
+                filename = m_cache.toString();
             }
         } else {
             const auto fileCacheItem = dynamic_cast<const Blocks::UrlCacheItem *>(m_cache.at(0));
             source = fileCacheItem->source;
-            filename = fileCacheItem->toString();
+            filename = m_cache.toString();
         }
 
         m_room->uploadFile(source, filename, relatesTo);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.