summary refs log tree commit diff
path: root/src/Community.cc
diff options
context:
space:
mode:
authorMax Sandholm <max@sandholm.org>2018-01-09 15:07:32 +0200
committermujx <mujx@users.noreply.github.com>2018-01-09 15:07:32 +0200
commit312df6f3bbcba0ad502864b13f9c51b4854ea2ce (patch)
treed43396836cb2ba21b13f218a6d25a7c82049338b /src/Community.cc
parentMake usernames in timeline less bold (diff)
downloadnheko-312df6f3bbcba0ad502864b13f9c51b4854ea2ce.tar.xz
Communities (#195)
Diffstat (limited to 'src/Community.cc')
-rw-r--r--src/Community.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Community.cc b/src/Community.cc
new file mode 100644

index 00000000..df425e88 --- /dev/null +++ b/src/Community.cc
@@ -0,0 +1,44 @@ +#include "include/Community.h" + +#include <QJsonArray> +#include <QJsonValue> + +void +Community::parseProfile(const QJsonObject &profile) +{ + if (profile["name"].type() == QJsonValue::Type::String) { + name_ = profile["name"].toString(); + } else { + name_ = "Unnamed Community"; // TODO: what is correct here? + } + + if (profile["avatar_url"].type() == QJsonValue::Type::String) { + avatar_ = QUrl(profile["avatar_url"].toString()); + } else { + avatar_ = QUrl(); + } + + if (profile["short_description"].type() == QJsonValue::Type::String) { + short_description_ = profile["short_description"].toString(); + } else { + short_description_ = ""; + } + + if (profile["long_description"].type() == QJsonValue::Type::String) { + long_description_ = profile["long_description"].toString(); + } else { + long_description_ = ""; + } +} + +void +Community::parseRooms(const QJsonObject &rooms) +{ + rooms_.clear(); + + for (auto i = 0; i < rooms["chunk"].toArray().size(); i++) { + rooms_.append(rooms["chunk"].toArray()[i].toObject()["room_id"].toString()); + } + + emit roomsChanged(rooms_); +}