feat(token-permissions): display channel names in SharedAddressesPanel
Modify the PermissionUtils a bit to return an array of `[key, channelName]` instead of just the keys and use it to display the channel names in the permissions overview panel (I could have used `QVariantMap` or `QJSonObject` here but those are always sorted by `key`, so had to resort to using a plain vector/array) Fixes #11584
This commit is contained in:
parent
d05d743d80
commit
e744c847ad
|
@ -504,10 +504,12 @@ QtObject {
|
|||
function createChannelsModel1() {
|
||||
return [
|
||||
{
|
||||
key: "_welcome"
|
||||
key: "_welcome",
|
||||
channelName: "Intro/welcome channel"
|
||||
},
|
||||
{
|
||||
key: "_general"
|
||||
key: "_general",
|
||||
channelName: "General"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -517,6 +519,11 @@ QtObject {
|
|||
}
|
||||
|
||||
function createChannelsModel3() {
|
||||
return [{ key: "_vip" } ]
|
||||
return [
|
||||
{
|
||||
key: "_vip",
|
||||
channelName: "Club VIP"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
class QAbstractItemModel;
|
||||
|
||||
|
@ -14,6 +15,7 @@ public:
|
|||
//!< traverse the permissions @p model, and look for unique token keys recursively under holdingsListModel->key
|
||||
Q_INVOKABLE QStringList getUniquePermissionTokenKeys(QAbstractItemModel *model) const;
|
||||
|
||||
//!< traverse the permissions @p model, and look for unique channel keys recursively under channelsListModel->key; filtering out @permissionTypes ([PermissionTypes.Type.FOO])
|
||||
Q_INVOKABLE QStringList getUniquePermissionChannels(QAbstractItemModel *model, const QList<int> &permissionTypes = {}) const;
|
||||
//!< traverse the permissions @p model, and look for unique channels recursively under channelsListModel->key; filtering out @permissionTypes ([PermissionTypes.Type.FOO])
|
||||
//! @return an array of array<key,channelName>
|
||||
Q_INVOKABLE QJsonArray getUniquePermissionChannels(QAbstractItemModel *model, const QList<int> &permissionTypes = {}) const;
|
||||
};
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
int roleByName(QAbstractItemModel* model, const QString &roleName)
|
||||
|
@ -61,8 +63,7 @@ QStringList PermissionUtilsInternal::getUniquePermissionTokenKeys(QAbstractItemM
|
|||
return {result.cbegin(), result.cend()};
|
||||
}
|
||||
|
||||
// TODO return a QVariantMap (https://github.com/status-im/status-desktop/issues/11481) with key->channelName
|
||||
QStringList PermissionUtilsInternal::getUniquePermissionChannels(QAbstractItemModel* model, const QList<int> &permissionTypes) const
|
||||
QJsonArray PermissionUtilsInternal::getUniquePermissionChannels(QAbstractItemModel* model, const QList<int> &permissionTypes) const
|
||||
{
|
||||
if (!model)
|
||||
return {};
|
||||
|
@ -75,7 +76,7 @@ QStringList PermissionUtilsInternal::getUniquePermissionChannels(QAbstractItemMo
|
|||
|
||||
const auto permissionTypeRole = roleByName(model, QStringLiteral("permissionType"));
|
||||
|
||||
std::set<QString> result; // unique, sorted by default
|
||||
std::vector<std::pair<QString,QString>> tmpRes; // key,channelName
|
||||
|
||||
const auto permissionsCount = model->rowCount();
|
||||
for (int i = 0; i < permissionsCount; i++) {
|
||||
|
@ -96,14 +97,30 @@ QStringList PermissionUtilsInternal::getUniquePermissionChannels(QAbstractItemMo
|
|||
const auto channelItemsCount = channelItems->rowCount();
|
||||
for (int j = 0; j < channelItemsCount; j++) {
|
||||
const auto keyRole = roleByName(channelItems, QStringLiteral("key"));
|
||||
const auto nameRole = roleByName(channelItems, QStringLiteral("channelName"));
|
||||
if (keyRole == -1) {
|
||||
qWarning() << Q_FUNC_INFO << "Requested roleName 'key' not found!";
|
||||
continue;
|
||||
}
|
||||
result.insert(channelItems->data(channelItems->index(j, 0), keyRole).toString());
|
||||
tmpRes.emplace_back(channelItems->data(channelItems->index(j, 0), keyRole).toString(),
|
||||
channelItems->data(channelItems->index(j, 0), nameRole).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {result.cbegin(), result.cend()};
|
||||
// sort by value (channel name)
|
||||
std::sort(tmpRes.begin(), tmpRes.end(), [](const auto& lhs, const auto& rhs) {
|
||||
return lhs.second.localeAwareCompare(rhs.second) < 0;
|
||||
});
|
||||
|
||||
// remove dupes
|
||||
tmpRes.erase(std::unique(tmpRes.begin(), tmpRes.end()), tmpRes.end());
|
||||
|
||||
// construct the (sorted) result
|
||||
QJsonArray result;
|
||||
std::transform(tmpRes.cbegin(), tmpRes.cend(), std::back_inserter(result), [](const auto& channel) -> QJsonArray {
|
||||
return {channel.first, channel.second};
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ Rectangle {
|
|||
}
|
||||
|
||||
Repeater { // channel repeater
|
||||
model: d.uniquePermissionChannels // TODO get channelName in addition (https://github.com/status-im/status-desktop/issues/11481)
|
||||
model: d.uniquePermissionChannels
|
||||
delegate: ChannelPermissionPanel {}
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ Rectangle {
|
|||
case PermissionTypes.Type.Member:
|
||||
return qsTr("Join %1").arg(root.communityName)
|
||||
default:
|
||||
return modelData // TODO display channel name https://github.com/status-im/status-desktop/issues/11481
|
||||
return d.uniquePermissionChannels[index][1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ Rectangle {
|
|||
padding: d.absLeftMargin
|
||||
background: PanelBg {}
|
||||
|
||||
readonly property string channelKey: modelData
|
||||
readonly property string channelKey: d.uniquePermissionChannels[index][0]
|
||||
|
||||
contentItem: RowLayout {
|
||||
spacing: Style.current.padding
|
||||
|
|
Loading…
Reference in New Issue