mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 09:30:47 +03:00
Dedup reactions
This commit is contained in:
parent
96f791daf1
commit
5164c2c5e8
1 changed files with 4 additions and 6 deletions
|
@ -575,8 +575,7 @@ EventStore::reactions(const std::string &event_id)
|
||||||
|
|
||||||
struct TempReaction
|
struct TempReaction
|
||||||
{
|
{
|
||||||
int count = 0;
|
std::set<std::string> users;
|
||||||
std::vector<std::string> users;
|
|
||||||
std::string reactedBySelf;
|
std::string reactedBySelf;
|
||||||
};
|
};
|
||||||
std::map<std::string, TempReaction> aggregation;
|
std::map<std::string, TempReaction> aggregation;
|
||||||
|
@ -595,14 +594,13 @@ EventStore::reactions(const std::string &event_id)
|
||||||
auto key = reaction->content.relations.annotates()->key.value();
|
auto key = reaction->content.relations.annotates()->key.value();
|
||||||
auto &agg = aggregation[key];
|
auto &agg = aggregation[key];
|
||||||
|
|
||||||
if (agg.count == 0) {
|
if (agg.users.empty()) {
|
||||||
Reaction temp{};
|
Reaction temp{};
|
||||||
temp.key_ = QString::fromStdString(key);
|
temp.key_ = QString::fromStdString(key);
|
||||||
reactions.push_back(temp);
|
reactions.push_back(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
agg.count++;
|
agg.users.insert(cache::displayName(room_id_, reaction->sender));
|
||||||
agg.users.push_back(cache::displayName(room_id_, reaction->sender));
|
|
||||||
if (reaction->sender == self)
|
if (reaction->sender == self)
|
||||||
agg.reactedBySelf = reaction->event_id;
|
agg.reactedBySelf = reaction->event_id;
|
||||||
}
|
}
|
||||||
|
@ -612,7 +610,7 @@ EventStore::reactions(const std::string &event_id)
|
||||||
temp.reserve(static_cast<int>(reactions.size()));
|
temp.reserve(static_cast<int>(reactions.size()));
|
||||||
for (auto &reaction : reactions) {
|
for (auto &reaction : reactions) {
|
||||||
const auto &agg = aggregation[reaction.key_.toStdString()];
|
const auto &agg = aggregation[reaction.key_.toStdString()];
|
||||||
reaction.count_ = agg.count;
|
reaction.count_ = agg.users.size();
|
||||||
reaction.selfReactedEvent_ = QString::fromStdString(agg.reactedBySelf);
|
reaction.selfReactedEvent_ = QString::fromStdString(agg.reactedBySelf);
|
||||||
|
|
||||||
bool firstReaction = true;
|
bool firstReaction = true;
|
||||||
|
|
Loading…
Reference in a new issue