1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 "signalproxy.h"
27 #include <QDataStream>
29 Message::Message(const BufferInfo &bufferInfo, Type type, const QString &contents, const QString &sender,
30 const QString &senderPrefixes, const QString &realName, const QString &avatarUrl, Flags flags)
31 : _timestamp(QDateTime::currentDateTime().toUTC()),
32 _bufferInfo(bufferInfo),
35 _senderPrefixes(senderPrefixes),
37 _avatarUrl(avatarUrl),
44 Message::Message(const QDateTime &ts, const BufferInfo &bufferInfo, Type type, const QString &contents,
45 const QString &sender, const QString &senderPrefixes, const QString &realName,
46 const QString &avatarUrl, Flags flags)
48 _bufferInfo(bufferInfo),
51 _senderPrefixes(senderPrefixes),
53 _avatarUrl(avatarUrl),
60 QDataStream &operator<<(QDataStream &out, const Message &msg)
62 Q_ASSERT(SignalProxy::current());
63 Q_ASSERT(SignalProxy::current()->targetPeer());
65 // We do not serialize the sender prefixes until we have a new protocol or client-features implemented
68 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::LongMessageTime)) {
69 out << (quint64) msg.timestamp().toMSecsSinceEpoch();
71 out << (quint32) msg.timestamp().toTime_t();
74 out << (quint32) msg.type()
75 << (quint8) msg.flags()
77 << msg.sender().toUtf8();
79 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::SenderPrefixes))
80 out << msg.senderPrefixes().toUtf8();
82 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::RichMessages)) {
83 out << msg.realName().toUtf8();
84 out << msg.avatarUrl().toUtf8();
87 out << msg.contents().toUtf8();
92 QDataStream &operator>>(QDataStream &in, Message &msg)
94 Q_ASSERT(SignalProxy::current());
95 Q_ASSERT(SignalProxy::current()->sourcePeer());
99 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::LongMessageTime)) {
102 msg._timestamp = QDateTime::fromMSecsSinceEpoch(timeStamp);
106 msg._timestamp = QDateTime::fromTime_t(timeStamp);
111 msg._type = Message::Type(type);
115 msg._flags = Message::Flags(flags);
117 in >> msg._bufferInfo;
121 msg._sender = QString::fromUtf8(sender);
123 QByteArray senderPrefixes;
124 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::SenderPrefixes))
125 in >> senderPrefixes;
126 msg._senderPrefixes = QString::fromUtf8(senderPrefixes);
129 QByteArray avatarUrl;
130 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::RichMessages)) {
134 msg._realName = QString::fromUtf8(realName);
135 msg._avatarUrl = QString::fromUtf8(avatarUrl);
139 msg._contents = QString::fromUtf8(contents);
145 QDebug operator<<(QDebug dbg, const Message &msg)
147 dbg.nospace() << qPrintable(QString("Message(MsgId:")) << msg.msgId()
148 << qPrintable(QString(",")) << msg.timestamp()
149 << qPrintable(QString(", Type:")) << msg.type()
150 << qPrintable(QString(", RealName:")) << msg.realName()
151 << qPrintable(QString(", AvatarURL:")) << msg.avatarUrl()
152 << qPrintable(QString(", Flags:")) << msg.flags() << qPrintable(QString(")"))
153 << msg.senderPrefixes() << msg.sender() << ":" << msg.contents();