File indexing completed on 2024-05-12 16:25:36

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "customuserstatus.h"
0008 
0009 #include "utils.h"
0010 
0011 CustomUserStatus::CustomUserStatus() = default;
0012 
0013 CustomUserStatus::~CustomUserStatus() = default;
0014 
0015 bool CustomUserStatus::isValid() const
0016 {
0017     return !mIdentifier.isEmpty() && (mStatusType != User::PresenceStatus::Unknown);
0018 }
0019 
0020 void CustomUserStatus::parseCustomStatus(const QJsonObject &customStatusObj, bool useRestApi)
0021 {
0022     mIdentifier = customStatusObj[QLatin1String("_id")].toString();
0023     mName = customStatusObj[QLatin1String("name")].toString();
0024     mStatusType = Utils::presenceStatusFromString(customStatusObj[QLatin1String("statusType")].toString());
0025     if (customStatusObj.contains(QLatin1String("_updatedAt"))) {
0026         if (useRestApi) {
0027             mUpdatedAt = Utils::parseIsoDate(QStringLiteral("_updatedAt"), customStatusObj);
0028         } else {
0029             mUpdatedAt = Utils::parseDate(QStringLiteral("_updatedAt"), customStatusObj);
0030         }
0031     }
0032 }
0033 
0034 QString CustomUserStatus::name() const
0035 {
0036     return mName;
0037 }
0038 
0039 void CustomUserStatus::setName(const QString &value)
0040 {
0041     mName = value;
0042 }
0043 
0044 qint64 CustomUserStatus::updatedAt() const
0045 {
0046     return mUpdatedAt;
0047 }
0048 
0049 void CustomUserStatus::setUpdatedAt(qint64 updatedAt)
0050 {
0051     mUpdatedAt = updatedAt;
0052 }
0053 
0054 QString CustomUserStatus::identifier() const
0055 {
0056     return mIdentifier;
0057 }
0058 
0059 void CustomUserStatus::setIdentifier(const QString &identifier)
0060 {
0061     mIdentifier = identifier;
0062 }
0063 
0064 User::PresenceStatus CustomUserStatus::statusType() const
0065 {
0066     return mStatusType;
0067 }
0068 
0069 void CustomUserStatus::setStatusType(User::PresenceStatus statusType)
0070 {
0071     mStatusType = statusType;
0072 }
0073 
0074 QDebug operator<<(QDebug d, const CustomUserStatus &t)
0075 {
0076     d.space() << "name" << t.name() << '\n';
0077     d.space() << "identifier" << t.identifier() << '\n';
0078     d.space() << "updatedAt" << t.updatedAt() << '\n';
0079     d.space() << "StatusType" << t.statusType() << '\n';
0080     return d;
0081 }
0082 
0083 bool CustomUserStatus::operator==(const CustomUserStatus &other) const
0084 {
0085     return mIdentifier == other.identifier() && mName == other.name() && mStatusType == other.statusType() && mUpdatedAt == other.updatedAt();
0086 }