summary refs log tree commit diff
path: root/src/Sync.cc
diff options
context:
space:
mode:
authorMax Sandholm <max@sandholm.org>2017-10-01 19:49:36 +0300
committermujx <mujx@users.noreply.github.com>2017-10-01 19:49:36 +0300
commit7ad45d8d6448c60b4c81c80fa8d6d81afd6e4a02 (patch)
tree821124200c7dac85128790115d527791c1fc4945 /src/Sync.cc
parentMore badges (diff)
downloadnheko-7ad45d8d6448c60b4c81c80fa8d6d81afd6e4a02.tar.xz
React to externally left and joined rooms, and add "leave room" button in room menu (#75)
* Initial "join room" feature.
* React correctly to remotely joined rooms.
* Leaving rooms implemented both locally using the room menu
   in nheko, and reacting properly when leaving a room remotely 
   from another client.
Diffstat (limited to 'src/Sync.cc')
-rw-r--r--src/Sync.cc41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/Sync.cc b/src/Sync.cc

index 58c423d1..90314352 100644 --- a/src/Sync.cc +++ b/src/Sync.cc
@@ -90,7 +90,6 @@ Rooms::deserialize(const QJsonValue &data) for (auto it = join.constBegin(); it != join.constEnd(); it++) { JoinedRoom tmp_room; - try { tmp_room.deserialize(it.value()); join_.insert(it.key(), tmp_room); @@ -112,7 +111,19 @@ Rooms::deserialize(const QJsonValue &data) if (!object.value("leave").isObject()) { throw DeserializationException("rooms/leave must be a JSON object"); } - // TODO: Implement leave handling + auto leave = object.value("leave").toObject(); + + for (auto it = leave.constBegin(); it != leave.constEnd(); it++) { + LeftRoom tmp_room; + + try { + tmp_room.deserialize(it.value()); + leave_.insert(it.key(), tmp_room); + } catch (DeserializationException &e) { + qWarning() << e.what(); + qWarning() << "Skipping malformed object for room" << it.key(); + } + } } } @@ -185,6 +196,32 @@ JoinedRoom::deserialize(const QJsonValue &data) } void +LeftRoom::deserialize(const QJsonValue &data) +{ + if (!data.isObject()) + throw DeserializationException("LeftRoom is not a JSON object"); + + QJsonObject object = data.toObject(); + + if (!object.contains("state")) + throw DeserializationException("leave/state is missing"); + + if (!object.contains("timeline")) + throw DeserializationException("leave/timeline is missing"); + + if (!object.value("state").isObject()) + throw DeserializationException("leave/state should be an object"); + + QJsonObject state = object.value("state").toObject(); + + if (!state.contains("events")) + throw DeserializationException("leave/state/events is missing"); + + state_.deserialize(state.value("events")); + timeline_.deserialize(object.value("timeline")); +} + +void Event::deserialize(const QJsonValue &data) { if (!data.isObject())