Chatterino
TwitchAccount.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "common/Aliases.hpp"
4 #include "common/Atomic.hpp"
5 #include "common/Channel.hpp"
8 #include "messages/Emote.hpp"
10 #include "util/QStringHash.hpp"
11 
12 #include <rapidjson/document.h>
13 #include <QColor>
14 #include <QElapsedTimer>
15 #include <QString>
16 
17 #include <functional>
18 #include <mutex>
19 #include <set>
20 
21 namespace chatterino {
22 
27 };
28 
30  const QString channelName;
31  const QString channelId;
32  const QString type;
33  const int tier;
34  const bool isCustom;
35  // Example response:
36  // {
37  // "channel_name": "zneix",
38  // "channel_id": "99631238",
39  // "type": "",
40  // "tier": 1,
41  // "custom": false
42  // }
43 
44  TwitchEmoteSetResolverResponse(QJsonObject jsonObject)
45  : channelName(jsonObject.value("channel_name").toString())
46  , channelId(jsonObject.value("channel_id").toString())
47  , type(jsonObject.value("type").toString())
48  , tier(jsonObject.value("tier").toInt())
49  , isCustom(jsonObject.value("custom").toBool())
50  {
51  }
52 };
53 
54 std::vector<QStringList> getEmoteSetBatches(QStringList emoteSetKeys);
55 
56 class TwitchAccount : public Account
57 {
58 public:
59  struct TwitchEmote {
60  EmoteId id;
61  EmoteName name;
62  };
63 
64  struct EmoteSet {
65  QString key;
66  QString channelName;
67  QString text;
68  bool local{false};
69  std::vector<TwitchEmote> emotes;
70  };
71 
72  std::map<QString, EmoteSet> staticEmoteSets;
73 
75  std::vector<std::shared_ptr<EmoteSet>> emoteSets;
76 
77  // this EmoteMap should contain all emotes available globally
78  // excluding locally available emotes, such as follower ones
80  };
81 
82  TwitchAccount(const QString &username, const QString &oauthToken_,
83  const QString &oauthClient_, const QString &_userID);
84 
85  virtual QString toString() const override;
86 
87  const QString &getUserName() const;
88  const QString &getOAuthToken() const;
89  const QString &getOAuthClient() const;
90  const QString &getUserId() const;
91 
92  QColor color();
93  void setColor(QColor color);
94 
95  // Attempts to update the users OAuth Client ID
96  // Returns true if the value has changed, otherwise false
97  bool setOAuthClient(const QString &newClientID);
98 
99  // Attempts to update the users OAuth Token
100  // Returns true if the value has changed, otherwise false
101  bool setOAuthToken(const QString &newOAuthToken);
102 
103  bool isAnon() const;
104 
105  void loadBlocks();
106  void blockUser(QString userId, std::function<void()> onSuccess,
107  std::function<void()> onFailure);
108  void unblockUser(QString userId, std::function<void()> onSuccess,
109  std::function<void()> onFailure);
110 
111  SharedAccessGuard<const std::set<QString>> accessBlockedUserIds() const;
112  SharedAccessGuard<const std::set<TwitchUser>> accessBlocks() const;
113 
114  void loadEmotes(std::weak_ptr<Channel> weakChannel = {});
115  // loadUserstateEmotes loads emote sets that are part of the USERSTATE emote-sets key
116  // this function makes sure not to load emote sets that have already been loaded
117  void loadUserstateEmotes(std::weak_ptr<Channel> weakChannel = {});
118  // setUserStateEmoteSets sets the emote sets that were parsed from the USERSTATE emote-sets key
119  // Returns true if the newly inserted emote sets differ from the ones previously saved
120  [[nodiscard]] bool setUserstateEmoteSets(QStringList newEmoteSets);
123  accessLocalEmotes() const;
124 
125  // Automod actions
126  void autoModAllow(const QString msgID, ChannelPtr channel);
127  void autoModDeny(const QString msgID, ChannelPtr channel);
128 
129 private:
130  void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet);
131 
132  QString oauthClient_;
133  QString oauthToken_;
134  QString userName_;
135  QString userId_;
136  const bool isAnon_;
137  Atomic<QColor> color_;
138 
139  mutable std::mutex ignoresMutex_;
140  QStringList userstateEmoteSets_;
142  UniqueAccess<std::set<QString>> ignoresUserIds_;
143 
144  // std::map<UserId, TwitchAccountEmoteData> emotes;
147 };
148 
149 } // namespace chatterino
Definition: TwitchAccount.hpp:56
QString text
Definition: TwitchAccount.hpp:67
FollowResult
Definition: TwitchAccount.hpp:23
std::vector< QStringList > getEmoteSetBatches(QStringList emoteSetKeys)
Definition: Account.hpp:9
Definition: TwitchAccount.hpp:59
std::map< QString, EmoteSet > staticEmoteSets
Definition: TwitchAccount.hpp:72
std::vector< std::shared_ptr< EmoteSet > > emoteSets
Definition: TwitchAccount.hpp:75
Definition: UniqueAccess.hpp:10
QString key
Definition: TwitchAccount.hpp:65
std::vector< TwitchEmote > emotes
Definition: TwitchAccount.hpp:69
Definition: Application.cpp:48
const QString type
Definition: TwitchAccount.hpp:32
EmoteId id
Definition: TwitchAccount.hpp:60
Definition: TwitchAccount.hpp:29
Definition: TwitchAccount.hpp:24
Definition: Emote.hpp:40
TwitchEmoteSetResolverResponse(QJsonObject jsonObject)
Definition: TwitchAccount.hpp:44
Definition: UniqueAccess.hpp:53
const bool isCustom
Definition: TwitchAccount.hpp:34
EmoteName name
Definition: TwitchAccount.hpp:61
const QString channelId
Definition: TwitchAccount.hpp:31
const int tier
Definition: TwitchAccount.hpp:33
Definition: TwitchAccount.hpp:64
QString channelName
Definition: TwitchAccount.hpp:66
std::shared_ptr< Channel > ChannelPtr
Definition: Channel.hpp:125
EmoteMap emotes
Definition: TwitchAccount.hpp:79
Definition: TwitchAccount.hpp:26
Definition: TwitchAccount.hpp:25
const QString channelName
Definition: TwitchAccount.hpp:30