1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
25 #include <QDataStream>
28 #include "signalproxy.h"
32 BufferInfo bufferInfo, Type type, QString contents, QString sender, QString senderPrefixes, QString realName, QString avatarUrl, Flags flags)
33 : _timestamp(QDateTime::currentDateTime().toUTC())
34 , _bufferInfo(std::move(bufferInfo))
35 , _contents(std::move(contents))
36 , _sender(std::move(sender))
37 , _senderPrefixes(std::move(senderPrefixes))
38 , _realName(std::move(realName))
39 , _avatarUrl(std::move(avatarUrl))
44 Message::Message(QDateTime ts,
45 BufferInfo bufferInfo,
49 QString senderPrefixes,
53 : _timestamp(std::move(ts))
54 , _bufferInfo(std::move(bufferInfo))
55 , _contents(std::move(contents))
56 , _sender(std::move(sender))
57 , _senderPrefixes(std::move(senderPrefixes))
58 , _realName(std::move(realName))
59 , _avatarUrl(std::move(avatarUrl))
64 QDataStream& operator<<(QDataStream& out, const Message& msg)
66 Q_ASSERT(SignalProxy::current());
67 Q_ASSERT(SignalProxy::current()->targetPeer());
69 // We do not serialize the sender prefixes until we have a new protocol or client-features implemented
72 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::LongTime)) {
73 // toMSecs returns a qint64, signed rather than unsigned
74 out << (qint64)msg.timestamp().toMSecsSinceEpoch();
77 out << (quint32)msg.timestamp().toTime_t();
80 out << (quint32)msg.type() << (quint8)msg.flags() << msg.bufferInfo() << msg.sender().toUtf8();
82 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::SenderPrefixes))
83 out << msg.senderPrefixes().toUtf8();
85 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::RichMessages)) {
86 out << msg.realName().toUtf8();
87 out << msg.avatarUrl().toUtf8();
90 out << msg.contents().toUtf8();
94 QDataStream& operator>>(QDataStream& in, Message& msg)
96 Q_ASSERT(SignalProxy::current());
97 Q_ASSERT(SignalProxy::current()->sourcePeer());
101 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::LongTime)) {
102 // timestamp is a qint64, signed rather than unsigned
105 msg._timestamp = QDateTime::fromMSecsSinceEpoch(timeStamp);
110 msg._timestamp = QDateTime::fromTime_t(timeStamp);
115 msg._type = Message::Type(type);
119 msg._flags = Message::Flags(flags);
121 in >> msg._bufferInfo;
125 msg._sender = QString::fromUtf8(sender);
127 QByteArray senderPrefixes;
128 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::SenderPrefixes))
129 in >> senderPrefixes;
130 msg._senderPrefixes = QString::fromUtf8(senderPrefixes);
133 QByteArray avatarUrl;
134 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::RichMessages)) {
138 msg._realName = QString::fromUtf8(realName);
139 msg._avatarUrl = QString::fromUtf8(avatarUrl);
143 msg._contents = QString::fromUtf8(contents);
148 QDebug operator<<(QDebug dbg, const Message& msg)
150 dbg.nospace() << qPrintable(QString("Message(MsgId:")) << msg.msgId() << qPrintable(QString(",")) << msg.timestamp()
151 << qPrintable(QString(", Type:")) << msg.type() << qPrintable(QString(", RealName:")) << msg.realName()
152 << qPrintable(QString(", AvatarURL:")) << msg.avatarUrl() << qPrintable(QString(", Flags:")) << msg.flags()
153 << qPrintable(QString(")")) << msg.senderPrefixes() << msg.sender() << ":" << msg.contents();