File indexing completed on 2024-10-06 04:34:01
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "messagepinned.h" 0008 #include <QJsonObject> 0009 MessagePinned::MessagePinned() = default; 0010 0011 bool MessagePinned::pinned() const 0012 { 0013 return mPinned; 0014 } 0015 0016 void MessagePinned::setPinned(bool pinned) 0017 { 0018 mPinned = pinned; 0019 } 0020 0021 QString MessagePinned::pinnedBy() const 0022 { 0023 return mPinnedBy; 0024 } 0025 0026 void MessagePinned::setPinnedBy(const QString &pinnedBy) 0027 { 0028 mPinnedBy = pinnedBy; 0029 } 0030 0031 bool MessagePinned::operator==(const MessagePinned &other) const 0032 { 0033 return (mPinned == other.pinned()) && (mPinnedBy == other.pinnedBy()); 0034 } 0035 0036 void MessagePinned::parse(const QJsonObject &o) 0037 { 0038 mPinned = o.value(QLatin1String("pinned")).toBool(); 0039 mPinnedBy = o.value(QLatin1String("pinnedBy")).toObject().value(QLatin1String("username")).toString(); 0040 } 0041 0042 QJsonObject MessagePinned::serialize(const MessagePinned &messagePinned) 0043 { 0044 QJsonObject o; 0045 o[QLatin1String("pinned")] = messagePinned.pinned(); 0046 if (!messagePinned.pinnedBy().isEmpty()) { 0047 o[QLatin1String("pinnedBy")] = messagePinned.pinnedBy(); 0048 } 0049 return o; 0050 } 0051 0052 QDebug operator<<(QDebug d, const MessagePinned &t) 0053 { 0054 d.space() << "isPinned" << t.pinned(); 0055 d.space() << "pinnedby" << t.pinnedBy(); 0056 return d; 0057 } 0058 0059 MessagePinned MessagePinned::deserialize(const QJsonObject &o) 0060 { 0061 MessagePinned pinned; 0062 pinned.setPinned(o[QLatin1String("pinned")].toBool()); 0063 pinned.setPinnedBy(o[QLatin1String("pinnedBy")].toString()); 0064 return pinned; 0065 }