From 71a51d34c740ab100271e693cf1a3fc16c02203d Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 11 Oct 2018 15:56:10 +0300 Subject: [PATCH] Combined emotes of different tiers in Emote Popup. --- src/widgets/dialogs/EmotePopup.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 0f3375121..227493050 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -48,19 +48,26 @@ namespace { std::vector> sets, Channel &globalChannel, Channel &subChannel) { - for (const auto &set : sets) { - auto &channel = set->key == "0" ? globalChannel : subChannel; + QMap>> mapOfSets; + for (const auto &set : sets) { // TITLE + auto channelName = set->channelName; auto text = set->key == "0" || set->text.isEmpty() ? "Twitch" : set->text; - channel.addMessage(makeTitleMessage(text)); // EMOTES MessageBuilder builder; builder->flags.set(MessageFlag::Centered); builder->flags.set(MessageFlag::DisableCompactEmotes); + // If value of map is empty, create init pair and add title. + if (mapOfSets.find(channelName) == mapOfSets.end()) { + std::vector b; + b.push_back(makeTitleMessage(text)); + mapOfSets[channelName] = qMakePair(set->key == "0", b); + } + for (const auto &emote : set->emotes) { builder .emplace( @@ -70,7 +77,16 @@ namespace { ->setLink(Link(Link::InsertText, emote.name.string)); } - channel.addMessage(builder.release()); + mapOfSets[channelName].second.push_back(builder.release()); + } + + // Output to channel all created messages, + // That contain title or emotes. + foreach (auto pair, mapOfSets) { + auto &channel = pair.first ? globalChannel : subChannel; + for (auto message : pair.second) { + channel.addMessage(message); + } } } } // namespace