Chatterino
TwitchUser.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <rapidjson/document.h>
7 #include <QString>
8 #include <pajlada/serialize.hpp>
9 
10 #include <cassert>
11 
12 namespace chatterino {
13 
14 struct TwitchUser {
15  QString id;
16  mutable QString name;
17  mutable QString displayName;
18 
19  void update(const TwitchUser &other) const
20  {
21  assert(this->id == other.id);
22 
23  this->name = other.name;
24  this->displayName = other.displayName;
25  }
26 
27  void fromHelixBlock(const HelixBlock &ignore)
28  {
29  this->id = ignore.userId;
30  this->name = ignore.userName;
31  this->displayName = ignore.displayName;
32  }
33 
34  bool operator<(const TwitchUser &rhs) const
35  {
36  return this->id < rhs.id;
37  }
38 };
39 
40 } // namespace chatterino
41 
42 namespace pajlada {
43 
44 template <>
45 struct Deserialize<chatterino::TwitchUser> {
46  static chatterino::TwitchUser get(const rapidjson::Value &value,
47  bool *error = nullptr)
48  {
49  using namespace chatterino;
50 
51  TwitchUser user;
52 
53  if (!value.IsObject())
54  {
55  PAJLADA_REPORT_ERROR(error)
56  return user;
57  }
58 
59  if (!rj::getSafe(value, "_id", user.id))
60  {
61  PAJLADA_REPORT_ERROR(error)
62  return user;
63  }
64 
65  if (!rj::getSafe(value, "name", user.name))
66  {
67  PAJLADA_REPORT_ERROR(error)
68  return user;
69  }
70 
71  if (!rj::getSafe(value, "display_name", user.displayName))
72  {
73  PAJLADA_REPORT_ERROR(error)
74  return user;
75  }
76 
77  return user;
78  }
79 };
80 
81 } // namespace pajlada
QString name
Definition: TwitchUser.hpp:16
QString displayName
Definition: TwitchUser.hpp:17
Definition: Application.cpp:48
void update(const TwitchUser &other) const
Definition: TwitchUser.hpp:19
QString userId
Definition: Helix.hpp:191
void fromHelixBlock(const HelixBlock &ignore)
Definition: TwitchUser.hpp:27
QString userName
Definition: Helix.hpp:192
QString id
Definition: TwitchUser.hpp:15
Definition: Command.hpp:25
QString displayName
Definition: Helix.hpp:193
Definition: TwitchUser.hpp:14
bool operator<(const TwitchUser &rhs) const
Definition: TwitchUser.hpp:34
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
Definition: RapidjsonHelpers.hpp:73
Definition: Helix.hpp:190