private static IList <ArchivedMessage> GetChatMessagesFromStanza(XmlElement xml) { List <ArchivedMessage> messages = new List <ArchivedMessage>(); DateTimeOffset startTime = default(DateTimeOffset); var startAttribute = xml.Attributes["start"]; if (startAttribute != null) { startTime = DateTimeProfiles.FromXmppString(startAttribute.InnerText); } var messageNodes = xml.GetElementsByTagName("from"); foreach (XmlElement node in messageNodes) { messages.Add(GetChatMessageFromNode(startTime, node)); } messageNodes = xml.GetElementsByTagName("to"); foreach (XmlElement node in messageNodes) { messages.Add(GetChatMessageFromNode(startTime, node)); } return(messages.OrderBy(m => m.Timestamp).ToList()); }
private static IList <ArchivedChatId> GetChatIdsFromStanza(XmlElement xml) { List <ArchivedChatId> chats = new List <ArchivedChatId>(); var chatNodes = xml.GetElementsByTagName("chat"); foreach (XmlNode node in chatNodes) { string with = null; try { with = node.Attributes["with"].InnerText; } catch { } DateTimeOffset start = default(DateTimeOffset); try { string startText = node.Attributes["start"].InnerText; start = DateTimeProfiles.FromXmppString(startText); } catch { } chats.Add(new ArchivedChatId(with, start)); } return(chats); }
/// <summary> /// Create an archived chat page from an xml response /// </summary> /// <param name="xml"></param> internal ArchivedChatPage(XmlElement xml) : base(xml, GetChatMessagesFromStanza) { var withAttribute = xml.Attributes["with"]; if (withAttribute != null) { With = withAttribute.InnerText; } var startAttribute = xml.Attributes["start"]; if (startAttribute != null) { Start = DateTimeProfiles.FromXmppString(startAttribute.InnerText); } var subjectAttribute = xml.Attributes["subject"]; if (subjectAttribute != null) { Subject = subjectAttribute.InnerText; } var versionAttribute = xml.Attributes["version"]; if (versionAttribute != null) { int version = 0; int.TryParse(versionAttribute.InnerText, out version); Version = version; } }
/// <summary> /// Try to get a timestamp from a delay node. If this fails, return the current UTC time. /// </summary> /// <param name="xml">The xml node that contains a delay node</param> public static DateTimeOffset GetDelayedTimestampOrNow(XmlElement xml) { DateTimeOffset timestamp = DateTimeOffset.UtcNow; // Refer to XEP-0203. var delay = xml["delay"]; if (delay != null && delay.NamespaceURI == "urn:xmpp:delay") { var stampAttribute = delay.GetAttribute("stamp"); if (stampAttribute != null) { timestamp = DateTimeProfiles.FromXmppString(stampAttribute); } } return(timestamp); }