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

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "moderationinfo.h"
0008 #include "utils.h"
0009 
0010 ModerationInfo::ModerationInfo() = default;
0011 
0012 QDebug operator<<(QDebug d, const ModerationInfo &t)
0013 {
0014     d.space() << "userId" << t.userId();
0015     d.space() << "name" << t.name();
0016     d.space() << "username" << t.userName();
0017     d.space() << "msgId" << t.msgId();
0018     d.space() << "mCount" << t.count();
0019     d.space() << "mIsUserDeleted" << t.isUserDeleted();
0020     d.space() << "mMessage" << t.message();
0021     d.space() << "mCreatedAt" << t.createdAt();
0022     d.space() << "mRoomName" << t.roomList();
0023     return d;
0024 }
0025 
0026 // obj QJsonObject({"count":1,"offset":0,"reports":[{"count":1,"isUserDeleted":false,"message":"Fghd","msgId":"eJ443teFnx7hTG5pZ","name":"Laurent m",
0027 // "rooms":[{"_id":"GotJhd87jLScanhwr","fname":"test4","name":"test4","t":"c"}],"ts":"2023-09-20T15:09:37.959Z","userId":"dddd","username":"laurent"}],
0028 // "success":true,"total":1})
0029 bool ModerationInfo::operator==(const ModerationInfo &other) const
0030 {
0031     return mUserId == other.mUserId && mName == other.mName && mUserName == other.mUserName && mUserId == other.mUserId && mCount == other.mCount
0032         && mIsUserDeleted == other.mIsUserDeleted && mMessage == other.mMessage && mCreatedAt == other.mCreatedAt && mRoomList == other.mRoomList;
0033 }
0034 
0035 void ModerationInfo::parseRoomList(const QJsonArray &rooms)
0036 {
0037     for (int i = 0; i < rooms.size(); i++) {
0038         const QJsonObject o = rooms.at(i).toObject();
0039         const QString fname = o[QLatin1String("fname")].toString();
0040         const QString name = o[QLatin1String("name")].toString();
0041         mRoomList.append(fname.isEmpty() ? name : fname);
0042     }
0043 }
0044 
0045 void ModerationInfo::parseModerationInfo(const QJsonObject &o)
0046 {
0047     // qDebug() << " ModerationInfo " << o;
0048     mUserId = o[QLatin1String("userId")].toString();
0049     mName = o[QLatin1String("name")].toString();
0050     mUserName = o[QLatin1String("username")].toString();
0051     mMsgId = o[QLatin1String("msgId")].toString();
0052     mCount = o[QLatin1String("count")].toInt();
0053     mIsUserDeleted = o[QLatin1String("isUserDeleted")].toBool();
0054     mMessage = o[QLatin1String("message")].toString();
0055     setCreatedAt(Utils::parseIsoDate(QStringLiteral("ts"), o));
0056     parseRoomList(o[QLatin1String("rooms")].toArray());
0057 }
0058 
0059 void ModerationInfo::setCreatedAt(qint64 newCreatedAt)
0060 {
0061     mCreatedAt = newCreatedAt;
0062     if (mCreatedAt != -1) {
0063         QLocale l;
0064         mCreateAtDisplayDateTime = l.toString(QDateTime::fromMSecsSinceEpoch(mCreatedAt), QLocale::LongFormat);
0065     }
0066 }
0067 
0068 QStringList ModerationInfo::roomList() const
0069 {
0070     return mRoomList;
0071 }
0072 
0073 void ModerationInfo::setRoomList(const QStringList &newRoomName)
0074 {
0075     mRoomList = newRoomName;
0076 }
0077 
0078 qint64 ModerationInfo::createdAt() const
0079 {
0080     return mCreatedAt;
0081 }
0082 
0083 const QString &ModerationInfo::createAtDisplayDateTime() const
0084 {
0085     return mCreateAtDisplayDateTime;
0086 }
0087 
0088 QString ModerationInfo::userId() const
0089 {
0090     return mUserId;
0091 }
0092 
0093 void ModerationInfo::setUserId(const QString &newUserId)
0094 {
0095     mUserId = newUserId;
0096 }
0097 
0098 QString ModerationInfo::name() const
0099 {
0100     return mName;
0101 }
0102 
0103 void ModerationInfo::setName(const QString &newName)
0104 {
0105     mName = newName;
0106 }
0107 
0108 QString ModerationInfo::userName() const
0109 {
0110     return mUserName;
0111 }
0112 
0113 void ModerationInfo::setUserName(const QString &newUserName)
0114 {
0115     mUserName = newUserName;
0116 }
0117 
0118 QString ModerationInfo::msgId() const
0119 {
0120     return mMsgId;
0121 }
0122 
0123 void ModerationInfo::setMsgId(const QString &newMsgId)
0124 {
0125     mMsgId = newMsgId;
0126 }
0127 
0128 int ModerationInfo::count() const
0129 {
0130     return mCount;
0131 }
0132 
0133 void ModerationInfo::setCount(int newCount)
0134 {
0135     mCount = newCount;
0136 }
0137 
0138 bool ModerationInfo::isUserDeleted() const
0139 {
0140     return mIsUserDeleted;
0141 }
0142 
0143 void ModerationInfo::setIsUserDeleted(bool newIsUserDeleted)
0144 {
0145     mIsUserDeleted = newIsUserDeleted;
0146 }
0147 
0148 QString ModerationInfo::message() const
0149 {
0150     return mMessage;
0151 }
0152 
0153 void ModerationInfo::setMessage(const QString &newMessage)
0154 {
0155     mMessage = newMessage;
0156 }