Chatterino
UserData.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <QColor>
7 #include <QString>
8 #include <boost/optional.hpp>
9 #include <pajlada/serialize.hpp>
10 
11 namespace chatterino {
12 
13 // UserData defines a set of data that is defined for a unique user
14 // It can contain things like optional replacement color for the user, a unique alias
15 // or a user note that should be displayed with the user
16 // Replacement fields should be optional, where none denotes that the field should not be updated for the user
17 struct UserData {
18  boost::optional<QColor> color{boost::none};
19 
20  // TODO: User note?
21 };
22 
23 } // namespace chatterino
24 
25 namespace pajlada {
26 
27 template <>
28 struct Serialize<chatterino::UserData> {
29  static rapidjson::Value get(const chatterino::UserData &value,
30  rapidjson::Document::AllocatorType &a)
31  {
32  rapidjson::Value obj;
33  obj.SetObject();
34  if (value.color)
35  {
36  const auto &color = *value.color;
37  chatterino::rj::set(obj, "color",
38  color.name().toUtf8().toStdString(), a);
39  }
40  return obj;
41  }
42 };
43 
44 template <>
45 struct Deserialize<chatterino::UserData> {
46  static chatterino::UserData get(const rapidjson::Value &value,
47  bool *error = nullptr)
48  {
49  if (!value.IsObject())
50  {
51  PAJLADA_REPORT_ERROR(error)
52  return chatterino::UserData{};
53  }
54 
56 
57  QString colorString;
58  if (chatterino::rj::getSafe(value, "color", colorString))
59  {
60  QColor color(colorString);
61  if (color.isValid())
62  {
63  user.color = color;
64  }
65  }
66 
67  return user;
68  }
69 };
70 
71 } // namespace pajlada
Definition: UserData.hpp:17
Definition: Application.cpp:48
void set(rapidjson::Value &obj, const char *key, const Type &value, rapidjson::Document::AllocatorType &a)
Definition: RapidjsonHelpers.hpp:22
Definition: Command.hpp:25
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
Definition: RapidjsonHelpers.hpp:73
boost::optional< QColor > color
Definition: UserData.hpp:18