/// <summary>
 /// Initializes a new instance of the Message class.
 /// </summary>
 /// <param name="to">The JID of the intended recipient.</param>
 /// <param name="body">The content of the message.</param>
 /// <param name="subject">The subject of the message.</param>
 /// <param name="thread">The conversation thread this message belongs to.</param>
 /// <param name="type">The type of the message. Can be one of the values from
 /// the MessagType enumeration.</param>
 /// <param name="language">The language of the XML character data of
 /// the stanza.</param>
 /// <exception cref="ArgumentNullException">The to parameter is null.</exception>
 /// <exception cref="ArgumentException">The body parameter is the empty string.</exception>
 public Message(Jid to, string body = null, string subject = null, string thread = null,
                MessageType type    = MessageType.Normal, CultureInfo language = null)
     : base(to, null, null, null, language)
 {
     to.ThrowIfNull("to");
     AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang");
     AlternateBodies   = new XmlDictionary(element, "body", "xml:lang");
     Type    = type;
     Body    = body;
     Subject = subject;
     Thread  = thread;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the Message class.
 /// </summary>
 /// <param name="to">The JID of the intended recipient.</param>
 /// <param name="body">The content of the message.</param>
 /// <param name="subject">The subject of the message.</param>
 /// <param name="thread">The conversation thread this message belongs to.</param>
 /// <param name="type">The type of the message. Can be one of the values from
 /// the MessagType enumeration.</param>
 /// <param name="language">The language of the XML character data of
 /// the stanza.</param>
 /// <exception cref="ArgumentNullException">The to parameter is null.</exception>
 /// <exception cref="ArgumentException">The body parameter is the empty string.</exception>
 public Message(Jid to, string body = null, string subject = null, string thread = null,
                MessageType type    = MessageType.Normal, CultureInfo language = null)
     : base(to, null, null, null, language)
 {
     to.ThrowIfNull("to");
     AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang");
     AlternateBodies   = new XmlDictionary(element, "body", "xml:lang");
     Type      = type;
     Body      = SecurityElement.Escape(body);
     Subject   = SecurityElement.Escape(subject);
     Thread    = thread;
     Timestamp = DelayedDelivery.GetDelayedTimestampOrNow(element);
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the Message class from the specified
        /// instance.
        /// </summary>
        /// <param name="messageNode">A message xml node</param>
        /// <param name="timestamp">The timestamp to use for the message</param>
        /// <exception cref="ArgumentNullException">The message parameter is null.</exception>
        /// <exception cref="ArgumentException">The 'type' attribute of
        /// the specified message stanza is invalid.</exception>
        internal Message(XmlElement messageNode, DateTimeOffset timestamp)
        {
            messageNode.ThrowIfNull("messageNode");
            type              = ParseType(messageNode.GetAttribute("type"));
            element           = messageNode;
            AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang");
            AlternateBodies   = new XmlDictionary(element, "body", "xml:lang");
            Timestamp         = timestamp;

            var forwardedMessageNode = element["forwarded"];

            if (forwardedMessageNode != null && forwardedMessageNode.NamespaceURI == "urn:xmpp:forward:0")
            {
                var forwardedTimestamp = DelayedDelivery.GetDelayedTimestampOrNow(forwardedMessageNode);
                ForwardedMessage = new Message(forwardedMessageNode["message"], forwardedTimestamp);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the Message class.
 /// </summary>
 /// <param name="to">The JID of the intended recipient.</param>
 /// <param name="bodies">A dictionary of message bodies. The dictionary
 /// keys denote the languages of the message bodies and must be valid
 /// ISO 2 letter language codes.</param>
 /// <param name="subjects">A dictionary of message subjects. The dictionary
 /// keys denote the languages of the message subjects and must be valid
 /// ISO 2 letter language codes.</param>
 /// <param name="thread">The conversation thread this message belongs to.</param>
 /// <param name="type">The type of the message. Can be one of the values from
 /// the MessagType enumeration.</param>
 /// <param name="language">The language of the XML character data of
 /// the stanza.</param>
 /// <exception cref="ArgumentNullException">The to parametr or the bodies
 /// parameter is null.</exception>
 public Message(Jid to, IDictionary <string, string> bodies,
                IDictionary <string, string> subjects = null, string thread = null,
                MessageType type = MessageType.Normal, CultureInfo language = null)
     : base(to, null, null, null, language)
 {
     to.ThrowIfNull("to");
     bodies.ThrowIfNull("bodies");
     AlternateSubjects = new XmlDictionary(element, "subject", "xml:lang");
     AlternateBodies   = new XmlDictionary(element, "body", "xml:lang");
     Type = type;
     foreach (var pair in bodies)
     {
         AlternateBodies.Add(pair.Key, pair.Value);
     }
     if (subjects != null)
     {
         foreach (var pair in subjects)
         {
             AlternateSubjects.Add(pair.Key, pair.Value);
         }
     }
     Thread = thread;
 }