Skip to content

Commit e8efe0b

Browse files
committed
little sugar
1 parent 0184b6c commit e8efe0b

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

src/xmpp/jid/jid.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ void Jid::setNode(const QString &s)
307307

308308
void Jid::setResource(const QString &s)
309309
{
310+
if (r == s) {
311+
return;
312+
}
310313
if (!valid)
311314
return;
312315
QString norm;

src/xmpp/xmpp-core/xmpp_stanza.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ class Stanza {
7979
int code() const;
8080
bool fromCode(int code);
8181

82+
inline bool isCancel() const { return type == ErrorType::Cancel; }
83+
inline bool isContinue() const { return type == ErrorType::Continue; }
84+
inline bool isModify() const { return type == ErrorType::Modify; }
85+
inline bool isAuth() const { return type == ErrorType::Auth; }
86+
inline bool isWait() const { return type == ErrorType::Wait; }
87+
8288
QPair<QString, QString> description() const;
8389
QString toString() const;
8490

src/xmpp/xmpp-im/types.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,13 +2067,13 @@ class StatusPrivate : public QSharedData {
20672067
public:
20682068
StatusPrivate() = default;
20692069

2070-
int priority = 0;
2071-
QString show, status, key;
2072-
QDateTime timeStamp;
2073-
bool isAvailable = false;
2074-
bool isInvisible = false;
2075-
QByteArray photoHash;
2076-
bool hasPhotoHash = false;
2070+
int priority = 0;
2071+
QString show, status, key;
2072+
QDateTime timeStamp;
2073+
bool isAvailable = false;
2074+
bool isInvisible = false;
2075+
2076+
std::optional<QByteArray> photoHash;
20772077

20782078
QString xsigned;
20792079
// gabber song extension
@@ -2230,15 +2230,9 @@ void Status::setMUCHistory(int maxchars, int maxstanzas, int seconds, const QDat
22302230
d->mucHistorySince = since;
22312231
}
22322232

2233-
const QByteArray &Status::photoHash() const { return d->photoHash; }
2234-
2235-
void Status::setPhotoHash(const QByteArray &h)
2236-
{
2237-
d->photoHash = h;
2238-
d->hasPhotoHash = true;
2239-
}
2233+
const std::optional<QByteArray> &Status::photoHash() const { return d->photoHash; }
22402234

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

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

src/xmpp/xmpp-im/xmpp_status.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <QString>
3030
#include <QStringList>
3131

32+
#include <optional>
33+
3234
namespace XMPP {
3335
class DiscoItem;
3436
class StatusPrivate;
@@ -132,9 +134,8 @@ class Status {
132134
void setSongTitle(const QString &);
133135

134136
// XEP-0153: vCard-Based Avatars
135-
const QByteArray &photoHash() const;
136-
void setPhotoHash(const QByteArray &);
137-
bool hasPhotoHash() const;
137+
const std::optional<QByteArray> &photoHash() const;
138+
void setPhotoHash(const QByteArray &);
138139

139140
// XEP-0231 bits of binary
140141
void addBoBData(const BoBData &);

src/xmpp/xmpp-im/xmpp_tasks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ void JT_Presence::pres(const Status &s)
610610
tag.appendChild(m);
611611
}
612612

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

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

0 commit comments

Comments
 (0)