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

Commit

Permalink
Fixed a cause for duplicate MUC messages #46
Browse files Browse the repository at this point in the history
When messages do not have an id attribute, but instead only an MAM archive node with an id attribute UWPX would handle them as new unique messages.
  • Loading branch information
COM8 committed Mar 1, 2020
1 parent c5d669e commit 47d6162
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions XMPP_API/Classes/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ public static class Consts
public const string XML_XEP_0336_NAMESPACE = "urn:xmpp:xdata:dynamic";
// XEP-IoT:
public const string XML_XEP_IOT_NAMESPACE = "urn:xmpp:uwpx:iot";
// XEP-0313 (Message Archive Management)
public const string XML_XEP_0313_NAMESPACE = "urn:xmpp:mam:tmp";
}
}
26 changes: 25 additions & 1 deletion XMPP_API/Classes/Network/XML/Messages/MessageMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MessageMessage(XmlNode node, string type) : this(node, CarbonCopyType.NON
chatMessageId = null;
}

public MessageMessage(XmlNode node, CarbonCopyType ccType) : base(node.Attributes["from"]?.Value, node.Attributes["to"]?.Value, (node.Attributes["id"]?.Value) ?? getRandomId())
public MessageMessage(XmlNode node, CarbonCopyType ccType) : base(node.Attributes["from"]?.Value, node.Attributes["to"]?.Value, loadMessageId(node))
{
CC_TYPE = ccType;
if (!node.HasChildNodes)
Expand Down Expand Up @@ -130,6 +130,30 @@ public DateTime getDelay()
return delay;
}

protected static string loadMessageId(XmlNode node)
{
// Check for the default message ID attribute:
string id = node.Attributes["id"]?.Value;
if (!(id is null))
{
return id;
}

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

// Fall back to a new message ID:
return getRandomId();
}

#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--
Expand Down

0 comments on commit 47d6162

Please sign in to comment.