1 /***************************************************************************
2 * Copyright (C) 2005-2016 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, const QString &senderPrefixes, Flags flags)
30 : _timestamp(QDateTime::currentDateTime().toUTC()),
31 _bufferInfo(bufferInfo),
34 _senderPrefixes(senderPrefixes),
41 Message::Message(const QDateTime &ts, const BufferInfo &bufferInfo, Type type, const QString &contents, const QString &sender, const QString &senderPrefixes, Flags flags)
43 _bufferInfo(bufferInfo),
46 _senderPrefixes(senderPrefixes),
53 QDataStream &operator<<(QDataStream &out, const Message &msg)
55 // We do not serialize the sender prefixes until we have a new protocol or client-features implemented
57 << (quint32) msg.timestamp().toTime_t()
58 << (quint32) msg.type()
59 << (quint8) msg.flags()
61 << msg.sender().toUtf8();
63 if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::SenderPrefixes))
64 out << msg.senderPrefixes().toUtf8();
66 out << msg.contents().toUtf8();
71 QDataStream &operator>>(QDataStream &in, Message &msg)
77 msg._timestamp = QDateTime::fromTime_t(timeStamp);
81 msg._type = Message::Type(type);
85 msg._flags = Message::Flags(flags);
87 in >> msg._bufferInfo;
91 msg._sender = QString::fromUtf8(sender);
93 QByteArray senderPrefixes;
94 if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::SenderPrefixes))
96 msg._senderPrefixes = QString::fromUtf8(senderPrefixes);
100 msg._contents = QString::fromUtf8(contents);
106 QDebug operator<<(QDebug dbg, const Message &msg)
108 dbg.nospace() << qPrintable(QString("Message(MsgId:")) << msg.msgId()
109 << qPrintable(QString(",")) << msg.timestamp()
110 << qPrintable(QString(", Type:")) << msg.type()
111 << qPrintable(QString(", Flags:")) << msg.flags() << qPrintable(QString(")"))
112 << msg.sender() << ":" << msg.contents();