Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Added XEP-0359: Unique and Stable Stanza IDs support
Browse files Browse the repository at this point in the history
* As a first part for adding MAM support #139
  • Loading branch information
COM8 committed Oct 9, 2020
1 parent 9ad10fb commit 2d76bac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Follow [@UWPX_APP](https://twitter.com/UWPX_APP) on ![Twitter](http://i.imgur.co
| Chat Markers | [XEP-0333](https://xmpp.org/extensions/xep-0333.html "XEP-0333") | 0.4 (2020-04-15) |
| Message Processing Hints | [XEP-0334](https://xmpp.org/extensions/xep-0334.html "XEP-0334") | 0.3.0 (2018-01-25) |
| Data Forms - Dynamic Forms | [XEP-0336](https://xmpp.org/extensions/xep-0336.html) | 0.2 (2015-11-09) |
| Unique and Stable Stanza IDs | [XEP-0359](https://xmpp.org/extensions/xep-0359.html) | 0.6.0 (2018-10-01) |
| Consistent Color Generation | [XEP-0392](https://xmpp.org/extensions/xep-0392.html) | 0.7.0 (2019-10-16) |


Expand Down
5 changes: 5 additions & 0 deletions XMPP_API/Classes/Network/XML/Messages/AbstractMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public byte getRestartConnection()
return restartConnection;
}

/// <summary>
/// Generates a new random RFC 4122 UUID and returns it as a string.
/// Example: de305d54-75b4-431b-adb2-eb6b9e546013
/// </summary>
/// <returns>A new random RFC 4122 UUID.</returns>
public static string getRandomId()
{
return Guid.NewGuid().ToString();
Expand Down
53 changes: 25 additions & 28 deletions XMPP_API/Classes/Network/XML/Messages/MessageMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ public MessageMessage(XmlNode node, CarbonCopyType ccType) : base(node.Attribute
if (error != null)
{
XmlNode text = XMLUtils.getChildNode(error, "text");
if (text != null)
{
MESSAGE = text.InnerText;
}
else
{
MESSAGE = error.InnerXml;
}
MESSAGE = text != null ? text.InnerText : error.InnerXml;
}
else
{
Expand Down Expand Up @@ -132,33 +125,33 @@ public DateTime getDelay()

protected static string loadMessageId(XmlNode node)
{
// Check for the default message ID attribute:
string id = node.Attributes["id"]?.Value;
if (!(id is null))
// Check for a 'XEP-0359: Unique and Stable Stanza IDs' ID:
XmlNode stanzaIdNode = XMLUtils.getChildNode(node, "stanza-id", Consts.XML_XMLNS, Consts.XML_XEP_0359_NAMESPACE);
if (!(stanzaIdNode is null))
{
return id;
string sId = stanzaIdNode.Attributes["id"]?.Value;
if (!(sId is null))
{
return sId;
}
}

// Check for a MAM-ID in the archived node:
XmlNode archivedNode = XMLUtils.getChildNode(node, "archived", Consts.XML_XMLNS, Consts.XML_XEP_0313_TMP_NAMESPACE);
if (!(archivedNode is null))
{
id = archivedNode.Attributes["id"]?.Value;
if (!(id is null))
string mamId = archivedNode.Attributes["id"]?.Value;
if (!(mamId is null))
{
return id;
return mamId;
}
}

// Check for a 'XEP-0359: Unique and Stable Stanza IDs' ID:
XmlNode stanzaIdNode = XMLUtils.getChildNode(node, "stanza-id", Consts.XML_XMLNS, Consts.XML_XEP_0359_NAMESPACE);
if (!(stanzaIdNode is null))
// Check for the default message ID attribute:
string id = node.Attributes["id"]?.Value;
if (!(id is null))
{
id = stanzaIdNode.Attributes["id"]?.Value;
if (!(id is null))
{
return id;
}
return id;
}

// Fall back to a new message ID:
Expand All @@ -182,11 +175,6 @@ public override XElement toXElement()
msgNode.Add(new XAttribute("to", TO));
}

if (ID != null)
{
msgNode.Add(new XAttribute("id", ID));
}

if (TYPE != null)
{
msgNode.Add(new XAttribute("type", TYPE));
Expand All @@ -197,6 +185,15 @@ public override XElement toXElement()
msgNode.Add(new XElement("body", MESSAGE));
}

// XEP-0359 (Unique and Stable Stanza IDs):
if (ID != null)
{
XNamespace ns = Consts.XML_XEP_0359_NAMESPACE;
XElement originId = new XElement(ns + "origin-id", MESSAGE);
originId.Add(new XAttribute("id", ID));
msgNode.Add(originId);
}

// XEP-0203 (Delayed Delivery):
if (delay != DateTime.MinValue)
{
Expand Down

0 comments on commit 2d76bac

Please sign in to comment.