Warning, file /network/ruqola/src/core/notificationinfo.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "notificationinfo.h"
0008 #include "ruqola_debug.h"
0009 #include <QJsonObject>
0010 
0011 NotificationInfo::NotificationInfo() = default;
0012 
0013 NotificationInfo::~NotificationInfo() = default;
0014 
0015 QDebug operator<<(QDebug d, const NotificationInfo &t)
0016 {
0017     d << " accountName " << t.accountName();
0018     d << " message " << t.message();
0019     d << " title " << t.title();
0020     d << " sender " << t.senderId();
0021     d << " senderName " << t.senderName();
0022     d << " mSenderUserName " << t.senderUserName();
0023     d << " roomName " << t.roomName();
0024     d << " roomId " << t.roomId();
0025     d << " type " << t.channelType();
0026     d << " tmId " << t.tmId();
0027     d << " pixmap is null ? " << t.pixmap().isNull();
0028     d << " date time " << t.dateTime();
0029     d << " messageId " << t.messageId();
0030     d << " mNotificationType " << t.notificationType();
0031     return d;
0032 }
0033 
0034 const QString &NotificationInfo::accountName() const
0035 {
0036     return mAccountName;
0037 }
0038 
0039 void NotificationInfo::setAccountName(const QString &newAccountName)
0040 {
0041     mAccountName = newAccountName;
0042 }
0043 
0044 const QString &NotificationInfo::message() const
0045 {
0046     return mMessage;
0047 }
0048 
0049 void NotificationInfo::setMessage(const QString &newMessage)
0050 {
0051     mMessage = newMessage;
0052 }
0053 
0054 const QString &NotificationInfo::title() const
0055 {
0056     return mTitle;
0057 }
0058 
0059 void NotificationInfo::setTitle(const QString &newTitle)
0060 {
0061     mTitle = newTitle;
0062 }
0063 
0064 const QString &NotificationInfo::senderId() const
0065 {
0066     return mSenderId;
0067 }
0068 
0069 void NotificationInfo::setSenderId(const QString &newSenderId)
0070 {
0071     mSenderId = newSenderId;
0072 }
0073 
0074 const QString &NotificationInfo::senderName() const
0075 {
0076     return mSenderName;
0077 }
0078 
0079 void NotificationInfo::setSenderName(const QString &newSenderName)
0080 {
0081     mSenderName = newSenderName;
0082 }
0083 
0084 const QString &NotificationInfo::senderUserName() const
0085 {
0086     return mSenderUserName;
0087 }
0088 
0089 void NotificationInfo::setSenderUserName(const QString &newSenderUserName)
0090 {
0091     mSenderUserName = newSenderUserName;
0092 }
0093 
0094 const QString &NotificationInfo::roomName() const
0095 {
0096     return mRoomName;
0097 }
0098 
0099 void NotificationInfo::setRoomName(const QString &newRoomName)
0100 {
0101     mRoomName = newRoomName;
0102 }
0103 
0104 const QString &NotificationInfo::roomId() const
0105 {
0106     return mRoomId;
0107 }
0108 
0109 void NotificationInfo::setRoomId(const QString &newRoomId)
0110 {
0111     mRoomId = newRoomId;
0112 }
0113 
0114 const QString &NotificationInfo::channelType() const
0115 {
0116     return mChannelType;
0117 }
0118 
0119 void NotificationInfo::setChannelType(const QString &newChannelType)
0120 {
0121     mChannelType = newChannelType;
0122 }
0123 
0124 const QString &NotificationInfo::tmId() const
0125 {
0126     return mTmId;
0127 }
0128 
0129 void NotificationInfo::setTmId(const QString &newTmId)
0130 {
0131     mTmId = newTmId;
0132 }
0133 
0134 const QPixmap &NotificationInfo::pixmap() const
0135 {
0136     return mPixmap;
0137 }
0138 
0139 void NotificationInfo::setPixmap(const QPixmap &newPixmap)
0140 {
0141     mPixmap = newPixmap;
0142 }
0143 
0144 void NotificationInfo::parseNotification(const QJsonArray &contents)
0145 {
0146     // qDebug() << " NotificationInfo::parseNotification(const QJsonArray &contents)" << contents;
0147     const QJsonObject obj = contents.at(0).toObject();
0148     setTitle(obj[QLatin1String("title")].toString());
0149     const QJsonObject payloadObj = obj.value(QLatin1String("payload")).toObject();
0150     if (!payloadObj.isEmpty()) {
0151         setMessageId(payloadObj[QLatin1String("_id")].toString());
0152         setRoomId(payloadObj[QLatin1String("rid")].toString());
0153         setRoomName(payloadObj[QLatin1String("name")].toString());
0154         setChannelType(payloadObj[QLatin1String("type")].toString());
0155         setTmId(payloadObj[QLatin1String("tmid")].toString());
0156         const QJsonObject senderObj = payloadObj.value(QLatin1String("sender")).toObject();
0157         if (!senderObj.isEmpty()) {
0158             setSenderId(senderObj.value(QLatin1String("_id")).toString());
0159             setSenderName(senderObj.value(QLatin1String("name")).toString());
0160             setSenderUserName(senderObj.value(QLatin1String("username")).toString());
0161         } else {
0162             qCDebug(RUQOLA_LOG) << "Problem with notification json: missing sender";
0163         }
0164         const QJsonObject messageObj = payloadObj.value(QLatin1String("message")).toObject();
0165         if (messageObj.isEmpty()) {
0166             qCDebug(RUQOLA_LOG) << "Problem with notification json: missing message";
0167             setMessage(obj[QLatin1String("text")].toString());
0168         } else {
0169             if (messageObj[QLatin1String("t")].toString() == QLatin1String("videoconf")) {
0170                 mNotificationType = ConferenceCall;
0171             } else {
0172                 setMessage(messageObj[QLatin1String("msg")].toString());
0173                 if (message().isEmpty()) {
0174                     // Fallback to text
0175                     setMessage(obj[QLatin1String("text")].toString());
0176                 }
0177             }
0178         }
0179     } else {
0180         qCDebug(RUQOLA_LOG) << "Problem with notification json: missing payload";
0181     }
0182     qCDebug(RUQOLA_LOG) << "info " << *this;
0183 }
0184 
0185 bool NotificationInfo::isValid() const
0186 {
0187     bool valid = !mSenderId.isEmpty() && !mChannelType.isEmpty();
0188     if (mNotificationType == ConferenceCall) {
0189         return valid;
0190     }
0191     return valid && !mMessage.isEmpty();
0192 }
0193 
0194 const QString &NotificationInfo::dateTime() const
0195 {
0196     return mDateTime;
0197 }
0198 
0199 void NotificationInfo::setDateTime(const QString &newDateTime)
0200 {
0201     mDateTime = newDateTime;
0202 }
0203 
0204 const QString &NotificationInfo::messageId() const
0205 {
0206     return mMessageId;
0207 }
0208 
0209 void NotificationInfo::setMessageId(const QString &newMessageId)
0210 {
0211     mMessageId = newMessageId;
0212 }
0213 
0214 NotificationInfo::NotificationType NotificationInfo::notificationType() const
0215 {
0216     return mNotificationType;
0217 }
0218 
0219 void NotificationInfo::setNotificationType(const NotificationType &newNotificationType)
0220 {
0221     mNotificationType = newNotificationType;
0222 }
0223 
0224 bool NotificationInfo::operator==(const NotificationInfo &other) const
0225 {
0226     return other.mMessageId == mMessageId && other.mAccountName == mAccountName && other.mMessage == mMessage && other.mTitle == mTitle
0227         && other.mSenderId == mSenderId && other.mSenderName == mSenderName && other.mSenderUserName == mSenderUserName && other.mRoomName == mRoomName
0228         && other.mRoomId == mRoomId && other.mChannelType == mChannelType && other.mTmId == mTmId && other.mDateTime == mDateTime
0229         && other.mPixmap.cacheKey() == mPixmap.cacheKey() && other.mNotificationType == mNotificationType;
0230 }
0231 
0232 #include "moc_notificationinfo.cpp"