simplified Image
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/SimpleSignalVector.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
@@ -22,6 +22,32 @@
|
||||
#include <QTimer>
|
||||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
|
||||
{
|
||||
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
|
||||
std::vector<MessagePtr> messages;
|
||||
|
||||
if (jsonMessages.empty()) return messages;
|
||||
|
||||
for (const auto jsonMessage : jsonMessages) {
|
||||
auto content = jsonMessage.toString().toUtf8();
|
||||
// passing nullptr as the channel makes the message invalid but we don't
|
||||
// check for that anyways
|
||||
auto message = Communi::IrcMessage::fromData(content, nullptr);
|
||||
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
|
||||
assert(privMsg);
|
||||
|
||||
MessageParseArgs args;
|
||||
TwitchMessageBuilder builder(&channel, privMsg, args);
|
||||
if (!builder.isIgnored()) {
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TwitchChannel::TwitchChannel(const QString &name)
|
||||
: Channel(name, Channel::Type::Twitch)
|
||||
@@ -436,45 +462,23 @@ void TwitchChannel::loadRecentMessages()
|
||||
NetworkRequest request(genericURL.arg(this->getRoomId()));
|
||||
request.makeAuthorizedV5(getDefaultClientID());
|
||||
request.setCaller(QThread::currentThread());
|
||||
// can't be concurrent right now due to SignalVector
|
||||
// request.setExecuteConcurrently(true);
|
||||
|
||||
request.onSuccess(
|
||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
ChannelPtr shared = weak.lock();
|
||||
if (!shared) return Failure;
|
||||
request.onSuccess([that = this](auto result) -> Outcome {
|
||||
auto messages = parseRecentMessages(result.parseJson(), *that);
|
||||
|
||||
return this->parseRecentMessages(result.parseJson());
|
||||
});
|
||||
// postToThread([that, weak = weakOf<Channel>(that),
|
||||
// messages = std::move(messages)]() mutable {
|
||||
that->addMessagesAtStart(messages);
|
||||
// });
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
Outcome TwitchChannel::parseRecentMessages(const QJsonObject &jsonRoot)
|
||||
{
|
||||
QJsonArray jsonMessages = jsonRoot.value("messages").toArray();
|
||||
if (jsonMessages.empty()) return Failure;
|
||||
|
||||
std::vector<MessagePtr> messages;
|
||||
|
||||
for (const auto jsonMessage : jsonMessages) {
|
||||
auto content = jsonMessage.toString().toUtf8();
|
||||
// passing nullptr as the channel makes the message invalid but we don't
|
||||
// check for that anyways
|
||||
auto message = Communi::IrcMessage::fromData(content, nullptr);
|
||||
auto privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
|
||||
assert(privMsg);
|
||||
|
||||
MessageParseArgs args;
|
||||
TwitchMessageBuilder builder(this, privMsg, args);
|
||||
if (!builder.isIgnored()) {
|
||||
messages.push_back(builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
this->addMessagesAtStart(messages);
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
||||
void TwitchChannel::refreshPubsub()
|
||||
{
|
||||
// listen to moderation actions
|
||||
@@ -581,7 +585,7 @@ void TwitchChannel::loadBadges()
|
||||
|
||||
void TwitchChannel::loadCheerEmotes()
|
||||
{
|
||||
auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" +
|
||||
/*auto url = Url{"https://api.twitch.tv/kraken/bits/actions?channel_id=" +
|
||||
this->getRoomId()};
|
||||
auto request = NetworkRequest::twitchRequest(url.string);
|
||||
request.setCaller(QThread::currentThread());
|
||||
@@ -589,6 +593,7 @@ void TwitchChannel::loadCheerEmotes()
|
||||
request.onSuccess(
|
||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||
auto cheerEmoteSets = ParseCheermoteSets(result.parseRapidJson());
|
||||
std::vector<CheerEmoteSet> emoteSets;
|
||||
|
||||
for (auto &set : cheerEmoteSets) {
|
||||
auto cheerEmoteSet = CheerEmoteSet();
|
||||
@@ -631,13 +636,15 @@ void TwitchChannel::loadCheerEmotes()
|
||||
return lhs.minBits < rhs.minBits; //
|
||||
});
|
||||
|
||||
this->cheerEmoteSets_.emplace_back(cheerEmoteSet);
|
||||
emoteSets.emplace_back(cheerEmoteSet);
|
||||
}
|
||||
*this->cheerEmoteSets_.access() = std::move(emoteSets);
|
||||
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
*/
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchChannel::getTwitchBadge(
|
||||
|
||||
@@ -116,7 +116,6 @@ private:
|
||||
void refreshViewerList();
|
||||
Outcome parseViewerList(const QJsonObject &jsonRoot);
|
||||
void loadRecentMessages();
|
||||
Outcome parseRecentMessages(const QJsonObject &jsonRoot);
|
||||
|
||||
void setLive(bool newLiveStatus);
|
||||
|
||||
@@ -144,7 +143,7 @@ private:
|
||||
|
||||
// "subscribers": { "0": ... "3": ... "6": ...
|
||||
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>> badgeSets_;
|
||||
std::vector<CheerEmoteSet> cheerEmoteSets_;
|
||||
UniqueAccess<std::vector<CheerEmoteSet>> cheerEmoteSets_;
|
||||
|
||||
// --
|
||||
QByteArray messageSuffix_;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <QString>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/Emotemap.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "providers/twitch/EmoteValue.hpp"
|
||||
|
||||
@@ -715,41 +715,38 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
||||
//}
|
||||
} else if (badge == "staff/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.staff),
|
||||
Image::fromPixmap(app->resources->twitch.staff),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Staff");
|
||||
} else if (badge == "admin/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.admin),
|
||||
Image::fromPixmap(app->resources->twitch.admin),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Admin");
|
||||
} else if (badge == "global_mod/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.globalmod),
|
||||
Image::fromPixmap(app->resources->twitch.globalmod),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Global Moderator");
|
||||
} else if (badge == "moderator/1") {
|
||||
// TODO: Implement custom FFZ moderator badge
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.moderator),
|
||||
Image::fromPixmap(app->resources->twitch.moderator),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Channel Moderator");
|
||||
} else if (badge == "turbo/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.turbo),
|
||||
Image::fromPixmap(app->resources->twitch.turbo),
|
||||
MessageElementFlag::BadgeGlobalAuthority)
|
||||
->setTooltip("Twitch Turbo Subscriber");
|
||||
} else if (badge == "broadcaster/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.broadcaster),
|
||||
Image::fromPixmap(app->resources->twitch.broadcaster),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("Twitch Broadcaster");
|
||||
} else if (badge == "premium/1") {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(&app->resources->twitch.prime),
|
||||
Image::fromPixmap(app->resources->twitch.prime),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Prime Subscriber");
|
||||
} else if (badge.startsWith("partner/")) {
|
||||
@@ -757,8 +754,8 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
||||
switch (index) {
|
||||
case 1: {
|
||||
this->emplace<ImageElement>(
|
||||
Image::fromNonOwningPixmap(
|
||||
&app->resources->twitch.verified, 0.25),
|
||||
Image::fromPixmap(app->resources->twitch.verified,
|
||||
0.25),
|
||||
MessageElementFlag::BadgeVanity)
|
||||
->setTooltip("Twitch Verified");
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user