Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MIX message, presence and roster extensions #175

Merged
merged 5 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.2)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 1)
set(SO_VERSION 1)
set(SO_VERSION 2)
Copy link
Contributor

@jlaine jlaine May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated to this PR.

Update: ah shit, roster IQ ABI changed, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the problem.

set(VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_STRING)

Expand Down
1 change: 1 addition & 0 deletions src/base/QXmppConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ const char* ns_mix_node_info = "urn:xmpp:mix:nodes:info";
// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
const char* ns_mix_pam = "urn:xmpp:mix:pam:0";
const char* ns_mix_roster = "urn:xmpp:mix:roster:0";
const char* ns_mix_presence = "urn:xmpp:presence:0";
1 change: 1 addition & 0 deletions src/base/QXmppConstants_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ extern const char* ns_mix_node_info;
// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
extern const char* ns_mix_pam;
extern const char* ns_mix_roster;
extern const char* ns_mix_presence;

#endif // QXMPPCONSTANTS_H
45 changes: 45 additions & 0 deletions src/base/QXmppMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class QXmppMessagePrivate : public QSharedData

// XEP-0308: Last Message Correction
QString replaceId;

// XEP-0369: Mediated Information eXchange (MIX)
QString mixUserJid;
QString mixUserNick;
};

/// Constructs a QXmppMessage.
Expand Down Expand Up @@ -513,6 +517,34 @@ void QXmppMessage::setReplaceId(const QString &replaceId)
d->replaceId = replaceId;
}

/// Returns the actual JID of a MIX channel participant.

QString QXmppMessage::mixUserJid() const
{
return d->mixUserJid;
}

/// Sets the actual JID of a MIX channel participant.

void QXmppMessage::setMixUserJid(const QString& mixUserJid)
{
d->mixUserJid = mixUserJid;
}

/// Returns the MIX participant's nickname.

QString QXmppMessage::mixUserNick() const
{
return d->mixUserNick;
}

/// Sets the MIX participant's nickname.

void QXmppMessage::setMixUserNick(const QString& mixUserNick)
{
d->mixUserNick = mixUserNick;
}

/// \cond
void QXmppMessage::parse(const QDomElement &element)
{
Expand Down Expand Up @@ -654,6 +686,10 @@ void QXmppMessage::parse(const QDomElement &element)
else {
extensions << QXmppElement(xElement);
}
// XEP-0369: Mediated Information eXchange (MIX)
} else if (xElement.tagName() == "mix" && xElement.namespaceURI() == ns_mix) {
d->mixUserJid = xElement.firstChildElement("jid").text();
d->mixUserNick = xElement.firstChildElement("nick").text();
} else if (!knownElems.contains(qMakePair(xElement.tagName(), xElement.namespaceURI())) &&
!knownElems.contains(qMakePair(xElement.tagName(), QString()))) {
// other extensions
Expand Down Expand Up @@ -791,6 +827,15 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}

// XEP-0369: Mediated Information eXchange (MIX)
if (!d->mixUserJid.isEmpty() || !d->mixUserNick.isEmpty()) {
xmlWriter->writeStartElement("mix");
xmlWriter->writeAttribute("xmlns", ns_mix);
helperToXmlAddTextElement(xmlWriter, "jid", d->mixUserJid);
helperToXmlAddTextElement(xmlWriter, "nick", d->mixUserNick);
xmlWriter->writeEndElement();
}

// other extensions
QXmppStanza::extensionsToXml(xmlWriter);

Expand Down
7 changes: 7 additions & 0 deletions src/base/QXmppMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class QXMPP_EXPORT QXmppMessage : public QXmppStanza
QString replaceId() const;
void setReplaceId(const QString&);

// XEP-0369: Mediated Information eXchange (MIX)
QString mixUserJid() const;
void setMixUserJid(const QString&);

QString mixUserNick() const;
void setMixUserNick(const QString&);

/// \cond
void parse(const QDomElement &element);
void toXml(QXmlStreamWriter *writer) const;
Expand Down
50 changes: 49 additions & 1 deletion src/base/QXmppPresence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class QXmppPresencePrivate : public QSharedData

// XEP-0319: Last User Interaction in Presence
QDateTime lastUserInteraction;

// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
QString mixUserJid;
QString mixUserNick;
};

/// Constructs a QXmppPresence.
Expand Down Expand Up @@ -265,6 +269,11 @@ void QXmppPresence::parse(const QDomElement &element)
d->lastUserInteraction = QXmppUtils::datetimeFromString(since);
}
}
// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
else if (xElement.tagName() == "mix" && xElement.namespaceURI() == ns_mix_presence) {
d->mixUserJid = xElement.firstChildElement("jid").text();
d->mixUserNick = xElement.firstChildElement("nick").text();
}
else if (xElement.tagName() != "addresses" && xElement.tagName() != "error"
&& xElement.tagName() != "show" && xElement.tagName() != "status"
&& xElement.tagName() != "priority")
Expand Down Expand Up @@ -361,6 +370,17 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const
xmlWriter->writeEndElement();
}

// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
if (!d->mixUserJid.isEmpty() || !d->mixUserNick.isEmpty()) {
xmlWriter->writeStartElement("mix");
xmlWriter->writeAttribute("xmlns", ns_mix_presence);
if (!d->mixUserJid.isEmpty())
xmlWriter->writeTextElement("jid", d->mixUserJid);
if (!d->mixUserNick.isEmpty())
xmlWriter->writeTextElement("nick", d->mixUserNick);
xmlWriter->writeEndElement();
}

// other extensions
QXmppStanza::extensionsToXml(xmlWriter);

Expand Down Expand Up @@ -522,7 +542,35 @@ void QXmppPresence::setLastUserInteraction(const QDateTime& lastUserInteraction)
d->lastUserInteraction = lastUserInteraction;
}

/// Indicates if the QXmppStanza is a stanza in the XMPP sense (i. e. a message,
/// Returns the actual (full) JID of the MIX channel participant.

QString QXmppPresence::mixUserJid() const
{
return d->mixUserJid;
}

/// Sets the actual (full) JID of the MIX channel participant.

void QXmppPresence::setMixUserJid(const QString& mixUserJid)
{
d->mixUserJid = mixUserJid;
}

/// Returns the MIX participant's nickname.

QString QXmppPresence::mixUserNick() const
{
return d->mixUserNick;
}

/// Sets the MIX participant's nickname.

void QXmppPresence::setMixUserNick(const QString& mixUserNick)
{
d->mixUserNick = mixUserNick;
}

/// Indicates if the QXmppStanza is a stanza in the XMPP sence (i. e. a message,
/// iq or presence)

bool QXmppPresence::isXmppStanza() const
Expand Down
7 changes: 7 additions & 0 deletions src/base/QXmppPresence.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ class QXMPP_EXPORT QXmppPresence : public QXmppStanza
QDateTime lastUserInteraction() const;
void setLastUserInteraction(const QDateTime&);

// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
QString mixUserJid() const;
void setMixUserJid(const QString&);

QString mixUserNick() const;
void setMixUserNick(const QString&);

bool isXmppStanza() const;

private:
Expand Down
Loading