mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Allow filtering by space
This commit is contained in:
parent
6a7d28d1b5
commit
6bfa6c4c79
5 changed files with 68 additions and 12 deletions
|
@ -905,7 +905,9 @@ Cache::runMigrations()
|
||||||
std::reverse(oldMessages.events.begin(),
|
std::reverse(oldMessages.events.begin(),
|
||||||
oldMessages.events.end());
|
oldMessages.events.end());
|
||||||
// save messages using the new method
|
// save messages using the new method
|
||||||
saveTimelineMessages(txn, room_id, oldMessages);
|
auto eventsDb = getEventsDb(txn, room_id);
|
||||||
|
saveTimelineMessages(
|
||||||
|
txn, eventsDb, room_id, oldMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete old messages db
|
// delete old messages db
|
||||||
|
@ -1208,13 +1210,24 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
auto statesdb = getStatesDb(txn, room.first);
|
auto statesdb = getStatesDb(txn, room.first);
|
||||||
auto stateskeydb = getStatesKeyDb(txn, room.first);
|
auto stateskeydb = getStatesKeyDb(txn, room.first);
|
||||||
auto membersdb = getMembersDb(txn, room.first);
|
auto membersdb = getMembersDb(txn, room.first);
|
||||||
|
auto eventsDb = getEventsDb(txn, room.first);
|
||||||
|
|
||||||
saveStateEvents(
|
saveStateEvents(txn,
|
||||||
txn, statesdb, stateskeydb, membersdb, room.first, room.second.state.events);
|
statesdb,
|
||||||
saveStateEvents(
|
stateskeydb,
|
||||||
txn, statesdb, stateskeydb, membersdb, room.first, room.second.timeline.events);
|
membersdb,
|
||||||
|
eventsDb,
|
||||||
|
room.first,
|
||||||
|
room.second.state.events);
|
||||||
|
saveStateEvents(txn,
|
||||||
|
statesdb,
|
||||||
|
stateskeydb,
|
||||||
|
membersdb,
|
||||||
|
eventsDb,
|
||||||
|
room.first,
|
||||||
|
room.second.timeline.events);
|
||||||
|
|
||||||
saveTimelineMessages(txn, room.first, room.second.timeline);
|
saveTimelineMessages(txn, eventsDb, room.first, room.second.timeline);
|
||||||
|
|
||||||
RoomInfo updatedInfo;
|
RoomInfo updatedInfo;
|
||||||
updatedInfo.name = getRoomName(txn, statesdb, membersdb).toStdString();
|
updatedInfo.name = getRoomName(txn, statesdb, membersdb).toStdString();
|
||||||
|
@ -2634,11 +2647,12 @@ void
|
||||||
Cache::savePendingMessage(const std::string &room_id,
|
Cache::savePendingMessage(const std::string &room_id,
|
||||||
const mtx::events::collections::TimelineEvent &message)
|
const mtx::events::collections::TimelineEvent &message)
|
||||||
{
|
{
|
||||||
auto txn = lmdb::txn::begin(env_);
|
auto txn = lmdb::txn::begin(env_);
|
||||||
|
auto eventsDb = getEventsDb(txn, room_id);
|
||||||
|
|
||||||
mtx::responses::Timeline timeline;
|
mtx::responses::Timeline timeline;
|
||||||
timeline.events.push_back(message.data);
|
timeline.events.push_back(message.data);
|
||||||
saveTimelineMessages(txn, room_id, timeline);
|
saveTimelineMessages(txn, eventsDb, room_id, timeline);
|
||||||
|
|
||||||
auto pending = getPendingMessagesDb(txn, room_id);
|
auto pending = getPendingMessagesDb(txn, room_id);
|
||||||
|
|
||||||
|
@ -2706,13 +2720,13 @@ Cache::removePendingStatus(const std::string &room_id, const std::string &txn_id
|
||||||
|
|
||||||
void
|
void
|
||||||
Cache::saveTimelineMessages(lmdb::txn &txn,
|
Cache::saveTimelineMessages(lmdb::txn &txn,
|
||||||
|
lmdb::dbi &eventsDb,
|
||||||
const std::string &room_id,
|
const std::string &room_id,
|
||||||
const mtx::responses::Timeline &res)
|
const mtx::responses::Timeline &res)
|
||||||
{
|
{
|
||||||
if (res.events.empty())
|
if (res.events.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto eventsDb = getEventsDb(txn, room_id);
|
|
||||||
auto relationsDb = getRelationsDb(txn, room_id);
|
auto relationsDb = getRelationsDb(txn, room_id);
|
||||||
|
|
||||||
auto orderDb = getEventOrderDb(txn, room_id);
|
auto orderDb = getEventOrderDb(txn, room_id);
|
||||||
|
|
|
@ -335,6 +335,7 @@ private:
|
||||||
std::string getLastEventId(lmdb::txn &txn, const std::string &room_id);
|
std::string getLastEventId(lmdb::txn &txn, const std::string &room_id);
|
||||||
DescInfo getLastMessageInfo(lmdb::txn &txn, const std::string &room_id);
|
DescInfo getLastMessageInfo(lmdb::txn &txn, const std::string &room_id);
|
||||||
void saveTimelineMessages(lmdb::txn &txn,
|
void saveTimelineMessages(lmdb::txn &txn,
|
||||||
|
lmdb::dbi &eventsDb,
|
||||||
const std::string &room_id,
|
const std::string &room_id,
|
||||||
const mtx::responses::Timeline &res);
|
const mtx::responses::Timeline &res);
|
||||||
|
|
||||||
|
@ -353,11 +354,12 @@ private:
|
||||||
lmdb::dbi &statesdb,
|
lmdb::dbi &statesdb,
|
||||||
lmdb::dbi &stateskeydb,
|
lmdb::dbi &stateskeydb,
|
||||||
lmdb::dbi &membersdb,
|
lmdb::dbi &membersdb,
|
||||||
|
lmdb::dbi &eventsDb,
|
||||||
const std::string &room_id,
|
const std::string &room_id,
|
||||||
const std::vector<T> &events)
|
const std::vector<T> &events)
|
||||||
{
|
{
|
||||||
for (const auto &e : events)
|
for (const auto &e : events)
|
||||||
saveStateEvent(txn, statesdb, stateskeydb, membersdb, room_id, e);
|
saveStateEvent(txn, statesdb, stateskeydb, membersdb, eventsDb, room_id, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -365,6 +367,7 @@ private:
|
||||||
lmdb::dbi &statesdb,
|
lmdb::dbi &statesdb,
|
||||||
lmdb::dbi &stateskeydb,
|
lmdb::dbi &stateskeydb,
|
||||||
lmdb::dbi &membersdb,
|
lmdb::dbi &membersdb,
|
||||||
|
lmdb::dbi &eventsDb,
|
||||||
const std::string &room_id,
|
const std::string &room_id,
|
||||||
const T &event)
|
const T &event)
|
||||||
{
|
{
|
||||||
|
@ -401,8 +404,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::visit(
|
std::visit(
|
||||||
[&txn, &statesdb, &stateskeydb](auto e) {
|
[&txn, &statesdb, &stateskeydb, &eventsDb](auto e) {
|
||||||
if constexpr (isStateEvent(e))
|
if constexpr (isStateEvent(e)) {
|
||||||
|
eventsDb.put(txn, e.event_id, json(e).dump());
|
||||||
|
|
||||||
if (e.type != EventType::Unsupported) {
|
if (e.type != EventType::Unsupported) {
|
||||||
if (e.state_key.empty())
|
if (e.state_key.empty())
|
||||||
statesdb.put(
|
statesdb.put(
|
||||||
|
@ -417,6 +422,7 @@ private:
|
||||||
})
|
})
|
||||||
.dump());
|
.dump());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
event);
|
event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,15 @@ CommunitiesModel::setCurrentTagId(QString tagId)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (tagId.startsWith("space:")) {
|
||||||
|
auto tag = tagId.mid(6);
|
||||||
|
for (const auto &t : spaceOrder_) {
|
||||||
|
if (t == tag) {
|
||||||
|
this->currentTagId_ = tagId;
|
||||||
|
emit currentTagIdChanged(currentTagId_);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->currentTagId_ = "";
|
this->currentTagId_ = "";
|
||||||
|
|
|
@ -530,6 +530,30 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else if (filterType == FilterBy::Space) {
|
||||||
|
auto roomid = sourceModel()
|
||||||
|
->data(sourceModel()->index(sourceRow, 0), RoomlistModel::RoomId)
|
||||||
|
.toString();
|
||||||
|
auto tags = sourceModel()
|
||||||
|
->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags)
|
||||||
|
.toStringList();
|
||||||
|
|
||||||
|
auto contains = [](const std::vector<std::string> &v, const std::string &str) {
|
||||||
|
for (const auto &e : v)
|
||||||
|
if (e == str)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
auto parents = cache::client()->getParentRoomIds(roomid.toStdString());
|
||||||
|
|
||||||
|
if (!contains(parents, filterStr.toStdString()))
|
||||||
|
return false;
|
||||||
|
else if (!hiddenTags.empty()) {
|
||||||
|
for (const auto &t : tags)
|
||||||
|
if (hiddenTags.contains(t))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,9 @@ public slots:
|
||||||
if (tagId.startsWith("tag:")) {
|
if (tagId.startsWith("tag:")) {
|
||||||
filterType = FilterBy::Tag;
|
filterType = FilterBy::Tag;
|
||||||
filterStr = tagId.mid(4);
|
filterStr = tagId.mid(4);
|
||||||
|
} else if (tagId.startsWith("space:")) {
|
||||||
|
filterType = FilterBy::Space;
|
||||||
|
filterStr = tagId.mid(6);
|
||||||
} else {
|
} else {
|
||||||
filterType = FilterBy::Nothing;
|
filterType = FilterBy::Nothing;
|
||||||
filterStr.clear();
|
filterStr.clear();
|
||||||
|
|
Loading…
Reference in a new issue