mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
chatroom emotes
This commit is contained in:
parent
bfa002d3a1
commit
e1ed3553b5
7 changed files with 121 additions and 5 deletions
|
@ -206,6 +206,7 @@ SOURCES += \
|
|||
src/widgets/splits/ClosedSplits.cpp \
|
||||
src/providers/ffz/FfzModBadge.cpp \
|
||||
src/widgets/settingspages/GeneralPage.cpp \
|
||||
src/providers/twitch/ChatroomChannel.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/Application.hpp \
|
||||
|
@ -385,7 +386,8 @@ HEADERS += \
|
|||
src/widgets/splits/ClosedSplits.hpp \
|
||||
src/providers/ffz/FfzModBadge.hpp \
|
||||
src/widgets/settingspages/GeneralPage.hpp \
|
||||
src/messages/HistoricMessageAppearance.hpp
|
||||
src/messages/HistoricMessageAppearance.hpp \
|
||||
src/providers/twitch/ChatroomChannel.hpp
|
||||
|
||||
RESOURCES += \
|
||||
resources/resources.qrc \
|
||||
|
|
44
src/providers/twitch/ChatroomChannel.cpp
Normal file
44
src/providers/twitch/ChatroomChannel.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "ChatroomChannel.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include "TwitchApi.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "messages\Emote.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/bttv/LoadBttvChannelEmote.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
ChatroomChannel::ChatroomChannel(const QString &channelName,
|
||||
TwitchBadges &globalTwitchBadges,
|
||||
BttvEmotes &globalBttv, FfzEmotes &globalFfz)
|
||||
: TwitchChannel(channelName, globalTwitchBadges, globalBttv, globalFfz)
|
||||
{
|
||||
auto list = channelName.split(":");
|
||||
if (list.size() > 2)
|
||||
{
|
||||
this->chatroomOwnerId = list[1];
|
||||
}
|
||||
}
|
||||
|
||||
void ChatroomChannel::refreshChannelEmotes()
|
||||
{
|
||||
TwitchApi::findUserName(
|
||||
this->chatroomOwnerId,
|
||||
[this, weak = weakOf<Channel>(this)](QString username) {
|
||||
qDebug() << username;
|
||||
BttvEmotes::loadChannel(username, [this, weak](auto &&emoteMap) {
|
||||
if (auto shared = weak.lock())
|
||||
this->bttvEmotes_.set(
|
||||
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||
});
|
||||
FfzEmotes::loadChannel(username, [this, weak](auto &&emoteMap) {
|
||||
if (auto shared = weak.lock())
|
||||
this->ffzEmotes_.set(
|
||||
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
25
src/providers/twitch/ChatroomChannel.hpp
Normal file
25
src/providers/twitch/ChatroomChannel.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include "TwitchChannel.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <atomic>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ChatroomChannel : public TwitchChannel
|
||||
{
|
||||
protected:
|
||||
explicit ChatroomChannel(const QString &channelName,
|
||||
TwitchBadges &globalTwitchBadges,
|
||||
BttvEmotes &globalBttv, FfzEmotes &globalFfz);
|
||||
virtual void refreshChannelEmotes() override;
|
||||
|
||||
QString chatroomOwnerId;
|
||||
|
||||
friend class TwitchServer;
|
||||
friend class TwitchMessageBuilder;
|
||||
friend class IrcMessageHandler;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -57,4 +57,31 @@ void TwitchApi::findUserId(const QString user,
|
|||
request.execute();
|
||||
}
|
||||
|
||||
void TwitchApi::findUserName(const QString userid,
|
||||
std::function<void(QString)> successCallback)
|
||||
{
|
||||
QString requestUrl("https://api.twitch.tv/kraken/users/" + userid);
|
||||
|
||||
NetworkRequest request(requestUrl);
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.makeAuthorizedV5(getDefaultClientID());
|
||||
request.setTimeout(30000);
|
||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||
auto root = result.parseJson();
|
||||
auto name = root.value("name");
|
||||
if (!name.isString())
|
||||
{
|
||||
log("API Error: while getting user id, first user object `_id` key "
|
||||
"is not a "
|
||||
"string");
|
||||
successCallback("");
|
||||
return Failure;
|
||||
}
|
||||
successCallback(name.toString());
|
||||
return Success;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -10,6 +10,8 @@ class TwitchApi
|
|||
public:
|
||||
static void findUserId(const QString user,
|
||||
std::function<void(QString)> callback);
|
||||
static void findUserName(const QString userid,
|
||||
std::function<void(QString)> callback);
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -32,7 +32,7 @@ class BttvEmotes;
|
|||
|
||||
class TwitchServer;
|
||||
|
||||
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
|
||||
class TwitchChannel : public Channel, pajlada::Signals::SignalHolder
|
||||
{
|
||||
public:
|
||||
struct StreamStatus {
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
std::shared_ptr<const EmoteMap> bttvEmotes() const;
|
||||
std::shared_ptr<const EmoteMap> ffzEmotes() const;
|
||||
|
||||
void refreshChannelEmotes();
|
||||
virtual void refreshChannelEmotes();
|
||||
|
||||
// Badges
|
||||
boost::optional<EmotePtr> ffzCustomModBadge() const;
|
||||
|
@ -104,10 +104,12 @@ private:
|
|||
QString localizedName;
|
||||
};
|
||||
|
||||
protected:
|
||||
explicit TwitchChannel(const QString &channelName,
|
||||
TwitchBadges &globalTwitchBadges,
|
||||
BttvEmotes &globalBttv, FfzEmotes &globalFfz);
|
||||
|
||||
private:
|
||||
// Methods
|
||||
void refreshLiveStatus();
|
||||
Outcome parseLiveStatus(const rapidjson::Document &document);
|
||||
|
@ -134,11 +136,14 @@ private:
|
|||
|
||||
// Emotes
|
||||
TwitchBadges &globalTwitchBadges_;
|
||||
|
||||
protected:
|
||||
BttvEmotes &globalBttv_;
|
||||
FfzEmotes &globalFfz_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
|
||||
|
||||
private:
|
||||
// Badges
|
||||
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>>
|
||||
badgeSets_; // "subscribers": { "0": ... "3": ... "6": ...
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/ChatroomChannel.hpp"
|
||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||
#include "providers/twitch/PubsubClient.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
|
@ -92,8 +93,18 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
|
|||
|
||||
std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
|
||||
{
|
||||
auto channel = std::shared_ptr<TwitchChannel>(new TwitchChannel(
|
||||
std::shared_ptr<TwitchChannel> channel;
|
||||
if (channelName.left(9).toLower() == "chatrooms")
|
||||
{
|
||||
channel = std::static_pointer_cast<TwitchChannel>(
|
||||
std::shared_ptr<ChatroomChannel>(new ChatroomChannel(
|
||||
channelName, this->twitchBadges, this->bttv, this->ffz)));
|
||||
}
|
||||
else
|
||||
{
|
||||
channel = std::shared_ptr<TwitchChannel>(new TwitchChannel(
|
||||
channelName, this->twitchBadges, this->bttv, this->ffz));
|
||||
}
|
||||
channel->initialize();
|
||||
|
||||
channel->sendMessageSignal.connect(
|
||||
|
|
Loading…
Reference in a new issue