Beispiel #1
0
        public MessageViewModel(Message message, MessageDirection direction)
            : this()
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Id = message.Id;
            Direction = direction;

            if (message.Content is PlainText)
            {
                Text = ((PlainText)message.Content).Text;
            }
            else
            {
                Text = "(Not supported content type)";
            }
        }
Beispiel #2
0
        private async void Conversation_LocalChatStateChanged(object sender, ChatStateEventArgs e)
        {
            if (!ModernUIHelper.IsInDesignMode)
            {
                var message = new Message()
                {
                    Id = Guid.Empty, // Fire and Forget mode
                    To = new Node()
                    {
                        Name = Contact.Identity.Name,
                        Domain = Contact.Identity.Domain                        
                    },
                    Content = new ChatState()
                    {
                        State = e.ChatState
                    }
                };

                await _clientChannel.SendMessageAsync(message);
            }
        }
Beispiel #3
0
        private async void Conversation_Messages_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (!ModernUIHelper.IsInDesignMode)
            {
                if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                {
                    foreach (var messageViewModel in e.NewItems.Cast<MessageViewModel>().Where(m => m.Direction == MessageDirection.Output))
                    {
                        var message = new Message()
                        {
                            Id = messageViewModel.Id,
                            To = new Node()
                            {
                                Name = this.Contact.Identity.Name,
                                Domain = this.Contact.Identity.Domain
                            },
                            Content = new PlainText()
                            {
                                Text = messageViewModel.Text
                            }
                        };

                        await _clientChannel.SendMessageAsync(message);
                    }
                }
            }
        }
Beispiel #4
0
		private static async Task MainAsync(string[] args)
		{
			var identity = GetNodeFromConsole ("Enter the identity (name@domain format): ");

			if (identity == null)
			{
				return;
			}

			System.Console.Write ("Enter the password: "******"Connecting...");

			var channel = await ConnectAsync ();

			System.Console.WriteLine ("Connected - Remote node: {0}", channel.RemoteNode);

			System.Console.WriteLine ("Authenticating...");

			var session = await AuthenticateAsync (channel, identity, password);

			if (session.State == SessionState.Established) 
			{
				System.Console.WriteLine ("Session established - Id: {0} - Local node: {1}", session.Id, channel.LocalNode);

				System.Console.WriteLine ("Setting presence...");

				var presenceResult = await SetPresenceAvailableAsync (channel);

				if (presenceResult.Status == CommandStatus.Success)
				{
					System.Console.WriteLine ("Presence set.");

					var cancellationTokenSource = new CancellationTokenSource ();

					var receiveMessagesTask = ReceiveMessagesAsync (channel, cancellationTokenSource.Token);
					var receiveNotificationsTask = ReceiveNotificationsAsync (channel, cancellationTokenSource.Token);


					while (true)
					{
						var destinationIdentity = GetNodeFromConsole ("Enter the destination (name@domain/instance format) or 'exit' to quit: ");
						if (destinationIdentity == null)
						{
							break;
						}

						System.Console.Write ("Enter the message text: ") ;
						var messageText = System.Console.ReadLine ();

						if (string.IsNullOrWhiteSpace ((messageText)))
						{
							break;
						}

						var message = new Message () 
						{
							To = destinationIdentity,
							Content = new PlainText () 
							{
								Text = messageText
							}
						};

						await channel.SendMessageAsync (message);
					}

					cancellationTokenSource.Cancel ();
					await Task.WhenAll (receiveMessagesTask, receiveNotificationsTask);
				}
				else
				{
					System.Console.WriteLine ("Presence command failed - Reason: {0}", presenceResult.Reason);
				}
			}
			else
			{
				System.Console.WriteLine ("Session failed - Reason: {0}", session.Reason);
			}
		}
 internal void ReceiveMessage(Message message)
 {
     if (message.Content is PlainText)
     {
         Messages.Add(new MessageViewModel(message, MessageDirection.Input));
     }
     else if (message.Content is ChatState)
     {
         var chatStateContent = (ChatState)message.Content;
         ChatState = chatStateContent.State;
     }
 }
Beispiel #6
0
        public Task SendTextMessageAsync(Node to, string text)
        {
            var message = new Message()
            {
                To = to,
                Content = new PlainText()
                {
                    Text = text
                }
            };

            return Channel.SendMessageAsync(message);
        }