Show the group stream icon only for active broadcasts

Open a single active stream directly and show a selection for multiple streams. Move stream publishing and management into the group menu.
This commit is contained in:
evgeny committed 2026-10-19 12:51:56 +02:00
1 parent ffe563bb9f
commit 62633bc924
1 file changed
+21 -12
+21 -12
View File
@@ -499,19 +499,24 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
m_streamBtn->setAccessibleName(QCoreApplication::translate("ChatGui", "Live streams"));
m_streamBtn->setCursor(Qt::PointingHandCursor);
connect(m_streamBtn, &QPushButton::clicked, this, [this] {
auto watch = [this](const LiveSource& source) {
if (source.self) { emit streamPublishRequested(m_currentChannelId.toULongLong()); return; }
const QString channel = m_currentChannelId;
auto watch = [this, channel](const LiveSource& source) {
if (channel != m_currentChannelId) {
DEBUG_WARN(DEBUG_CATEGORY_STREAM, "desktop stream selection: channel changed old=%s current=%s",
qPrintable(channel), qPrintable(m_currentChannelId));
return;
}
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop selected stream group=%s source=%llx epoch=%llx",
qPrintable(m_currentChannelId), (unsigned long long)source.id, (unsigned long long)source.epoch);
emit streamRequested(m_currentChannelId.toULongLong(), source.id, source.epoch, source.name);
qPrintable(channel), (unsigned long long)source.id, (unsigned long long)source.epoch);
emit streamRequested(channel.toULongLong(), source.id, source.epoch, source.name);
};
if (m_streamSources.size() == 1) { watch(m_streamSources.first()); return; }
if (m_streamSources.isEmpty()) {
DEBUG_WARN(DEBUG_CATEGORY_STREAM, "desktop stream selection: no active sources group=%s", qPrintable(channel));
return;
}
QMenu menu(this);
bool own = std::any_of(m_streamSources.begin(), m_streamSources.end(), [](const LiveSource& source) { return source.self; });
auto* publish = menu.addAction(QCoreApplication::translate("ChatGui", own ? "Manage stream" : "Start stream"));
connect(publish, &QAction::triggered, this, [this] { emit streamPublishRequested(m_currentChannelId.toULongLong()); });
if (!m_streamSources.isEmpty()) menu.addSeparator();
for (const auto& source : m_streamSources) {
if (source.self) continue;
auto* action = menu.addAction(QStringLiteral("%1 · %2").arg(source.name).arg(source.id));
connect(action, &QAction::triggered, this, [watch, source] { watch(source); });
}
@@ -532,6 +537,9 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
if (!channel.toULongLong()) return;
auto text = [](const char* s) { return QCoreApplication::translate("ChatGui", s); };
QMenu menu(this);
const bool own = std::any_of(m_streamSources.begin(), m_streamSources.end(), [](const LiveSource& source) { return source.self; });
auto* publish = menu.addAction(text(own ? "Manage stream" : "Start stream"));
menu.addSeparator();
auto* files = menu.addAction(text("Group files"));
auto* ownFiles = menu.addAction(text("My files"));
auto* poll = menu.addAction(text("Create poll"));
@@ -551,7 +559,8 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent
return;
}
DEBUG_INFO(DEBUG_CATEGORY_CHAT, "group menu: channel=%s action=%s", qPrintable(channel), qPrintable(action->text()));
if (action == files) emit filesRequested(channel);
if (action == publish) emit streamPublishRequested(channel.toULongLong());
else if (action == files) emit filesRequested(channel);
else if (action == ownFiles) emit ownFilesRequested(channel);
else if (action == poll) createPoll();
else if (action == share) emit shareInviteRequested(channel);
@@ -1554,7 +1563,7 @@ void MessageList::watchStreams() {
void MessageList::clearStreams() {
m_streamSources.clear(); m_streamBtn->setText(QString());
m_streamBtn->setVisible(!m_currentChannelId.isEmpty() && !isDmChannel(m_currentChannelId));
m_streamBtn->hide();
m_streamBtn->setToolTip(QCoreApplication::translate("ChatGui", "Live streams"));
}
@@ -1582,7 +1591,7 @@ void MessageList::onStreamSources(const uint8_t* data, int len) {
QString name = member.value("name").toString(); if (name.isEmpty()) name = QString::number(id);
sources.push_back({id, epoch, name, member.value("self").toInt() != 0});
}
m_streamSources = std::move(sources); m_streamBtn->setVisible(true);
m_streamSources = std::move(sources); m_streamBtn->setVisible(!m_streamSources.isEmpty());
m_streamBtn->setText(m_streamSources.size() > 1 ? QString::number(m_streamSources.size()) : QString());
m_streamBtn->setToolTip(QCoreApplication::translate("ChatGui", "Live streams: %1").arg(m_streamSources.size()));
DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop stream header group=%llx sources=%d", (unsigned long long)group, (int)m_streamSources.size());