Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
Sort entries in the community bar
Browse files Browse the repository at this point in the history
  • Loading branch information
elinorbgr committed Sep 27, 2018
1 parent 8005e13 commit 48ef732
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/CommunitiesList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ CommunitiesList::setCommunities(const mtx::responses::JoinedGroups &response)

communities_["world"]->setPressedState(true);
emit communityChanged("world");
sortEntries();
}

void
CommunitiesList::syncTags(const std::map<QString, RoomInfo> &info)
{
for (const auto &room : info)
setTagsForRoom(room.first, room.second.tags);
sortEntries();
}

void
Expand Down Expand Up @@ -252,3 +254,40 @@ CommunitiesList::roomList(const QString &id) const

return {};
}

void
CommunitiesList::sortEntries()
{
std::vector<CommunitiesListItem *> header;
std::vector<CommunitiesListItem *> communities;
std::vector<CommunitiesListItem *> tags;
std::vector<CommunitiesListItem *> footer;
// remove all the contents and sort them in the 4 vectors
for (auto &entry : communities_) {
CommunitiesListItem *item = entry.second.get();
contentsLayout_->removeWidget(item);
// world is handled separately
if (entry.first == "world")
continue;
// sort the rest
if (item->is_tag())
if (entry.first == "tag:m.favourite")
header.push_back(item);
else if (entry.first == "tag:m.lowpriority")
footer.push_back(item);
else
tags.push_back(item);
else
communities.push_back(item);
}

contentsLayout_->insertWidget(contentsLayout_->count() - 1, communities_["world"].get());
for (auto item : header)
contentsLayout_->insertWidget(contentsLayout_->count() - 1, item);
for (auto item : communities)
contentsLayout_->insertWidget(contentsLayout_->count() - 1, item);
for (auto item : tags)
contentsLayout_->insertWidget(contentsLayout_->count() - 1, item);
for (auto item : footer)
contentsLayout_->insertWidget(contentsLayout_->count() - 1, item);
}
1 change: 1 addition & 0 deletions src/CommunitiesList.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public slots:
private:
void fetchCommunityAvatar(const QString &id, const QString &avatarUrl);
void addGlobalItem() { addCommunity("world"); }
void sortEntries();

//! Check whether or not a community id is currently managed.
bool communityExists(const QString &id) const
Expand Down

0 comments on commit 48ef732

Please sign in to comment.