forked from blue/squawk
full transition to lmdbal, DOESNT WORK, DONT TAKE!
This commit is contained in:
parent
23ec80ccba
commit
9d688e8596
18 changed files with 497 additions and 1752 deletions
|
@ -61,50 +61,42 @@ Shared::Message::Message():
|
|||
attachPath()
|
||||
{}
|
||||
|
||||
QString Shared::Message::getBody() const
|
||||
{
|
||||
QString Shared::Message::getBody() const {
|
||||
return body;
|
||||
}
|
||||
|
||||
QString Shared::Message::getFrom() const
|
||||
{
|
||||
QString Shared::Message::getFrom() const {
|
||||
QString from = jFrom;
|
||||
if (rFrom.size() > 0) {
|
||||
if (rFrom.size() > 0)
|
||||
from += "/" + rFrom;
|
||||
}
|
||||
|
||||
return from;
|
||||
}
|
||||
|
||||
QString Shared::Message::getTo() const
|
||||
{
|
||||
QString Shared::Message::getTo() const {
|
||||
QString to = jTo;
|
||||
if (rTo.size() > 0) {
|
||||
if (rTo.size() > 0)
|
||||
to += "/" + rTo;
|
||||
}
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
QString Shared::Message::getId() const
|
||||
{
|
||||
if (id.size() > 0) {
|
||||
QString Shared::Message::getId() const {
|
||||
if (id.size() > 0)
|
||||
return id;
|
||||
} else {
|
||||
else
|
||||
return stanzaId;
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime Shared::Message::getTime() const
|
||||
{
|
||||
QDateTime Shared::Message::getTime() const {
|
||||
return time;
|
||||
}
|
||||
|
||||
void Shared::Message::setBody(const QString& p_body)
|
||||
{
|
||||
void Shared::Message::setBody(const QString& p_body) {
|
||||
body = p_body;
|
||||
}
|
||||
|
||||
void Shared::Message::setFrom(const QString& from)
|
||||
{
|
||||
void Shared::Message::setFrom(const QString& from) {
|
||||
QStringList list = from.split("/");
|
||||
if (list.size() == 1) {
|
||||
jFrom = from.toLower();
|
||||
|
@ -114,8 +106,7 @@ void Shared::Message::setFrom(const QString& from)
|
|||
}
|
||||
}
|
||||
|
||||
void Shared::Message::setTo(const QString& to)
|
||||
{
|
||||
void Shared::Message::setTo(const QString& to) {
|
||||
QStringList list = to.split("/");
|
||||
if (list.size() == 1) {
|
||||
jTo = to.toLower();
|
||||
|
@ -125,153 +116,122 @@ void Shared::Message::setTo(const QString& to)
|
|||
}
|
||||
}
|
||||
|
||||
void Shared::Message::setId(const QString& p_id)
|
||||
{
|
||||
void Shared::Message::setId(const QString& p_id) {
|
||||
id = p_id;
|
||||
}
|
||||
|
||||
void Shared::Message::setTime(const QDateTime& p_time)
|
||||
{
|
||||
void Shared::Message::setTime(const QDateTime& p_time) {
|
||||
time = p_time;
|
||||
}
|
||||
|
||||
QString Shared::Message::getFromJid() const
|
||||
{
|
||||
QString Shared::Message::getFromJid() const {
|
||||
return jFrom;
|
||||
}
|
||||
|
||||
QString Shared::Message::getFromResource() const
|
||||
{
|
||||
QString Shared::Message::getFromResource() const {
|
||||
return rFrom;
|
||||
}
|
||||
|
||||
QString Shared::Message::getToJid() const
|
||||
{
|
||||
QString Shared::Message::getToJid() const {
|
||||
return jTo;
|
||||
}
|
||||
|
||||
QString Shared::Message::getToResource() const
|
||||
{
|
||||
QString Shared::Message::getToResource() const {
|
||||
return rTo;
|
||||
}
|
||||
|
||||
QString Shared::Message::getErrorText() const
|
||||
{
|
||||
QString Shared::Message::getErrorText() const {
|
||||
return errorText;
|
||||
}
|
||||
|
||||
QString Shared::Message::getPenPalJid() const
|
||||
{
|
||||
if (outgoing) {
|
||||
QString Shared::Message::getPenPalJid() const {
|
||||
if (outgoing)
|
||||
return jTo;
|
||||
} else {
|
||||
else
|
||||
return jFrom;
|
||||
}
|
||||
}
|
||||
|
||||
QString Shared::Message::getPenPalResource() const
|
||||
{
|
||||
if (outgoing) {
|
||||
QString Shared::Message::getPenPalResource() const {
|
||||
if (outgoing)
|
||||
return rTo;
|
||||
} else {
|
||||
else
|
||||
return rFrom;
|
||||
}
|
||||
}
|
||||
|
||||
Shared::Message::State Shared::Message::getState() const
|
||||
{
|
||||
Shared::Message::State Shared::Message::getState() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
bool Shared::Message::getEdited() const
|
||||
{
|
||||
bool Shared::Message::getEdited() const {
|
||||
return edited;
|
||||
}
|
||||
|
||||
void Shared::Message::setFromJid(const QString& from)
|
||||
{
|
||||
void Shared::Message::setFromJid(const QString& from) {
|
||||
jFrom = from.toLower();
|
||||
}
|
||||
|
||||
void Shared::Message::setFromResource(const QString& from)
|
||||
{
|
||||
void Shared::Message::setFromResource(const QString& from) {
|
||||
rFrom = from;
|
||||
}
|
||||
|
||||
void Shared::Message::setToJid(const QString& to)
|
||||
{
|
||||
void Shared::Message::setToJid(const QString& to) {
|
||||
jTo = to.toLower();
|
||||
}
|
||||
|
||||
void Shared::Message::setToResource(const QString& to)
|
||||
{
|
||||
void Shared::Message::setToResource(const QString& to) {
|
||||
rTo = to;
|
||||
}
|
||||
|
||||
void Shared::Message::setErrorText(const QString& err)
|
||||
{
|
||||
if (state == State::error) {
|
||||
void Shared::Message::setErrorText(const QString& err) {
|
||||
if (state == State::error)
|
||||
errorText = err;
|
||||
}
|
||||
}
|
||||
|
||||
bool Shared::Message::getOutgoing() const
|
||||
{
|
||||
bool Shared::Message::getOutgoing() const {
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
void Shared::Message::setOutgoing(bool og)
|
||||
{
|
||||
void Shared::Message::setOutgoing(bool og) {
|
||||
outgoing = og;
|
||||
}
|
||||
|
||||
bool Shared::Message::getForwarded() const
|
||||
{
|
||||
bool Shared::Message::getForwarded() const {
|
||||
return forwarded;
|
||||
}
|
||||
|
||||
void Shared::Message::generateRandomId()
|
||||
{
|
||||
void Shared::Message::generateRandomId() {
|
||||
id = generateUUID();
|
||||
}
|
||||
|
||||
QString Shared::Message::getThread() const
|
||||
{
|
||||
QString Shared::Message::getThread() const {
|
||||
return thread;
|
||||
}
|
||||
|
||||
void Shared::Message::setForwarded(bool fwd)
|
||||
{
|
||||
void Shared::Message::setForwarded(bool fwd) {
|
||||
forwarded = fwd;
|
||||
}
|
||||
|
||||
void Shared::Message::setThread(const QString& p_body)
|
||||
{
|
||||
void Shared::Message::setThread(const QString& p_body) {
|
||||
thread = p_body;
|
||||
}
|
||||
|
||||
QDateTime Shared::Message::getLastModified() const
|
||||
{
|
||||
QDateTime Shared::Message::getLastModified() const {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
QString Shared::Message::getOriginalBody() const
|
||||
{
|
||||
QString Shared::Message::getOriginalBody() const {
|
||||
return originalMessage;
|
||||
}
|
||||
|
||||
Shared::Message::Type Shared::Message::getType() const
|
||||
{
|
||||
Shared::Message::Type Shared::Message::getType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
void Shared::Message::setType(Shared::Message::Type t)
|
||||
{
|
||||
void Shared::Message::setType(Shared::Message::Type t) {
|
||||
type = t;
|
||||
}
|
||||
|
||||
void Shared::Message::setState(Shared::Message::State p_state)
|
||||
{
|
||||
void Shared::Message::setState(Shared::Message::State p_state) {
|
||||
state = p_state;
|
||||
|
||||
if (state != State::error) {
|
||||
|
@ -279,96 +239,92 @@ void Shared::Message::setState(Shared::Message::State p_state)
|
|||
}
|
||||
}
|
||||
|
||||
bool Shared::Message::serverStored() const
|
||||
{
|
||||
bool Shared::Message::serverStored() const {
|
||||
return state == State::delivered || state == State::sent;
|
||||
}
|
||||
|
||||
void Shared::Message::setEdited(bool p_edited)
|
||||
{
|
||||
void Shared::Message::setEdited(bool p_edited) {
|
||||
edited = p_edited;
|
||||
}
|
||||
|
||||
void Shared::Message::serialize(QDataStream& data) const
|
||||
{
|
||||
data << jFrom;
|
||||
data << rFrom;
|
||||
data << jTo;
|
||||
data << rTo;
|
||||
data << id;
|
||||
data << body;
|
||||
data << time;
|
||||
data << thread;
|
||||
data << (quint8)type;
|
||||
data << outgoing;
|
||||
data << forwarded;
|
||||
data << oob;
|
||||
data << (quint8)state;
|
||||
data << edited;
|
||||
if (state == State::error) {
|
||||
data << errorText;
|
||||
QDataStream& operator<<(QDataStream& out, const Shared::Message& info) {
|
||||
out << info.jFrom;
|
||||
out << info.rFrom;
|
||||
out << info.jTo;
|
||||
out << info.rTo;
|
||||
out << info.id;
|
||||
out << info.body;
|
||||
out << info.time;
|
||||
out << info.thread;
|
||||
out << (quint8)info.type;
|
||||
out << info.outgoing;
|
||||
out << info.forwarded;
|
||||
out << info.oob;
|
||||
out << (quint8)info.state;
|
||||
out << info.edited;
|
||||
if (info.state == Shared::Message::State::error)
|
||||
out << info.errorText;
|
||||
|
||||
if (info.edited) {
|
||||
out << info.originalMessage;
|
||||
out << info.lastModified;
|
||||
}
|
||||
if (edited) {
|
||||
data << originalMessage;
|
||||
data << lastModified;
|
||||
}
|
||||
data << stanzaId;
|
||||
data << attachPath;
|
||||
out << info.stanzaId;
|
||||
out << info.attachPath;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void Shared::Message::deserialize(QDataStream& data)
|
||||
{
|
||||
data >> jFrom;
|
||||
data >> rFrom;
|
||||
data >> jTo;
|
||||
data >> rTo;
|
||||
data >> id;
|
||||
data >> body;
|
||||
data >> time;
|
||||
data >> thread;
|
||||
QDataStream & operator>>(QDataStream& in, Shared::Message& info) {
|
||||
in >> info.jFrom;
|
||||
in >> info.rFrom;
|
||||
in >> info.jTo;
|
||||
in >> info.rTo;
|
||||
in >> info.id;
|
||||
in >> info.body;
|
||||
in >> info.time;
|
||||
in >> info.thread;
|
||||
quint8 t;
|
||||
data >> t;
|
||||
type = static_cast<Type>(t);
|
||||
data >> outgoing;
|
||||
data >> forwarded;
|
||||
data >> oob;
|
||||
in >> t;
|
||||
info.type = static_cast<Shared::Message::Type>(t);
|
||||
in >> info.outgoing;
|
||||
in >> info.forwarded;
|
||||
in >> info.oob;
|
||||
quint8 s;
|
||||
data >> s;
|
||||
state = static_cast<State>(s);
|
||||
data >> edited;
|
||||
if (state == State::error) {
|
||||
data >> errorText;
|
||||
in >> s;
|
||||
info.state = static_cast<Shared::Message::State>(s);
|
||||
in >> info.edited;
|
||||
if (info.state == Shared::Message::State::error)
|
||||
in >> info.errorText;
|
||||
|
||||
if (info.edited) {
|
||||
in >> info.originalMessage;
|
||||
in >> info.lastModified;
|
||||
}
|
||||
if (edited) {
|
||||
data >> originalMessage;
|
||||
data >> lastModified;
|
||||
}
|
||||
data >> stanzaId;
|
||||
data >> attachPath;
|
||||
in >> info.stanzaId;
|
||||
in >> info.attachPath;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
bool Shared::Message::change(const QMap<QString, QVariant>& data)
|
||||
{
|
||||
QMap<QString, QVariant>::const_iterator itr = data.find("state");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setState(static_cast<State>(itr.value().toUInt()));
|
||||
}
|
||||
|
||||
itr = data.find("outOfBandUrl");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setOutOfBandUrl(itr.value().toString());
|
||||
}
|
||||
|
||||
itr = data.find("attachPath");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setAttachPath(itr.value().toString());
|
||||
}
|
||||
|
||||
if (state == State::error) {
|
||||
itr = data.find("errorText");
|
||||
if (itr != data.end()) {
|
||||
if (itr != data.end())
|
||||
setErrorText(itr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
bool idChanged = false;
|
||||
|
@ -386,9 +342,8 @@ bool Shared::Message::change(const QMap<QString, QVariant>& data)
|
|||
QString newId = itr.value().toString();
|
||||
if (stanzaId != newId) {
|
||||
setStanzaId(newId);
|
||||
if (id.size() == 0) {
|
||||
if (id.size() == 0)
|
||||
idChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,15 +353,15 @@ bool Shared::Message::change(const QMap<QString, QVariant>& data)
|
|||
if (body != b) {
|
||||
QMap<QString, QVariant>::const_iterator dItr = data.find("stamp");
|
||||
QDateTime correctionDate;
|
||||
if (dItr != data.end()) {
|
||||
if (dItr != data.end())
|
||||
correctionDate = dItr.value().toDateTime();
|
||||
} else {
|
||||
else
|
||||
correctionDate = QDateTime::currentDateTimeUtc(); //in case there is no information about time of this correction it's applied
|
||||
}
|
||||
|
||||
if (!edited || lastModified < correctionDate) {
|
||||
if (!edited) {
|
||||
if (!edited)
|
||||
originalMessage = body;
|
||||
}
|
||||
|
||||
lastModified = correctionDate;
|
||||
setBody(b);
|
||||
setEdited(true);
|
||||
|
@ -416,57 +371,47 @@ bool Shared::Message::change(const QMap<QString, QVariant>& data)
|
|||
QMap<QString, QVariant>::const_iterator dItr = data.find("stamp");
|
||||
if (dItr != data.end()) {
|
||||
QDateTime ntime = dItr.value().toDateTime();
|
||||
if (time != ntime) {
|
||||
if (time != ntime)
|
||||
setTime(ntime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return idChanged;
|
||||
}
|
||||
|
||||
void Shared::Message::setCurrentTime()
|
||||
{
|
||||
void Shared::Message::setCurrentTime() {
|
||||
time = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
|
||||
QString Shared::Message::getOutOfBandUrl() const
|
||||
{
|
||||
QString Shared::Message::getOutOfBandUrl() const {
|
||||
return oob;
|
||||
}
|
||||
|
||||
bool Shared::Message::hasOutOfBandUrl() const
|
||||
{
|
||||
bool Shared::Message::hasOutOfBandUrl() const {
|
||||
return oob.size() > 0;
|
||||
}
|
||||
|
||||
void Shared::Message::setOutOfBandUrl(const QString& url)
|
||||
{
|
||||
void Shared::Message::setOutOfBandUrl(const QString& url) {
|
||||
oob = url;
|
||||
}
|
||||
|
||||
bool Shared::Message::storable() const
|
||||
{
|
||||
bool Shared::Message::storable() const {
|
||||
return id.size() > 0 && (body.size() > 0 || oob.size() > 0 || attachPath.size() > 0);
|
||||
}
|
||||
|
||||
void Shared::Message::setStanzaId(const QString& sid)
|
||||
{
|
||||
void Shared::Message::setStanzaId(const QString& sid) {
|
||||
stanzaId = sid;
|
||||
}
|
||||
|
||||
QString Shared::Message::getStanzaId() const
|
||||
{
|
||||
QString Shared::Message::getStanzaId() const {
|
||||
return stanzaId;
|
||||
}
|
||||
|
||||
QString Shared::Message::getAttachPath() const
|
||||
{
|
||||
QString Shared::Message::getAttachPath() const {
|
||||
return attachPath;
|
||||
}
|
||||
|
||||
void Shared::Message::setAttachPath(const QString& path)
|
||||
{
|
||||
void Shared::Message::setAttachPath(const QString& path) {
|
||||
attachPath = path;
|
||||
}
|
||||
|
||||
|
@ -474,18 +419,15 @@ Shared::Message::Change::Change(const QMap<QString, QVariant>& _data):
|
|||
data(_data),
|
||||
idModified(false) {}
|
||||
|
||||
void Shared::Message::Change::operator()(Shared::Message& msg)
|
||||
{
|
||||
void Shared::Message::Change::operator()(Shared::Message& msg) {
|
||||
idModified = msg.change(data);
|
||||
}
|
||||
|
||||
void Shared::Message::Change::operator()(Shared::Message* msg)
|
||||
{
|
||||
void Shared::Message::Change::operator()(Shared::Message* msg) {
|
||||
idModified = msg->change(data);
|
||||
}
|
||||
|
||||
bool Shared::Message::Change::hasIdBeenModified() const
|
||||
{
|
||||
bool Shared::Message::Change::hasIdBeenModified() const {
|
||||
return idModified;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,12 +25,20 @@
|
|||
#include <QMap>
|
||||
#include <QDataStream>
|
||||
|
||||
namespace Shared {
|
||||
class Message;
|
||||
}
|
||||
|
||||
QDataStream& operator << (QDataStream& out, const Shared::Message& info);
|
||||
QDataStream& operator >> (QDataStream& in, Shared::Message& info);
|
||||
namespace Shared {
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
*/
|
||||
class Message {
|
||||
friend QDataStream& ::operator << (QDataStream& out, const Shared::Message& info);
|
||||
friend QDataStream& ::operator >> (QDataStream& in, Shared::Message& info);
|
||||
public:
|
||||
enum Type {
|
||||
error,
|
||||
|
@ -116,9 +124,6 @@ public:
|
|||
QString getStanzaId() const;
|
||||
QString getAttachPath() const;
|
||||
|
||||
void serialize(QDataStream& data) const;
|
||||
void deserialize(QDataStream& data);
|
||||
|
||||
private:
|
||||
QString jFrom;
|
||||
QString rFrom;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue