diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/ChatScreen.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/ChatScreen.kt index 6a86e4a3..3921df53 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/ChatScreen.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/ui/screens/ChatScreen.kt @@ -105,6 +105,7 @@ fun ChatScreen( var properties by remember(channel.id) { mutableStateOf(false) } var menu by remember(channel.id) { mutableStateOf(false) } val streams by viewModel.streamSources.collectAsState() + val watchSources = streams.filterNot { it.self } val publisher by StreamController.state.collectAsState() val ownStream = publisher?.takeIf { it.ongoing && it.group.toULong().toString() == channel.id } LaunchedEffect(channel.id, ownStream?.id, ownStream?.phase) { @@ -120,7 +121,7 @@ fun ChatScreen( TextButton(onClick = { chooseStream = false; onWatchAllStreams() }) { Text(stringResource(R.string.stream_watch_all)) } - streams.forEach { source -> + watchSources.forEach { source -> TextButton(onClick = { chooseStream = false; onWatchStream(source) }) { Text("${source.displayName} · ${source.id.toULong()}") } @@ -206,9 +207,13 @@ fun ChatScreen( IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, stringResource(R.string.back)) } }, actions = { - IconButton(onClick = { chooseStream = true }) { - BadgedBox(badge = { if (streams.size > 1) Badge { Text(streams.size.toString()) } }) { - Icon(Icons.Filled.LiveTv, stringResource(R.string.stream_available, streams.size), tint = Color(0xFFE53935)) + IconButton(onClick = { + LogManager.addLog("INFO", "stream", "stream chooser channel=${channel.id} " + + "remote=${watchSources.size} ownExcluded=${streams.size - watchSources.size}") + chooseStream = true + }) { + BadgedBox(badge = { if (watchSources.size > 1) Badge { Text(watchSources.size.toString()) } }) { + Icon(Icons.Filled.LiveTv, stringResource(R.string.stream_available, watchSources.size), tint = Color(0xFFE53935)) } } if (ownStream != null) IconButton(onClick = { diff --git a/tools/chatgui/src/messagelist.cpp b/tools/chatgui/src/messagelist.cpp index f22b20e7..44a2a66c 100644 --- a/tools/chatgui/src/messagelist.cpp +++ b/tools/chatgui/src/messagelist.cpp @@ -506,10 +506,8 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent qPrintable(channel), qPrintable(m_currentChannelId)); return; } - DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop selected stream group=%s source=%llx epoch=%llx action=%s", - qPrintable(channel), (unsigned long long)source.id, (unsigned long long)source.epoch, - source.self ? "manage" : "watch"); - if (source.self) { emit streamPublishRequested(channel.toULongLong()); return; } + DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop selected stream group=%s source=%llx epoch=%llx action=watch", + qPrintable(channel), (unsigned long long)source.id, (unsigned long long)source.epoch); emit streamRequested(channel.toULongLong(), source.id, source.epoch, source.name); }; QMenu menu(this); @@ -517,8 +515,10 @@ MessageList::MessageList(DbManager* db, AudioRecorder* recorder, QWidget *parent connect(all, &QAction::triggered, this, [this, channel] { if (channel == m_currentChannelId) emit allStreamsRequested(channel.toULongLong()); }); - if (!m_streamSources.isEmpty()) menu.addSeparator(); + bool first = true; for (const auto& source : m_streamSources) { + if (source.self) continue; + if (first) { menu.addSeparator(); first = false; } auto* action = menu.addAction(QStringLiteral("%1 · %2").arg(source.name).arg(source.id)); connect(action, &QAction::triggered, this, [watch, source] { watch(source); }); } @@ -1611,9 +1611,11 @@ void MessageList::onStreamSources(const uint8_t* data, int len) { DEBUG_WARN(DEBUG_CATEGORY_STREAM, "desktop source catalogue unavailable group=%llx", (unsigned long long)group); return; } m_streamSources = std::move(snapshot.sources); m_streamBtn->show(); - 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()); + const auto remote = std::count_if(m_streamSources.begin(), m_streamSources.end(), [](const LiveStreamSource& source) { return !source.self; }); + m_streamBtn->setText(remote > 1 ? QString::number(remote) : QString()); + m_streamBtn->setToolTip(QCoreApplication::translate("ChatGui", "Live streams: %1").arg(remote)); + DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop stream header group=%llx sources=%d remote=%d", + (unsigned long long)group, (int)m_streamSources.size(), (int)remote); } bool MessageList::enableRadio() {