Updated chatterino badges api

This commit is contained in:
fourtf 2019-08-23 16:52:04 +02:00
parent 0c6760d0ca
commit 0577692c99
6 changed files with 23 additions and 18 deletions

View file

@ -20,7 +20,7 @@ AccountController::AccountController()
auto it = std::find(accs.begin(), accs.end(), args.item); auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end()); assert(it != accs.end());
this->accounts_.removeItem(it - accs.begin()); this->accounts_.removeItem(it - accs.begin(), this);
} }
}); });
@ -29,11 +29,13 @@ AccountController::AccountController()
{ {
case ProviderId::Twitch: case ProviderId::Twitch:
{ {
auto &accs = this->twitch.accounts; if (args.caller != this)
auto it = std::find(accs.begin(), accs.end(), args.item); {
assert(it != accs.end()); auto accs = this->twitch.accounts.cloneVector();
auto it = std::find(accs.begin(), accs.end(), args.item);
this->twitch.accounts.removeItem(it - accs.begin(), this); assert(it != accs.end());
this->twitch.accounts.removeItem(it - accs.begin(), this);
}
} }
break; break;
} }

View file

@ -22,9 +22,9 @@ ChatterinoBadges::ChatterinoBadges()
{ {
} }
boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserName &username) boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserId &id)
{ {
auto it = badgeMap.find(username.string); auto it = badgeMap.find(id.string);
if (it != badgeMap.end()) if (it != badgeMap.end())
{ {
return emotes[it->second]; return emotes[it->second];
@ -34,10 +34,9 @@ boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserName &username)
void ChatterinoBadges::loadChatterinoBadges() void ChatterinoBadges::loadChatterinoBadges()
{ {
static QUrl url("https://fourtf.com/chatterino/badges.json"); static QUrl url("https://api.chatterino.com/badges");
NetworkRequest(url) NetworkRequest(url)
.onSuccess([this](auto result) -> Outcome { .onSuccess([this](auto result) -> Outcome {
auto jsonRoot = result.parseJson(); auto jsonRoot = result.parseJson();
int index = 0; int index = 0;
@ -46,7 +45,9 @@ void ChatterinoBadges::loadChatterinoBadges()
auto jsonBadge = jsonBadge_.toObject(); auto jsonBadge = jsonBadge_.toObject();
auto emote = Emote{ auto emote = Emote{
EmoteName{}, EmoteName{},
ImageSet{Url{jsonBadge.value("image").toString()}}, ImageSet{Url{jsonBadge.value("image1").toString()},
Url{jsonBadge.value("image2").toString()},
Url{jsonBadge.value("image3").toString()}},
Tooltip{jsonBadge.value("tooltip").toString()}, Url{}}; Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
emotes.push_back( emotes.push_back(

View file

@ -19,7 +19,7 @@ public:
virtual void initialize(Settings &settings, Paths &paths) override; virtual void initialize(Settings &settings, Paths &paths) override;
ChatterinoBadges(); ChatterinoBadges();
boost::optional<EmotePtr> getBadge(const UserName &username); boost::optional<EmotePtr> getBadge(const UserId &id);
private: private:
void loadChatterinoBadges(); void loadChatterinoBadges();

View file

@ -15,8 +15,9 @@ TwitchAccountManager::TwitchAccountManager()
currentUser->loadIgnores(); currentUser->loadIgnores();
}); });
this->accounts.itemRemoved.connect( this->accounts.itemRemoved.connect([this](const auto &acc) { //
[this](const auto &acc) { this->removeUser(acc.item.get()); }); this->removeUser(acc.item.get());
});
} }
std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent() std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent()

View file

@ -191,6 +191,8 @@ void TwitchMessageBuilder::triggerHighlights()
MessagePtr TwitchMessageBuilder::build() MessagePtr TwitchMessageBuilder::build()
{ {
// PARSING // PARSING
this->userId_ = this->ircMessage->tag("user-id").toString();
this->parseUsername(); this->parseUsername();
if (this->userName == this->channel->getName()) if (this->userName == this->channel->getName())
@ -1276,11 +1278,9 @@ void TwitchMessageBuilder::appendTwitchBadges()
void TwitchMessageBuilder::appendChatterinoBadges() void TwitchMessageBuilder::appendChatterinoBadges()
{ {
auto chatterinoBadgePtr = if (auto badge = getApp()->chatterinoBadges->getBadge({this->userId_}))
getApp()->chatterinoBadges->getBadge({this->userName});
if (chatterinoBadgePtr)
{ {
this->emplace<BadgeElement>(*chatterinoBadgePtr, this->emplace<BadgeElement>(*badge,
MessageElementFlag::BadgeChatterino); MessageElementFlag::BadgeChatterino);
} }
} }

View file

@ -80,6 +80,7 @@ private:
bool hasBits_ = false; bool hasBits_ = false;
bool historicalMessage_ = false; bool historicalMessage_ = false;
QString userId_;
QColor usernameColor_; QColor usernameColor_;
QString originalMessage_; QString originalMessage_;
bool senderIsBroadcaster{}; bool senderIsBroadcaster{};