mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Reenable tag hiding
This commit is contained in:
parent
8d2d8dc267
commit
a5291605a9
6 changed files with 94 additions and 22 deletions
|
@ -33,16 +33,16 @@ Page {
|
|||
Platform.Menu {
|
||||
id: communityContextMenu
|
||||
|
||||
property string id
|
||||
property string tagId
|
||||
|
||||
function show(id_, tags_) {
|
||||
id = id_;
|
||||
tagId = id_;
|
||||
open();
|
||||
}
|
||||
|
||||
Platform.MenuItem {
|
||||
text: qsTr("Leave room")
|
||||
onTriggered: Rooms.leave(roomContextMenu.roomid)
|
||||
text: qsTr("Hide rooms with this tag or from this space by default.")
|
||||
onTriggered: Communities.toggleTagId(communityContextMenu.tagId)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ Page {
|
|||
states: [
|
||||
State {
|
||||
name: "highlight"
|
||||
when: hovered.hovered && !(Communities.currentTagId == model.id)
|
||||
when: (hovered.hovered || model.hidden) && !(Communities.currentTagId == model.id)
|
||||
|
||||
PropertyChanges {
|
||||
target: communityItem
|
||||
|
|
|
@ -21,6 +21,7 @@ CommunitiesModel::roleNames() const
|
|||
{DisplayName, "displayName"},
|
||||
{Tooltip, "tooltip"},
|
||||
{ChildrenHidden, "childrenHidden"},
|
||||
{Hidden, "hidden"},
|
||||
{Id, "id"},
|
||||
};
|
||||
}
|
||||
|
@ -38,6 +39,8 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
|||
return tr("Shows all rooms without filtering.");
|
||||
case CommunitiesModel::Roles::ChildrenHidden:
|
||||
return false;
|
||||
case CommunitiesModel::Roles::Hidden:
|
||||
return false;
|
||||
case CommunitiesModel::Roles::Id:
|
||||
return "";
|
||||
}
|
||||
|
@ -82,8 +85,10 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
|
||||
switch (role) {
|
||||
case CommunitiesModel::Roles::Hidden:
|
||||
return hiddentTagIds_.contains("tag:" + tag);
|
||||
case CommunitiesModel::Roles::ChildrenHidden:
|
||||
return UserSettings::instance()->hiddenTags().contains("tag:" + tag);
|
||||
return true;
|
||||
case CommunitiesModel::Roles::Id:
|
||||
return "tag:" + tag;
|
||||
}
|
||||
|
@ -107,9 +112,12 @@ CommunitiesModel::initializeSidebar()
|
|||
tags_.clear();
|
||||
for (const auto &t : ts)
|
||||
tags_.push_back(QString::fromStdString(t));
|
||||
|
||||
hiddentTagIds_ = UserSettings::instance()->hiddenTags();
|
||||
endResetModel();
|
||||
|
||||
emit tagsChanged();
|
||||
emit hiddenTagsChanged();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -158,3 +166,23 @@ CommunitiesModel::setCurrentTagId(QString tagId)
|
|||
this->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();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public:
|
|||
DisplayName,
|
||||
Tooltip,
|
||||
ChildrenHidden,
|
||||
Hidden,
|
||||
Id,
|
||||
};
|
||||
|
||||
|
@ -49,12 +50,15 @@ public slots:
|
|||
emit currentTagIdChanged(currentTagId_);
|
||||
}
|
||||
QStringList tags() const { return tags_; }
|
||||
void toggleTagId(QString tagId);
|
||||
|
||||
signals:
|
||||
void currentTagIdChanged(QString tagId);
|
||||
void hiddenTagsChanged();
|
||||
void tagsChanged();
|
||||
|
||||
private:
|
||||
QStringList tags_;
|
||||
QString currentTagId_;
|
||||
QStringList hiddentTagIds_;
|
||||
};
|
||||
|
|
|
@ -462,22 +462,6 @@ FilteredRoomlistModel::lessThan(const QModelIndex &left, const QModelIndex &righ
|
|||
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)
|
||||
: QSortFilterProxyModel(parent)
|
||||
, roomlistmodel(model)
|
||||
|
@ -502,6 +486,55 @@ FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *pare
|
|||
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
|
||||
FilteredRoomlistModel::toggleTag(QString roomid, QString tag, bool on)
|
||||
{
|
||||
|
|
|
@ -142,6 +142,8 @@ public slots:
|
|||
invalidateFilter();
|
||||
}
|
||||
|
||||
void updateHiddenTagsAndSpaces();
|
||||
|
||||
signals:
|
||||
void currentRoomChanged();
|
||||
|
||||
|
@ -158,4 +160,5 @@ private:
|
|||
};
|
||||
QString filterStr = "";
|
||||
FilterBy filterType = FilterBy::Nothing;
|
||||
QStringList hiddenTags, hiddenSpaces;
|
||||
};
|
||||
|
|
|
@ -201,6 +201,10 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
|
|||
&CommunitiesModel::currentTagIdChanged,
|
||||
ptr,
|
||||
&FilteredRoomlistModel::updateFilterTag);
|
||||
connect(self->communities_,
|
||||
&CommunitiesModel::hiddenTagsChanged,
|
||||
ptr,
|
||||
&FilteredRoomlistModel::updateHiddenTagsAndSpaces);
|
||||
return ptr;
|
||||
});
|
||||
qmlRegisterSingletonType<RoomlistModel>(
|
||||
|
|
Loading…
Reference in a new issue