public async Task<bool> SendMessage(IUser user, IUser friend, string message)
		{
			bool result = await modService.SendMessage(user, friend, message, user.SocialNetwork);

			if (user.SocialNetwork == enSocialNetwork.Twitter)
			{
				var messages = new Message() { Sender = user, Content = message, Recipient = friend };
				Messenger.Default.Send<MessagesUI.MessageNewMyMessageWasSent>(new MessagesUI.MessageNewMyMessageWasSent(messages));
			}

			return result;
		}
		private async Task OnSendMessageCommand()
		{
			try
			{
				bool isSent = await modIWebService.SendMessage(modUser, modFriend, Message);
				var message = new Message() { Sender = modUser, Content = Message, Recipient = modFriend };


			}
			catch (Exception ex)
			{

			}
		}
		private void OnNewMessageWasSentToMe(MessagesUI.MessageNewMessageWasSentToMe msg)
		{
			try
			{
				var message = new Message() 
				{ 
					Sender = msg.Sender.Sender, 
					Content = msg.Sender.Content, 
					Recipient = msg.Sender.Recipient 
				};

				this.Messages.Insert(0, new MessageVm(message) { Name = msg.Sender.Sender.Uid == modUser.Uid ?
																												 String.Format("{0} {1}", modUser.FirstName, modUser.LastName) :
																												 String.Format("{0} {1}", modFriend.FirstName, modFriend.LastName) });
			}
			catch (Exception ex)
			{
			}
		}
예제 #4
0
		public async Task<IEnumerable<IDialog>> GetDialogs(IUser user, enSocialNetwork socialNetwork)
		{
			IList<IDialog> dialogs = null;
			try
			{
				String url =
					String.Format("https://api.vk.com/method/messages.getDialogs?&count={0}&access_token={1}"
					, 100.ToString(), user.SerializeInfo);

				HttpClient httpClient = new HttpClient();
				string response =
					await httpClient.GetStringAsync(new Uri(url));

				string[] responseString = response.Split('[');
				string[] responseDialogsArray = responseString[1].Split('{');

				dialogs = new List<IDialog>();
				foreach (var item in responseDialogsArray)
				{
					try
					{
						string uid = item.Split(',')[3].Split(':')[1];
						string message = String.Empty;
						try
						{
							message = item.Split(',')[6].Split(':')[1];
						}
						catch (Exception ex)
						{
							message = item.Split(',')[6].Split('\"')[0].Trim();
						}

						IUser friend = new User() { Uid = uid, SerializeInfo = user.SerializeInfo };
						IMessage friendMessage = new Message() { Content = message };
						IDialog dialog = new Dialog(friend, new List<IMessage>() { friendMessage });
						dialogs.Add(dialog);
					}
					catch (Exception ex)
					{

					}
				}
			}
			catch (Exception ex)
			{

			}

			return dialogs;
		}