Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:XmppEventMessage"/> class.
 /// </summary>
 /// <param name="message">The event.</param>
 internal XmppEventMessage(Message message)
 {
     this.identifier     = message.ID;
     this.from 		    = message.From;
     this.to			    = message.To;
     this.eventMessage	= (PubSubEvent)message.Items[0];
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:XmppMessage"/> class.
 /// </summary>
 /// <param name="message">The message.</param>
 internal XmppMessage(Message message)
 {
     this.Initialize(message);
 }
Example #3
0
        private void Initialize(Message message)
        {
            this.identifier             = message.ID;
            this.from                   = message.From;
            this.to			            = message.To;
            this.language               = message.Lang;
            this.type                   = message.Type;
            this.thread                 = String.Empty;
            this.chatStateNotification  = XmppChatStateNotification.None;

            foreach (object item in message.Items)
            {
                if (item is MessageBody)
                {
                    this.body = ((MessageBody)item).Value;
                }
                else if (item is MessageSubject)
                {
                    this.subject = ((MessageSubject)item).Value;
                }
                else if (item is NotificationActive)
                {
                    this.chatStateNotification = XmppChatStateNotification.Active;
                }
                else if (item is NotificationComposing)
                {
                    this.chatStateNotification = XmppChatStateNotification.Composing;
                }
                else if (item is NotificationGone)
                {
                    this.chatStateNotification = XmppChatStateNotification.Gone;
                }
                else if (item is NotificationInactive)
                {
                    this.chatStateNotification = XmppChatStateNotification.Inactive;
                }
                else if (item is NotificationPaused)
                {
                    this.chatStateNotification = XmppChatStateNotification.Paused;
                }
            }
        }
Example #4
0
 /// <summary>
 /// Process an XMPP Message
 /// </summary>
 /// <param name="message"></param>
 private void ProcessMessage(Message message)
 {
     if (message.Items.Count > 0 &&
         message.Items[0] is PubSubEvent)
     {
         this.onEventMessage.OnNext(new XmppEventMessage(message));
     }
     else
     {
         this.onMessageReceived.OnNext(new XmppMessage(message));
     }
 }
Example #5
0
        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public XmppChatRoom SendMessage(string message)
        {
            Message chatMessage = new Message
            {
                ID      = XmppIdentifierGenerator.Generate(),
                Type    = MessageType.GroupChat,
                From    = this.Session.UserId.ToString(),
                To      = this.Identifier
            };

            chatMessage.Items.Add
            (
                new MessageBody
                {
                    Value = message
                }
            );

            this.Session.Send(chatMessage);

            return this;
        }
Example #6
0
        /// <summary>
        /// Invites the given contact to the chat room
        /// </summary>
        /// <param name="contact"></param>
        public XmppChatRoom Invite(XmppContact contact)
        {
            MucUser user    = new MucUser();
            Message message = new Message
            {
                From    = this.Session.UserId,
                To      = this.Identifier.BareIdentifier,
            };
            MucUserInvite   invite  = new MucUserInvite
            {
                To      = contact.ContactId.BareIdentifier,
                Reason  = "Ninja invite"
            };

            user.Items.Add(invite);
            message.Items.Add(user);

            this.Session.Send(message);

            return this;
        }
Example #7
0
        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public string SendMessage(string message)
        {
            if (this.session == null)
            {
                throw new InvalidOperationException("Chat session is closed.");
            }

            MessageBody body = new MessageBody
            {
                Value = message
            };

            Message chatMessage = new Message
            {
                ID      = XmppIdentifierGenerator.Generate(),
                Type    = MessageType.Chat,
                From    = this.session.UserId.ToString(),
                To      = this.Contact.ContactId.ToString(),
            };

            if (this.Contact.SupportsChatStateNotifications)
            {
                chatMessage.Items.Add(CreateChatStateNotification(XmppChatStateNotification.Active));
            }

            chatMessage.Items.Add(body);

            this.session.Send(chatMessage);

            return chatMessage.ID;
        }
Example #8
0
        /// <summary>
        /// Sends a chat state notification
        /// </summary>
        /// <param name="notificationType"></param>
        public void SendChatStateNotification(XmppChatStateNotification notificationType)
        {
            // Generate the notification only if the target entity supports it
            if (this.Contact.SupportsChatStateNotifications)
            {
                Message message = new Message
                {
                    ID      = XmppIdentifierGenerator.Generate(),
                    Type    = MessageType.Chat,
                    From    = this.session.UserId.ToString(),
                    To      = this.Contact.ContactId.ToString(),
                };

                message.Items.Add(CreateChatStateNotification(notificationType));

                this.session.Send(message);
            }
        }