Reenable tag hiding

This commit is contained in:
Nicolas Werner 2021-06-11 17:54:05 +02:00
parent 8d2d8dc267
commit a5291605a9
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
6 changed files with 94 additions and 22 deletions

View file

@ -33,16 +33,16 @@ Page {
Platform.Menu { Platform.Menu {
id: communityContextMenu id: communityContextMenu
property string id property string tagId
function show(id_, tags_) { function show(id_, tags_) {
id = id_; tagId = id_;
open(); open();
} }
Platform.MenuItem { Platform.MenuItem {
text: qsTr("Leave room") text: qsTr("Hide rooms with this tag or from this space by default.")
onTriggered: Rooms.leave(roomContextMenu.roomid) onTriggered: Communities.toggleTagId(communityContextMenu.tagId)
} }
} }
@ -65,7 +65,7 @@ Page {
states: [ states: [
State { State {
name: "highlight" name: "highlight"
when: hovered.hovered && !(Communities.currentTagId == model.id) when: (hovered.hovered || model.hidden) && !(Communities.currentTagId == model.id)
PropertyChanges { PropertyChanges {
target: communityItem target: communityItem

View file

@ -21,6 +21,7 @@ CommunitiesModel::roleNames() const
{DisplayName, "displayName"}, {DisplayName, "displayName"},
{Tooltip, "tooltip"}, {Tooltip, "tooltip"},
{ChildrenHidden, "childrenHidden"}, {ChildrenHidden, "childrenHidden"},
{Hidden, "hidden"},
{Id, "id"}, {Id, "id"},
}; };
} }
@ -38,6 +39,8 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
return tr("Shows all rooms without filtering."); return tr("Shows all rooms without filtering.");
case CommunitiesModel::Roles::ChildrenHidden: case CommunitiesModel::Roles::ChildrenHidden:
return false; return false;
case CommunitiesModel::Roles::Hidden:
return false;
case CommunitiesModel::Roles::Id: case CommunitiesModel::Roles::Id:
return ""; return "";
} }
@ -82,8 +85,10 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
} }
switch (role) { switch (role) {
case CommunitiesModel::Roles::Hidden:
return hiddentTagIds_.contains("tag:" + tag);
case CommunitiesModel::Roles::ChildrenHidden: case CommunitiesModel::Roles::ChildrenHidden:
return UserSettings::instance()->hiddenTags().contains("tag:" + tag); return true;
case CommunitiesModel::Roles::Id: case CommunitiesModel::Roles::Id:
return "tag:" + tag; return "tag:" + tag;
} }
@ -107,9 +112,12 @@ CommunitiesModel::initializeSidebar()
tags_.clear(); tags_.clear();
for (const auto &t : ts) for (const auto &t : ts)
tags_.push_back(QString::fromStdString(t)); tags_.push_back(QString::fromStdString(t));
hiddentTagIds_ = UserSettings::instance()->hiddenTags();
endResetModel(); endResetModel();
emit tagsChanged(); emit tagsChanged();
emit hiddenTagsChanged();
} }
void void
@ -158,3 +166,23 @@ CommunitiesModel::setCurrentTagId(QString tagId)
this->currentTagId_ = ""; this->currentTagId_ = "";
emit currentTagIdChanged(currentTagId_); emit currentTagIdChanged(currentTagId_);
} }
void
CommunitiesModel::toggleTagId(QString tagId)
{
if (hiddentTagIds_.contains(tagId)) {
hiddentTagIds_.removeOne(tagId);
UserSettings::instance()->setHiddenTags(hiddentTagIds_);
} else {
hiddentTagIds_.push_back(tagId);
UserSettings::instance()->setHiddenTags(hiddentTagIds_);
}
if (tagId.startsWith("tag:")) {
auto idx = tags_.indexOf(tagId.mid(4));
if (idx != -1)
emit dataChanged(index(idx), index(idx), {Hidden});
}
emit hiddenTagsChanged();
}

View file

@ -25,6 +25,7 @@ public:
DisplayName, DisplayName,
Tooltip, Tooltip,
ChildrenHidden, ChildrenHidden,
Hidden,
Id, Id,
}; };
@ -49,12 +50,15 @@ public slots:
emit currentTagIdChanged(currentTagId_); emit currentTagIdChanged(currentTagId_);
} }
QStringList tags() const { return tags_; } QStringList tags() const { return tags_; }
void toggleTagId(QString tagId);
signals: signals:
void currentTagIdChanged(QString tagId); void currentTagIdChanged(QString tagId);
void hiddenTagsChanged();
void tagsChanged(); void tagsChanged();
private: private:
QStringList tags_; QStringList tags_;
QString currentTagId_; QString currentTagId_;
QStringList hiddentTagIds_;
}; };

View file

@ -462,22 +462,6 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ
return left.row() < right.row(); return left.row() < right.row();
} }
bool
FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const
{
if (filterType == FilterBy::Nothing)
return true;
else if (filterType == FilterBy::Tag) {
auto tags = sourceModel()
->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags)
.toStringList();
return tags.contains(filterStr);
} else {
return true;
}
}
FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *parent) FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *parent)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
, roomlistmodel(model) , roomlistmodel(model)
@ -502,6 +486,55 @@ FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *pare
sort(0); sort(0);
} }
void
FilteredRoomlistModel::updateHiddenTagsAndSpaces()
{
hiddenTags.clear();
hiddenSpaces.clear();
for (const auto &t : UserSettings::instance()->hiddenTags()) {
if (t.startsWith("tag:"))
hiddenTags.push_back(t.mid(4));
else if (t.startsWith("space:"))
hiddenSpaces.push_back(t.mid(6));
}
invalidateFilter();
}
bool
FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const
{
if (filterType == FilterBy::Nothing) {
if (!hiddenTags.empty()) {
auto tags =
sourceModel()
->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags)
.toStringList();
for (const auto &t : tags)
if (hiddenTags.contains(t))
return false;
}
return true;
} else if (filterType == FilterBy::Tag) {
auto tags = sourceModel()
->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags)
.toStringList();
if (!tags.contains(filterStr))
return false;
else if (!hiddenTags.empty()) {
for (const auto &t : tags)
if (t != filterStr && hiddenTags.contains(t))
return false;
}
return true;
} else {
return true;
}
}
void void
FilteredRoomlistModel::toggleTag(QString roomid, QString tag, bool on) FilteredRoomlistModel::toggleTag(QString roomid, QString tag, bool on)
{ {

View file

@ -142,6 +142,8 @@ public slots:
invalidateFilter(); invalidateFilter();
} }
void updateHiddenTagsAndSpaces();
signals: signals:
void currentRoomChanged(); void currentRoomChanged();
@ -158,4 +160,5 @@ private:
}; };
QString filterStr = ""; QString filterStr = "";
FilterBy filterType = FilterBy::Nothing; FilterBy filterType = FilterBy::Nothing;
QStringList hiddenTags, hiddenSpaces;
}; };

View file

@ -201,6 +201,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
&CommunitiesModel::currentTagIdChanged, &CommunitiesModel::currentTagIdChanged,
ptr, ptr,
&FilteredRoomlistModel::updateFilterTag); &FilteredRoomlistModel::updateFilterTag);
connect(self->communities_,
&CommunitiesModel::hiddenTagsChanged,
ptr,
&FilteredRoomlistModel::updateHiddenTagsAndSpaces);
return ptr; return ptr;
}); });
qmlRegisterSingletonType<RoomlistModel>( qmlRegisterSingletonType<RoomlistModel>(