Merge pull request #1404 from LcsTen/dont-show-private-rooms-in-space

Don't show inaccessible private rooms in spaces
This commit is contained in:
DeepBlueV7.X 2023-03-18 14:02:03 +00:00 committed by GitHub
commit 9ad3f3f4fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

@ -211,7 +211,7 @@ Item {
Layout.alignment: Qt.AlignHCenter
MatrixText {
text: preview.roomName == "" ? qsTr("No preview available") : preview.roomName
text: !roomPreview.isFetched ? qsTr("No preview available") : preview.roomName
font.pixelSize: 24
}
@ -252,7 +252,7 @@ Item {
Layout.rightMargin: Nheko.paddingLarge
TextArea {
text: TimelineManager.escapeEmoji(preview.roomTopic)
text: roomPreview.isFetched ? TimelineManager.escapeEmoji(preview.roomTopic) : qsTr("This room is possibly inaccessible. If this room is private, you should remove it from the child list of this space.")
wrapMode: TextEdit.WordWrap
textFormat: TextEdit.RichText
readOnly: true

View file

@ -222,7 +222,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
case Roles::RoomName:
return tr("No preview available");
case Roles::LastMessage:
return QString();
return tr("This room is possibly inaccessible");
case Roles::Time:
return QString();
case Roles::Timestamp:
@ -796,11 +796,13 @@ RoomlistModel::setCurrentRoom(const QString &roomid)
p.roomName_ = QString::fromStdString(i->name);
p.roomTopic_ = QString::fromStdString(i->topic);
p.roomAvatarUrl_ = QString::fromStdString(i->avatar_url);
p.isFetched_ = true;
currentRoomPreview_ = std::move(p);
nhlog::ui()->debug("Switched to (preview): {}",
currentRoomPreview_->roomid_.toStdString());
} else {
p.roomid_ = roomid;
p.isFetched_ = false;
currentRoomPreview_ = p;
nhlog::ui()->debug("Switched to (empty): {}",
currentRoomPreview_->roomid_.toStdString());
@ -1100,6 +1102,15 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons
.toBool();
}
// If it is a preview but it can't be fetched, it is probably an inaccessible private room.
// Hide it if the user isn't an admin.
auto index = sourceModel()->index(sourceRow, 0);
if (sourceModel()->data(index, RoomlistModel::IsPreview).toBool() &&
!sourceModel()->data(index, RoomlistModel::IsPreviewFetched).toBool() &&
!Permissions(filterStr).canChange(qml_mtx_events::SpaceChild)) {
return false;
}
return true;
} else {
return true;

View file

@ -32,6 +32,7 @@ class RoomPreview
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl CONSTANT)
Q_PROPERTY(QString reason READ reason CONSTANT)
Q_PROPERTY(bool isInvite READ isInvite CONSTANT)
Q_PROPERTY(bool isFetched READ isFetched CONSTANT)
public:
RoomPreview() {}
@ -42,9 +43,10 @@ public:
QString roomAvatarUrl() const { return roomAvatarUrl_; }
QString reason() const { return reason_; }
bool isInvite() const { return isInvite_; }
bool isFetched() const { return isFetched_; }
QString roomid_, roomName_, roomAvatarUrl_, roomTopic_, reason_;
bool isInvite_ = false;
bool isInvite_ = false, isFetched_ = true;
};
class RoomlistModel final : public QAbstractListModel