File indexing completed on 2024-05-12 05:02:10

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "moderationreportinfo.h"
0008 #include "utils.h"
0009 
0010 #include <QLocale>
0011 
0012 ModerationReportInfo::ModerationReportInfo() = default;
0013 
0014 ModerationReportInfo::~ModerationReportInfo() = default;
0015 
0016 bool ModerationReportInfo::operator==(const ModerationReportInfo &other) const
0017 {
0018     return mDescription == other.description() && mReportIdentifier == other.reportIdentifier() && mTimeStamp == other.timeStamp() && mRoomId == other.roomId()
0019         && mUserId == other.userId() && mUserName == other.userName();
0020 }
0021 
0022 void ModerationReportInfo::parseModerationReportInfo(const QJsonObject &o)
0023 {
0024     mReportIdentifier = o[QLatin1String("_id")].toString();
0025     mDescription = o[QLatin1String("description")].toString();
0026     setTimeStamp(Utils::parseIsoDate(QStringLiteral("ts"), o));
0027     parseRoom(o[QLatin1String("room")].toObject());
0028     parseReportedBy(o[QLatin1String("reportedBy")].toObject());
0029     // TODO add more
0030     //{"reports":[{"_id":"6523e2465d66533fd6f85856","description":"test message report\n","reportedBy":{"_id":"H7Q9djXQ4zD9T2","username":"bla","name":"foo",
0031     // "createdAt":"2018-03-13T16:11:51.761Z"},"room":{"_id":"bBvCRnStXcG68zjna","name":"roomname","t":"p","fname":"roomname"},
0032     // "ts":"2023-10-09T11:21:42.135Z"}],"count":1,"offset":0,"total":1,"success":true}
0033 }
0034 
0035 QString ModerationReportInfo::timeStampDateTimeStr() const
0036 {
0037     return mTimeStampDateTimeStr;
0038 }
0039 
0040 qint64 ModerationReportInfo::timeStamp() const
0041 {
0042     return mTimeStamp;
0043 }
0044 
0045 void ModerationReportInfo::setTimeStamp(qint64 newTimeStamp)
0046 {
0047     mTimeStamp = newTimeStamp;
0048     QLocale l;
0049     mTimeStampDateTimeStr = l.toString(QDateTime::fromMSecsSinceEpoch(mTimeStamp), QLocale::LongFormat);
0050 }
0051 
0052 QString ModerationReportInfo::description() const
0053 {
0054     return mDescription;
0055 }
0056 
0057 void ModerationReportInfo::setDescription(const QString &newDescription)
0058 {
0059     mDescription = newDescription;
0060 }
0061 
0062 QString ModerationReportInfo::reportIdentifier() const
0063 {
0064     return mReportIdentifier;
0065 }
0066 
0067 void ModerationReportInfo::setReportIdentifier(const QString &newReportIdentifier)
0068 {
0069     mReportIdentifier = newReportIdentifier;
0070 }
0071 
0072 void ModerationReportInfo::parseReportedBy(const QJsonObject &o)
0073 {
0074     mUserId = o[QLatin1String("_id")].toString();
0075     mUserName = o[QLatin1String("username")].toString();
0076     // TODO
0077 }
0078 
0079 QString ModerationReportInfo::userName() const
0080 {
0081     return mUserName;
0082 }
0083 
0084 void ModerationReportInfo::setUserName(const QString &newUserName)
0085 {
0086     mUserName = newUserName;
0087 }
0088 
0089 QString ModerationReportInfo::userId() const
0090 {
0091     return mUserId;
0092 }
0093 
0094 void ModerationReportInfo::setUserId(const QString &newUserId)
0095 {
0096     mUserId = newUserId;
0097 }
0098 
0099 QString ModerationReportInfo::roomId() const
0100 {
0101     return mRoomId;
0102 }
0103 
0104 void ModerationReportInfo::setRoomId(const QString &newRoomId)
0105 {
0106     mRoomId = newRoomId;
0107 }
0108 
0109 void ModerationReportInfo::parseRoom(const QJsonObject &o)
0110 {
0111     mRoomId = o[QLatin1String("_id")].toString();
0112     // TODO add more ? roomName etc ?
0113 }
0114 
0115 QDebug operator<<(QDebug d, const ModerationReportInfo &t)
0116 {
0117     d.space() << "mDescription" << t.description();
0118     d.space() << "mReportIdentifier" << t.reportIdentifier();
0119     d.space() << "mTimeStamp" << t.timeStamp();
0120     d.space() << "mRoomId" << t.roomId();
0121     d.space() << "mUserId" << t.userId();
0122     d.space() << "mUserName" << t.userName();
0123     return d;
0124 }