File indexing completed on 2023-11-26 08:17:49
0001 /* 0002 SPDX-FileCopyrightText: 2018-2023 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "channel.h" 0008 #include "utils.h" 0009 0010 #include <QJsonObject> 0011 0012 Channel::Channel() = default; 0013 0014 Channel::~Channel() = default; 0015 0016 void Channel::parseChannel(const QJsonObject &object, ChannelType type) 0017 { 0018 mType = type; 0019 if (mType == ChannelType::DirectChannel) { 0020 mUserId = object.value(QLatin1String("_id")).toString(); 0021 mName = object.value(QLatin1String("name")).toString(); 0022 mStatus = object.value(QLatin1String("status")).toString(); 0023 mUserName = object.value(QLatin1String("username")).toString(); 0024 } else { 0025 mRoomId = object.value(QLatin1String("_id")).toString(); 0026 mRoomName = object.value(QLatin1String("name")).toString(); 0027 mRoomType = object.value(QLatin1String("t")).toString(); 0028 } 0029 } 0030 0031 Channel::ChannelType Channel::type() const 0032 { 0033 return mType; 0034 } 0035 0036 void Channel::setType(ChannelType type) 0037 { 0038 mType = type; 0039 } 0040 0041 bool Channel::operator==(const Channel &other) const 0042 { 0043 return (mType == other.type()) && (mRoomId == other.roomId()) && (mRoomType == other.roomType()) && (mRoomName == other.roomName()) 0044 && (mUserId == other.userId()) && (mName == other.name()) && (mStatus == other.status()) && (mUserName == other.userName()); 0045 } 0046 0047 QString Channel::roomId() const 0048 { 0049 return mRoomId; 0050 } 0051 0052 void Channel::setRoomId(const QString &roomId) 0053 { 0054 mRoomId = roomId; 0055 } 0056 0057 QString Channel::roomName() const 0058 { 0059 return mRoomName; 0060 } 0061 0062 void Channel::setRoomName(const QString &roomName) 0063 { 0064 mRoomName = roomName; 0065 } 0066 0067 QString Channel::roomType() const 0068 { 0069 return mRoomType; 0070 } 0071 0072 void Channel::setRoomType(const QString &roomType) 0073 { 0074 mRoomType = roomType; 0075 } 0076 0077 QString Channel::userId() const 0078 { 0079 return mUserId; 0080 } 0081 0082 void Channel::setUserId(const QString &userId) 0083 { 0084 mUserId = userId; 0085 } 0086 0087 QString Channel::name() const 0088 { 0089 return mName; 0090 } 0091 0092 void Channel::setName(const QString &name) 0093 { 0094 mName = name; 0095 } 0096 0097 QString Channel::status() const 0098 { 0099 return mStatus; 0100 } 0101 0102 void Channel::setStatus(const QString &status) 0103 { 0104 mStatus = status; 0105 } 0106 0107 QString Channel::userName() const 0108 { 0109 return mUserName; 0110 } 0111 0112 void Channel::setUserName(const QString &userName) 0113 { 0114 mUserName = userName; 0115 } 0116 0117 QString Channel::iconFromStatus() const 0118 { 0119 return Utils::iconFromStatus(mStatus); 0120 } 0121 0122 QDebug operator<<(QDebug d, const Channel &t) 0123 { 0124 d << "type: " << t.type(); 0125 d << "roomName: " << t.roomName(); 0126 d << "roomType: " << t.roomType(); 0127 d << "roomId: " << t.roomId(); 0128 d << "mUserId " << t.userId(); 0129 d << "mName " << t.name(); 0130 d << "mStatus " << t.status(); 0131 d << "mUserName " << t.userName(); 0132 0133 return d; 0134 } 0135 0136 #include "moc_channel.cpp"