Skip to content

Commit

Permalink
little sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed May 27, 2024
1 parent 0184b6c commit e8efe0b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/xmpp/jid/jid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ void Jid::setNode(const QString &s)

void Jid::setResource(const QString &s)
{
if (r == s) {
return;
}
if (!valid)
return;
QString norm;
Expand Down
6 changes: 6 additions & 0 deletions src/xmpp/xmpp-core/xmpp_stanza.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class Stanza {
int code() const;
bool fromCode(int code);

inline bool isCancel() const { return type == ErrorType::Cancel; }
inline bool isContinue() const { return type == ErrorType::Continue; }
inline bool isModify() const { return type == ErrorType::Modify; }
inline bool isAuth() const { return type == ErrorType::Auth; }
inline bool isWait() const { return type == ErrorType::Wait; }

QPair<QString, QString> description() const;
QString toString() const;

Expand Down
24 changes: 9 additions & 15 deletions src/xmpp/xmpp-im/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,13 +2067,13 @@ class StatusPrivate : public QSharedData {
public:
StatusPrivate() = default;

int priority = 0;
QString show, status, key;
QDateTime timeStamp;
bool isAvailable = false;
bool isInvisible = false;
QByteArray photoHash;
bool hasPhotoHash = false;
int priority = 0;
QString show, status, key;
QDateTime timeStamp;
bool isAvailable = false;
bool isInvisible = false;

std::optional<QByteArray> photoHash;

QString xsigned;
// gabber song extension
Expand Down Expand Up @@ -2230,15 +2230,9 @@ void Status::setMUCHistory(int maxchars, int maxstanzas, int seconds, const QDat
d->mucHistorySince = since;
}

const QByteArray &Status::photoHash() const { return d->photoHash; }

void Status::setPhotoHash(const QByteArray &h)
{
d->photoHash = h;
d->hasPhotoHash = true;
}
const std::optional<QByteArray> &Status::photoHash() const { return d->photoHash; }

bool Status::hasPhotoHash() const { return d->hasPhotoHash; }
void Status::setPhotoHash(const QByteArray &h) { d->photoHash = h; }

void Status::addBoBData(const BoBData &bob) { d->bobDataList.append(bob); }

Expand Down
7 changes: 4 additions & 3 deletions src/xmpp/xmpp-im/xmpp_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <QString>
#include <QStringList>

#include <optional>

namespace XMPP {
class DiscoItem;
class StatusPrivate;
Expand Down Expand Up @@ -132,9 +134,8 @@ class Status {
void setSongTitle(const QString &);

// XEP-0153: vCard-Based Avatars
const QByteArray &photoHash() const;
void setPhotoHash(const QByteArray &);
bool hasPhotoHash() const;
const std::optional<QByteArray> &photoHash() const;
void setPhotoHash(const QByteArray &);

// XEP-0231 bits of binary
void addBoBData(const BoBData &);
Expand Down
6 changes: 3 additions & 3 deletions src/xmpp/xmpp-im/xmpp_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ void JT_Presence::pres(const Status &s)
tag.appendChild(m);
}

if (s.hasPhotoHash()) {
if (s.photoHash().has_value()) {
QDomElement m = doc()->createElementNS("vcard-temp:x:update", "x");
m.appendChild(textTag(doc(), "photo", QString::fromLatin1(s.photoHash().toHex())));
m.appendChild(textTag(doc(), "photo", QString::fromLatin1(s.photoHash()->toHex())));
tag.appendChild(m);
}

Expand Down Expand Up @@ -751,7 +751,7 @@ bool JT_PushPresence::take(const QDomElement &e)
if (!t.isNull())
p.setPhotoHash(
QByteArray::fromHex(tagContent(t).toLatin1())); // if hash is empty this may mean photo removal
// else vcard.hasPhotoHash() returns false and that's mean user is not yet ready to advertise his image
// else vcard.photoHash() returns false and that's mean user is not yet ready to advertise his image
} else if (i.tagName() == "x" && i.namespaceURI() == "http://jabber.org/protocol/muc#user") {
for (QDomElement muc_e = i.firstChildElement(); !muc_e.isNull(); muc_e = muc_e.nextSiblingElement()) {
if (muc_e.tagName() == "item")
Expand Down

0 comments on commit e8efe0b

Please sign in to comment.