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 ***************************************************************************/
23 #include <QDataStream>
27 #include "signalproxy.h"
30 Message::Message(BufferInfo bufferInfo,
34 QString senderPrefixes,
38 : _timestamp(QDateTime::currentDateTime().toUTC())
39 , _bufferInfo(std::move(bufferInfo))
40 , _contents(std::move(contents))
41 , _sender(std::move(sender))
42 , _senderPrefixes(std::move(senderPrefixes))
43 , _realName(std::move(realName))
44 , _avatarUrl(std::move(avatarUrl))
49 Message::Message(QDateTime ts,
50 BufferInfo bufferInfo,
54 QString senderPrefixes,
58 : _timestamp(std::move(ts))
59 , _bufferInfo(std::move(bufferInfo))
60 , _contents(std::move(contents))
61 , _sender(std::move(sender))
62 , _senderPrefixes(std::move(senderPrefixes))
63 , _realName(std::move(realName))
64 , _avatarUrl(std::move(avatarUrl))
69 QDataStream& operator<<(QDataStream& out, const Message& msg)
71 Q_ASSERT(SignalProxy::current());
72 Q_ASSERT(SignalProxy::current()->targetPeer());
74 // We do not serialize the sender prefixes until we have a new protocol or client-features implemented
77 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::LongTime)) {
78 // toMSecs returns a qint64, signed rather than unsigned
79 out << (qint64) msg.timestamp().toMSecsSinceEpoch();
82 out << (quint32) msg.timestamp().toTime_t();
85 out << (quint32) msg.type()
86 << (quint8) msg.flags()
88 << msg.sender().toUtf8();
90 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::SenderPrefixes))
91 out << msg.senderPrefixes().toUtf8();
93 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::RichMessages)) {
94 out << msg.realName().toUtf8();
95 out << msg.avatarUrl().toUtf8();
98 out << msg.contents().toUtf8();
102 QDataStream& operator>>(QDataStream& in, Message& msg)
104 Q_ASSERT(SignalProxy::current());
105 Q_ASSERT(SignalProxy::current()->sourcePeer());
109 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::LongTime)) {
110 // timestamp is a qint64, signed rather than unsigned
113 msg._timestamp = QDateTime::fromMSecsSinceEpoch(timeStamp);
118 msg._timestamp = QDateTime::fromTime_t(timeStamp);
123 msg._type = Message::Type(type);
127 msg._flags = Message::Flags(flags);
129 in >> msg._bufferInfo;
133 msg._sender = QString::fromUtf8(sender);
135 QByteArray senderPrefixes;
136 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::SenderPrefixes))
137 in >> senderPrefixes;
138 msg._senderPrefixes = QString::fromUtf8(senderPrefixes);
141 QByteArray avatarUrl;
142 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::RichMessages)) {
146 msg._realName = QString::fromUtf8(realName);
147 msg._avatarUrl = QString::fromUtf8(avatarUrl);
151 msg._contents = QString::fromUtf8(contents);
156 QDebug operator<<(QDebug dbg, const Message& msg)
158 dbg.nospace() << qPrintable(QString("Message(MsgId:")) << msg.msgId()
159 << qPrintable(QString(",")) << msg.timestamp()
160 << qPrintable(QString(", Type:")) << msg.type()
161 << qPrintable(QString(", RealName:")) << msg.realName()
162 << qPrintable(QString(", AvatarURL:")) << msg.avatarUrl()
163 << qPrintable(QString(", Flags:")) << msg.flags()
164 << qPrintable(QString(")"))
165 << msg.senderPrefixes() << msg.sender() << ":"