Use channel member snapshots for desktop participant details

This commit is contained in:
evgeny committed 2026-10-25 20:04:59 +01:00
1 parent 1a73e3588f
commit ea73fa271c
18 files changed
+586 -444

No files matched your search

+50 -46
View File
@@ -17,14 +17,14 @@ extern "C" {
static void applyPhoto(MemberListItem& item, const QString& channel) {
auto* manager = AvatarManager::instance(); if (!manager) return;
const QImage image = manager->image(channel, item.nodeId); if (image.isNull()) return;
const QImage image = manager->image(channel, item.snapshot.node_id); if (image.isNull()) return;
const int size = MemberListModel::kAvatarSize;
QPixmap pixmap(size, size); pixmap.fill(Qt::transparent);
QPainter painter(&pixmap); painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
QPainterPath clip; clip.addEllipse(QRectF(0, 0, size, size)); painter.setClipPath(clip);
painter.drawImage(QRect(0, 0, size, size), image); painter.setClipping(false);
const QColor statusColor = item.online ? QColor("#4CAF50") : QColor("#9E9E9E");
const QColor statusColor = item.snapshot.online ? QColor("#4CAF50") : QColor("#9E9E9E");
painter.setPen(QPen(statusColor, 1)); painter.setBrush(statusColor);
painter.drawEllipse(QRect(size - 9, size - 9, 8, 8)); painter.end(); item.avatar = pixmap;
}
@@ -36,7 +36,7 @@ MemberListModel::MemberListModel(QObject* parent)
if (auto* manager = AvatarManager::instance()) connect(manager, &AvatarManager::changed, this,
[this](const QString& channel, quint64 owner) {
if (channel != m_channelId) return;
for (auto it = m_cache.begin(); it != m_cache.end(); ++it) if (it->nodeId == owner) {
for (auto it = m_cache.begin(); it != m_cache.end(); ++it) if (it->snapshot.node_id == owner) {
applyPhoto(*it, channel); emit dataChanged(index(it.key()), index(it.key()), {Qt::DecorationRole});
}
});
@@ -60,61 +60,58 @@ QVariant MemberListModel::data(const QModelIndex& index, int role) const {
if (role == Qt::DecorationRole) return QVariant::fromValue(QIcon(it->avatar));
if (role == Qt::UserRole + 1) {
QString sub;
if (it->rtt >= 0) sub += QString("rtt=%1ms").arg(it->rtt / 10);
if (it->natType >= 0) {
if (it->snapshot.rtt != 0xffff) sub += QString("rtt=%1ms").arg(it->snapshot.rtt / 10);
if (it->snapshot.nat_type != 0xff) {
static const char* nat[] = {"NET","DIR","EIM","DEP","NAT?","CONTACT","EIM?"};
const char* nt = (it->natType <= 6) ? nat[it->natType] : "?";
const char* nt = (it->snapshot.nat_type <= 6) ? nat[it->snapshot.nat_type] : "?";
if (!sub.isEmpty()) sub += " ";
sub += nt;
}
return sub;
}
if (role == Qt::ToolTipRole)
return (it->online ? QCoreApplication::translate("ChatGui",
return (it->snapshot.online ? QCoreApplication::translate("ChatGui",
"online") : QCoreApplication::translate("ChatGui",
"offline")) + " | 0x" +
QString("%1").arg(it->nodeId, 16, 16, QChar('0')) +
((it->flags & CHAT_MEMBER_FLAG_RADIO) ? QCoreApplication::translate("ChatGui", " · Radio enabled") : QString());
if (role == Qt::UserRole + 2) return it->isSelf;
if (role == Qt::UserRole + 3) return it->flags;
if (role == Qt::UserRole + 4) return (bool)it->storage;
if (role == RadioSpeakingRole) return it->isSelf ? m_selfTransmitting : m_radioTalkers.contains(it->nodeId);
if (role == OnlineRole) return it->online;
QString("%1").arg(it->snapshot.node_id, 16, 16, QChar('0')) +
((it->snapshot.flags & CHAT_MEMBER_FLAG_RADIO) ? QCoreApplication::translate("ChatGui", " · Radio enabled") : QString());
if (role == Qt::UserRole + 2) return it->snapshot.is_self;
if (role == Qt::UserRole + 3) return it->snapshot.flags;
if (role == Qt::UserRole + 4) return (bool)it->snapshot.storage;
if (role == RadioSpeakingRole) return it->snapshot.is_self ? m_selfTransmitting : m_radioTalkers.contains(it->snapshot.node_id);
if (role == OnlineRole) return it->snapshot.online;
return {};
}
return {};
}
void MemberListModel::setChannel(const QString& channelId, bool isOwner) {
beginResetModel();
if (m_channelId != channelId) {
beginResetModel();
DEBUG_DEBUG(DEBUG_CATEGORY_RADIO, "radio members: channel %s -> %s cleared talkers=%d self_tx=%d",
qPrintable(m_channelId), qPrintable(channelId), int(m_radioTalkers.size()), m_selfTransmitting);
m_radioTalkers.clear(); m_radioActive = false; m_selfTransmitting = false;
m_totalCount = 0; m_cache.clear(); endResetModel();
emit snapshotChanged(0);
}
m_channelId = channelId;
m_isOwner = isOwner;
m_totalCount = 0;
m_cache.clear();
endResetModel();
m_channelId = channelId; m_isOwner = isOwner;
refresh();
}
if (!channelId.isEmpty()) {
void MemberListModel::refresh() {
if (!m_channelId.isEmpty() && gui_bridge_is_uasync_ready()) {
struct chat_member_list_req* req = (struct chat_member_list_req*)u_calloc(1, sizeof(*req));
if (!req) return;
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "member list request allocation failed"); return; }
req->inst = gui_bridge_get_inst();
strncpy(req->ch_id, channelId.toUtf8().constData(), sizeof(req->ch_id) - 1);
strncpy(req->ch_id, m_channelId.toUtf8().constData(), sizeof(req->ch_id) - 1);
gui_bridge_post_uasync_fn(chat_core_request_member_list_trampoline, req);
}
}
void MemberListModel::refresh() {
if (!m_channelId.isEmpty()) setChannel(m_channelId, m_isOwner);
}
void MemberListModel::refreshRtt() {
if (m_channelId.isEmpty()) return;
if (m_channelId.isEmpty() || !gui_bridge_is_uasync_ready()) return;
struct chat_member_list_req* req = (struct chat_member_list_req*)u_calloc(1, sizeof(*req));
if (!req) return;
if (!req) { DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "member RTT request allocation failed"); return; }
req->inst = gui_bridge_get_inst();
strncpy(req->ch_id, m_channelId.toUtf8().constData(), sizeof(req->ch_id) - 1);
gui_bridge_post_uasync_fn(chat_core_request_member_rtt_trampoline, req);
@@ -122,24 +119,25 @@ void MemberListModel::refreshRtt() {
quint64 MemberListModel::nodeIdAt(int row) const {
auto it = m_cache.find(row);
return it != m_cache.end() ? it->nodeId : 0;
return it != m_cache.end() ? it->snapshot.node_id : 0;
}
bool MemberListModel::isOnlineAt(int row) const {
auto it = m_cache.find(row);
return it != m_cache.end() ? it->online : false;
return it != m_cache.end() ? it->snapshot.online : false;
}
std::optional<chat_member_display> MemberListModel::member(quint64 nodeId) const {
for (auto it = m_cache.cbegin(); it != m_cache.cend(); ++it)
if (it->snapshot.node_id == nodeId) return it->snapshot;
return std::nullopt;
}
static void deserialize_member(const uint8_t* src, MemberListItem& item) {
struct chat_member_display member;
chat_core_deserialize_member(src, &member);
item.nodeId = member.node_id; item.isSelf = member.is_self != 0;
item.flags = member.flags; item.rtt = member.rtt == 0xffff ? -1 : member.rtt;
item.natType = member.nat_type == 0xff ? -1 : member.nat_type;
item.storage = member.storage; item.online = member.online != 0;
item.name = QString::fromUtf8(member.name);
chat_core_deserialize_member(src, &item.snapshot);
item.name = QString::fromUtf8(item.snapshot.name);
QColor c = item.online ? QColor("#4CAF50") : QColor("#9E9E9E");
QColor c = item.snapshot.online ? QColor("#4CAF50") : QColor("#9E9E9E");
const int size = MemberListModel::kAvatarSize;
QPixmap pm(size, size); pm.fill(Qt::transparent);
QPainter p(&pm);
@@ -157,7 +155,10 @@ static void deserialize_member(const uint8_t* src, MemberListItem& item) {
void MemberListModel::onMemberList(const QString& chId, int count, const uint8_t* data, int dataLen) {
if (chId != m_channelId) return;
if (count < 0 || count > dataLen / CHAT_MEMBER_DISPLAY_SIZE) return;
if (count < 0 || dataLen < 0 || count != dataLen / CHAT_MEMBER_DISPLAY_SIZE ||
dataLen % CHAT_MEMBER_DISPLAY_SIZE || (count && !data)) {
DEBUG_ERROR(DEBUG_CATEGORY_CHAT_SYNC, "member list: invalid count=%d bytes=%d", count, dataLen); return;
}
beginResetModel();
m_totalCount = 0;
@@ -168,11 +169,12 @@ void MemberListModel::onMemberList(const QString& chId, int count, const uint8_t
MemberListItem item;
deserialize_member(data + i * CHAT_MEMBER_DISPLAY_SIZE, item);
applyPhoto(item, chId);
if ((item.flags & CHAT_MEMBER_FLAG_DELETED) && !m_isOwner) continue;
if ((item.snapshot.flags & CHAT_MEMBER_FLAG_DELETED) && !m_isOwner) continue;
m_cache[row++] = item;
}
m_totalCount = row;
endResetModel();
emit snapshotChanged(0);
}
void MemberListModel::onMemberUpdated(const QString& chId, const uint8_t* data) {
@@ -185,12 +187,12 @@ void MemberListModel::onMemberUpdated(const QString& chId, const uint8_t* data)
/* find existing row by nodeId */
int row = -1;
for (auto it = m_cache.begin(); it != m_cache.end(); ++it) {
if (it->nodeId == item.nodeId) { row = it.key(); break; }
if (it->snapshot.node_id == item.snapshot.node_id) { row = it.key(); break; }
}
if ((item.flags & CHAT_MEMBER_FLAG_DELETED) && !m_isOwner) {
if ((item.snapshot.flags & CHAT_MEMBER_FLAG_DELETED) && !m_isOwner) {
/* deleted member — remove from non-owner's list */
onMemberRemoved(chId, item.nodeId);
onMemberRemoved(chId, item.snapshot.node_id);
return;
}
@@ -205,6 +207,7 @@ void MemberListModel::onMemberUpdated(const QString& chId, const uint8_t* data)
m_totalCount++;
endInsertRows();
}
emit snapshotChanged(item.snapshot.node_id);
}
void MemberListModel::onMemberRemoved(const QString& chId, uint64_t nodeId) {
@@ -214,13 +217,14 @@ void MemberListModel::onMemberRemoved(const QString& chId, uint64_t nodeId) {
qPrintable(chId), (unsigned long long)nodeId);
for (auto it = m_cache.begin(); it != m_cache.end(); ++it) {
if (it->nodeId == nodeId) {
if (it->snapshot.node_id == nodeId) {
int row = it.key();
beginRemoveRows(QModelIndex(), row, row);
m_cache.remove(row);
for (int next = row + 1; next < m_totalCount; ++next) m_cache[next - 1] = m_cache.take(next);
m_totalCount--;
endRemoveRows();
emit snapshotChanged(nodeId);
return;
}
}
@@ -255,7 +259,7 @@ void MemberListModel::onRadioTalk(quint64 groupId, quint64 nodeId, bool on) {
else m_radioTalkers.remove(nodeId);
DEBUG_DEBUG(DEBUG_CATEGORY_RADIO, "radio members: talk ch=%s node=%016llx on=%d talkers=%d",
qPrintable(m_channelId), (unsigned long long)nodeId, on, int(m_radioTalkers.size()));
for (auto it = m_cache.cbegin(); it != m_cache.cend(); ++it) if (it->nodeId == nodeId) {
for (auto it = m_cache.cbegin(); it != m_cache.cend(); ++it) if (it->snapshot.node_id == nodeId) {
emit dataChanged(index(it.key()), index(it.key()), {RadioSpeakingRole});
return;
}