Ejemplo n.º 1
0
        public void UpdateOnlineStatus(string friendName, bool newStatus)
        {
            FriendsListEntry friend = FindFriend(friendName);

            if (friend != null)
            {
                friend.isOnline = newStatus;
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Gets the view model for this <see cref="Page"/>.
		/// This can be changed to a strongly typed view model.
		/* </summary>
		public ObservableDictionary DefaultViewModel
		{
			get { return this.defaultViewModel; }
		}
		*/

		/// <summary>
		/// Populates the page with content passed during navigation.  Any saved state is also
		/// provided when recreating a page from a prior session.
		/// </summary>
		/// <param name="sender">
		/// The source of the event; typically <see cref="NavigationHelper"/>
		/// </param>
		/// <param name="e">Event data that provides both the navigation parameter passed to
		/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
		/// a dictionary of state preserved by this page during an earlier
		/// session.  The state will be null the first time a page is visited.</param>
		private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
		{
			this.ScrollToBottom();
			this.currFriend = AppServices.friendsData.FindFriend(AppServices.friendsData.currFriendsName);
			this.currFriend.unreadCount = "0";
		}
Ejemplo n.º 3
0
		private void friendsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (friendsListView.SelectionMode == ListViewSelectionMode.Single)
			{
				// If selected item is null (no selection) do nothing
				if (friendsListView.SelectedItem == null)
				{
					return;
				}

				// Retrieve the selected friend and toggle the chat buttons
				FriendsListEntry selectedFriend = friendsListView.SelectedItem as FriendsListEntry;

				// Setup the chat variables and open the chat window if we already have a session
				if (selectedFriend.sessionEstablished)
				{
					// Set the binding variables to the data from the current friend we are chatting with and hide the chat buttons
					AppServices.friendsData.currFriendsName = selectedFriend.username;
					AppServices.friendsData.chatHistory = selectedFriend.history;
					AppServices.friendsData.sendButtonEnabled = true;
					selectedFriend.chatButtonsVisible = false;
					lastSelected = null;
					friendsListView.SelectedItem = null;
					Frame.Navigate(typeof(ChatPage));
				}
				else
				{
					// Stop showing the chat buttons for the last selected friend. If the last selected and current selected are the same toggle the buttons
					//	and return
					if (lastSelected != null)
					{
						if (lastSelected.Equals(friendsListView.SelectedItem))
						{
							lastSelected.chatButtonsVisible = !lastSelected.chatButtonsVisible;
							friendsListView.SelectedItem = null;
							return;
						}
						else
						{
							lastSelected.chatButtonsVisible = false;
						}
					}


					selectedFriend.chatButtonsVisible = true;

					lastSelected = selectedFriend;
				}
				
				friendsListView.SelectedItem = null;
				return;
			}
			else if (friendsListView.SelectionMode == ListViewSelectionMode.Multiple)
			{
				return;
			}
		}
Ejemplo n.º 4
0
		// Compute the encryption keys and load the chat page
		private void webChatButton_Click(object sender, RoutedEventArgs e)
		{
			// Tell the user we selected that a session is being established
			if (lastSelected.isOnline && string.IsNullOrWhiteSpace(lastSelected.sessionID) == false)
			{
				AppServices.appWarpLastSentToUsername = lastSelected.username;
				AppServices.warpClient.sendPrivateUpdate(lastSelected.username, MessageBuilder.bulidSessionEstablishedBytes(AppServices.defaultEncryptionKey));
			}
			else if (lastSelected.isOnline == false)
			{
				return;
			}

			

			// No session exists so we create a session
			int compareResult = string.Compare(AppServices.localUsernameEncrypted, lastSelected.encryptedUsername);
			this.keyBuff = null;
			// My username is greater so we use my sessionID as the encryptionKey
			if (compareResult > 0)
			{
				keyBuff = CryptographicBuffer.ConvertStringToBinary(AppServices.localSessionId, BinaryStringEncoding.Utf8);
			}
			else
			{
				keyBuff = CryptographicBuffer.ConvertStringToBinary(lastSelected.sessionID, BinaryStringEncoding.Utf8);
			}
			lastSelected.encryptionKey = AppServices.encryptionAlgorithim.CreateSymmetricKey(keyBuff);
			// Set the binding variables to the data from the current friend we are chatting with and hide the chat buttons
			AppServices.friendsData.currFriendsName = lastSelected.username;
			AppServices.friendsData.chatHistory = lastSelected.history;
			AppServices.friendsData.sendButtonEnabled = true;
			lastSelected.chatButtonsVisible = false;
			lastSelected = null;
			this.Frame.Navigate(typeof(ChatPage));
		}
Ejemplo n.º 5
0
		private void ProximityDeviceDeparted(object sender)
		{
			if (this.publishedMessageID != -1)
			{
				AppServices.myProximityDevice.StopPublishingMessage(this.publishedMessageID);
				this.publishedMessageID = -1;
			}
			if (this.subscribedMessageID != -1)
			{
				AppServices.myProximityDevice.StopSubscribingForMessage(this.subscribedMessageID);
				this.subscribedMessageID = -1;
			}

			AppServices.myProximityDevice.DeviceArrived -= ProximityDeviceArrived;
			AppServices.myProximityDevice.DeviceDeparted -= ProximityDeviceDeparted;

			this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
			{
				// Set the binding variables to the data from the current friend we are chatting with and hide the chat buttons
				AppServices.friendsData.currFriendsName = lastSelected.username;
				AppServices.friendsData.chatHistory = lastSelected.history;
				AppServices.friendsData.sendButtonEnabled = true;
				lastSelected.chatButtonsVisible = false;
				lastSelected = null;
				this.Frame.Navigate(typeof(ChatPage));
			});
		}
Ejemplo n.º 6
0
		private void nfcChatButton_Click(object sender, RoutedEventArgs e)
		{
			if (lastSelected.isOnline == false)
			{
				this.PrintMessage("User is not online, cannot start chat.");
				return;
			}
			if (lastSelected.sessionEstablished)
			{
				lastSelected.chatButtonsVisible = false;
				lastSelected = null;
				this.Frame.Navigate(typeof(ChatPage));
				return;
			}
			if (AppServices.myProximityDevice == null)
			{
				AppServices.myProximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();
				if (AppServices.myProximityDevice == null)
				{
					this.PrintMessage("Unable to get NFC chip. This device might not be capable of proximity interactions or NFC is disabled in settings");
					return;
				}
				AppServices.myProximityDevice.DeviceArrived += ProximityDeviceArrived;
				AppServices.myProximityDevice.DeviceDeparted += ProximityDeviceDeparted;
			}
			int compareResult = string.Compare(AppServices.localUsernameEncrypted, lastSelected.encryptedUsername);
			this.keyBuff = null;
			// My username is greater so I generate a key
			if (compareResult > 0)
			{
				keyBuff = CryptographicBuffer.GenerateRandom(256);
			}

			PrintMessage("Please close this message and then tap and hold the devices together");
		}