File indexing completed on 2024-12-01 04:35:46

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 "channelcounterinfo.h"
0008 
0009 ChannelCounterInfo::ChannelCounterInfo() = default;
0010 
0011 ChannelCounterInfo::~ChannelCounterInfo() = default;
0012 
0013 void ChannelCounterInfo::parseCounterInfo(const QJsonObject &replyObject)
0014 {
0015     mMessageCount = replyObject.value(QLatin1String("msgs")).toInt();
0016     mUnreadMessages = replyObject.value(QLatin1String("unreads")).toInt();
0017     mJoined = replyObject.value(QLatin1String("joined")).toBool();
0018     mUnreadFrom = QDateTime::fromString(replyObject.value(QLatin1String("unreadsFrom")).toString(), Qt::ISODate);
0019     mUnreadFrom = mUnreadFrom.toTimeSpec(Qt::LocalTime);
0020     mUnreadMessageTimeStep = mUnreadFrom.toMSecsSinceEpoch();
0021 }
0022 
0023 bool ChannelCounterInfo::operator==(const ChannelCounterInfo &other) const
0024 {
0025     return mUnreadMessages == other.unreadMessages() && mMessageCount == other.messageCount() && mUnreadFrom == other.unreadFrom() && mJoined == other.joined();
0026 }
0027 
0028 bool ChannelCounterInfo::operator!=(const ChannelCounterInfo &other) const
0029 {
0030     return !operator==(other);
0031 }
0032 
0033 quint64 ChannelCounterInfo::unreadMessages() const
0034 {
0035     return mUnreadMessages;
0036 }
0037 
0038 void ChannelCounterInfo::setUnreadMessages(quint64 unreadMessages)
0039 {
0040     mUnreadMessages = unreadMessages;
0041 }
0042 
0043 QDateTime ChannelCounterInfo::unreadFrom() const
0044 {
0045     return mUnreadFrom;
0046 }
0047 
0048 void ChannelCounterInfo::setUnreadFrom(const QDateTime &unreadFrom)
0049 {
0050     mUnreadFrom = unreadFrom;
0051 }
0052 
0053 quint64 ChannelCounterInfo::messageCount() const
0054 {
0055     return mMessageCount;
0056 }
0057 
0058 void ChannelCounterInfo::setMessageCount(quint64 messageCount)
0059 {
0060     mMessageCount = messageCount;
0061 }
0062 
0063 bool ChannelCounterInfo::joined() const
0064 {
0065     return mJoined;
0066 }
0067 
0068 void ChannelCounterInfo::setJoined(bool joined)
0069 {
0070     mJoined = joined;
0071 }
0072 
0073 bool ChannelCounterInfo::isValid() const
0074 {
0075     return mUnreadFrom.isValid();
0076 }
0077 
0078 qint64 ChannelCounterInfo::unreadMessageTimeStep() const
0079 {
0080     return mUnreadMessageTimeStep;
0081 }
0082 
0083 void ChannelCounterInfo::setUnreadMessageTimeStep(qint64 unreadMessageTimeStep)
0084 {
0085     mUnreadMessageTimeStep = unreadMessageTimeStep;
0086 }
0087 
0088 QDebug operator<<(QDebug d, const ChannelCounterInfo &t)
0089 {
0090     d.space() << "Unread Messages" << t.unreadMessages();
0091     d.space() << "Messages count" << t.messageCount();
0092     d.space() << "Unread from" << t.unreadFrom();
0093     d.space() << "joined" << t.joined();
0094     return d;
0095 }