File indexing completed on 2024-05-12 05:01:25

0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #include "pollevent.h"
0005 
0006 using namespace Quotient;
0007 
0008 PollStartEvent::PollStartEvent(const QJsonObject &obj)
0009     : RoomEvent(obj)
0010 {
0011 }
0012 
0013 int PollStartEvent::maxSelections() const
0014 {
0015     return contentJson()["org.matrix.msc3381.poll.start"_ls]["max_selections"_ls].toInt();
0016 }
0017 
0018 QString PollStartEvent::question() const
0019 {
0020     return contentJson()["org.matrix.msc3381.poll.start"_ls]["question"_ls]["body"_ls].toString();
0021 }
0022 
0023 PollResponseEvent::PollResponseEvent(const QJsonObject &obj)
0024     : RoomEvent(obj)
0025 {
0026 }
0027 
0028 PollEndEvent::PollEndEvent(const QJsonObject &obj)
0029     : RoomEvent(obj)
0030 {
0031 }
0032 
0033 PollResponseEvent::PollResponseEvent(const QString &pollStartEventId, QStringList responses)
0034     : RoomEvent(basicJson(TypeId,
0035                           {{"org.matrix.msc3381.poll.response"_ls, QJsonObject{{"answers"_ls, QJsonArray::fromStringList(responses)}}},
0036                            {"m.relates_to"_ls, QJsonObject{{"rel_type"_ls, "m.reference"_ls}, {"event_id"_ls, pollStartEventId}}}}))
0037 {
0038 }