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

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "inviteinfo.h"
0008 #include "utils.h"
0009 
0010 InviteInfo::InviteInfo() = default;
0011 
0012 void InviteInfo::parseInviteInfo(const QJsonObject &replyObject)
0013 {
0014     mIdentifier = replyObject[QLatin1String("_id")].toString();
0015     mUserIdentifier = replyObject[QLatin1String("userId")].toString();
0016     mRoomId = replyObject[QLatin1String("rid")].toString();
0017     mUses = replyObject[QLatin1String("uses")].toInt();
0018     mMaxUses = replyObject[QLatin1String("maxUses")].toInt();
0019     if (replyObject.contains(QLatin1String("createdAt"))) {
0020         setCreateDateTime(QDateTime::fromMSecsSinceEpoch(Utils::parseIsoDate(QStringLiteral("createdAt"), replyObject)));
0021     }
0022     if (replyObject.contains(QLatin1String("expires"))) {
0023         setExpireDateTime(QDateTime::fromMSecsSinceEpoch(Utils::parseIsoDate(QStringLiteral("expires"), replyObject)));
0024     }
0025 }
0026 
0027 const QString &InviteInfo::identifier() const
0028 {
0029     return mIdentifier;
0030 }
0031 
0032 void InviteInfo::setIdentifier(const QString &newIdentifier)
0033 {
0034     mIdentifier = newIdentifier;
0035 }
0036 
0037 int InviteInfo::maxUses() const
0038 {
0039     return mMaxUses;
0040 }
0041 
0042 void InviteInfo::setMaxUses(int newMaxUses)
0043 {
0044     mMaxUses = newMaxUses;
0045 }
0046 
0047 const QString &InviteInfo::userIdentifier() const
0048 {
0049     return mUserIdentifier;
0050 }
0051 
0052 void InviteInfo::setUserIdentifier(const QString &newUserIdentifier)
0053 {
0054     mUserIdentifier = newUserIdentifier;
0055 }
0056 
0057 const QString &InviteInfo::roomId() const
0058 {
0059     return mRoomId;
0060 }
0061 
0062 void InviteInfo::setRoomId(const QString &newRoomId)
0063 {
0064     mRoomId = newRoomId;
0065 }
0066 
0067 int InviteInfo::uses() const
0068 {
0069     return mUses;
0070 }
0071 
0072 void InviteInfo::setUses(int newUses)
0073 {
0074     mUses = newUses;
0075 }
0076 
0077 const QDateTime &InviteInfo::expireDateTime() const
0078 {
0079     return mExpireDateTime;
0080 }
0081 
0082 void InviteInfo::setExpireDateTime(const QDateTime &newExpireDateTime)
0083 {
0084     mExpireDateTime = newExpireDateTime;
0085 }
0086 
0087 const QDateTime &InviteInfo::createDateTime() const
0088 {
0089     return mCreateDateTime;
0090 }
0091 
0092 void InviteInfo::setCreateDateTime(const QDateTime &newCreateDateTime)
0093 {
0094     mCreateDateTime = newCreateDateTime;
0095 }
0096 
0097 bool InviteInfo::operator==(const InviteInfo &other) const
0098 {
0099     return mUserIdentifier == other.userIdentifier() && mIdentifier == other.identifier() && mRoomId == other.roomId()
0100         && mExpireDateTime == other.expireDateTime() && mCreateDateTime == other.createDateTime() && mUses == other.uses() && mMaxUses == other.maxUses();
0101 }
0102 
0103 QDebug operator<<(QDebug d, const InviteInfo &t)
0104 {
0105     d.space() << "mIdentifier:" << t.identifier();
0106     d.space() << "mUserIdentifier:" << t.userIdentifier();
0107     d.space() << "mMaxUses:" << t.maxUses();
0108     d.space() << "uses:" << t.uses();
0109     d.space() << "mRoomId:" << t.roomId();
0110     d.space() << "mExpireDateTime:" << t.expireDateTime();
0111     d.space() << "mCreateDateTime:" << t.createDateTime();
0112     return d;
0113 }