/// <summary> /// Enters a group conversation /// </summary> /// <param name="sender">A reference to the ListView (i think)</param> /// <param name="e">A reference to the GroupsContent</param> public void groupClicked(object sender, ItemClickEventArgs e) { GroupsContent group = (GroupsContent)e.ClickedItem; MessageHistoryViewModel view = group.messageHistoryViewModel; RightFrameNavigator.Navigate(typeof(MessageHistoryView), view); }
//Constructor used for application code public MessageHistoryViewModel(GroupsContent group) { composeCommand = new DelegateCommand(toggleCanvasView); receiveCommand = new DelegateCommand(receive); addCommand = new DelegateCommand(addUsers); sendTextCommand = new DelegateCommand(sendText); model = new MessageHistoryModel(); navService = NavigationService.getNavigationServiceInstance(); LoadingIndicator = true; History = new ChatHistory(group.group.id); LoadingIndicator = false; this.group = group; // replace with group name when field is supplied if (group.group.Name != null) { this._groupName = group.group.Name; } else { this._groupName = "GROUP NAME"; } }
/// <summary> /// Updates the frames to display the newly created group /// <param>groupContent: The newly created GroupsContent</param> public void displayNewGroup(GroupsContent groupContent) { bool frameVisible = LeftFrameNavigator.isSubFrameVisible(); // determine whether to add the group to the group list or journal list // switch to that list if (groupContent.group.GroupMembers.Count == 1) { journalList.Add(groupContent); switchToJournal(); } else { convoList.Add(groupContent); switchToGroups(); } //display the new conversation in the proper frame if (frameVisible) { LeftFrameNavigator.NavigateSubFrame(typeof(MessageHistoryView), groupContent.messageHistoryViewModel); RightFrameNavigator.Navigate(typeof(MessageHistoryView), groupContent.messageHistoryViewModel); RightFrameNavigator.Navigate(typeof(CanvasPage), groupContent); } else { RightFrameNavigator.Navigate(typeof(MessageHistoryView), groupContent.messageHistoryViewModel); } }
private void GroupsBox_RightTapped(object sender, RightTappedRoutedEventArgs e) { selectedGroup = ((FrameworkElement)e.OriginalSource).DataContext as GroupsContent; ListView lv = (ListView)sender; GroupOptionsFlyout.ShowAt(lv, e.GetPosition(lv)); }
public void TestSetGroupIcon() { Assert.AreEqual("GC", GroupsContent.getGroupIconChars(null)); Assert.AreEqual("GC", GroupsContent.getGroupIconChars("")); Assert.AreEqual("GC", GroupsContent.getGroupIconChars(" ")); Assert.AreEqual("T", GroupsContent.getGroupIconChars("Test")); Assert.AreEqual("LG", GroupsContent.getGroupIconChars("Longer group title")); Assert.AreEqual("TW", GroupsContent.getGroupIconChars(" title with spaces ")); Assert.AreEqual("T", GroupsContent.getGroupIconChars("\nTitle")); }
public GroupsView() { this.InitializeComponent(); LeftFrameNavigator.SetSubFrame(contentFrame); selectedGroup = null; viewModel = new GroupsViewModel(); this.DataContext = viewModel; this.NavigationCacheMode = NavigationCacheMode.Required; App.notificationManager.channel.PushNotificationReceived += OnPushNotification; }
/// <summary> /// Creates a popup box to allow the user to change the group name and then sends the /// updated groupname to the server /// </summary> public async Task changeGroupNameAsync(GroupsContent groupContent) { if (App.User != null) { string currentGroupName = groupContent.group.Name; Tuple <Boolean, String> tup = await createGroupNameInputDialog(); // User inputs Boolean cancelled = tup.Item1; string newGroupName = tup.Item2; if (!cancelled && newGroupName != "") { GroupChat updatedGroup = await renameGroupChat(groupContent.group, newGroupName); // Display message to user if the name change failed (no server) if (updatedGroup == null) { ContentDialog noServerDialog = new ContentDialog() { Title = "Cannot change groupname", Content = "Is your wifi down?", PrimaryButtonText = "Ok" }; await ContentDialogHelper.CreateContentDialogAsync(noServerDialog, true); } else { string members = await getGroupMemberNames(updatedGroup); GroupsContent updatedContent = new GroupsContent(updatedGroup, members); updatedContent.updateCanvasFrom(groupContent); // Preserve ordering int originalIndex = getGroupsContentIndex(groupContent.group.id); GroupsList.Remove(groupContent); GroupsList.Insert(originalIndex, updatedContent); // if the user is currently looking at the group, update the group content message history if (RightFrameNavigator.GetLastContext() != null && RightFrameNavigator.GetLastContext().Equals(groupContent.messageHistoryViewModel)) { RightFrameNavigator.Navigate(typeof(MessageHistoryView), updatedContent.messageHistoryViewModel); } } } } }
/// <summary> /// Checks to see if the collection contains an instance of the group and checks if the group is updated /// if so: removes the old instance /// Finally adds the group if not in the appropriate collection /// </summary> /// <param name="group">the group to update in the lists</param> /// <returns></returns> private void groupsListUpdate(GroupsContent group) { ObservableCollection <GroupsContent> contentList; // determine if the group is in a current list if (journalList.Contains(group)) { contentList = journalList; } else if (convoList.Contains(group)) { contentList = convoList; } else { contentList = null; } // check if the group has been updated if (contentList != null) { int oldGroupIndex = contentList.IndexOf(group); GroupsContent oldGroup = contentList[oldGroupIndex]; group.updateCanvasFrom(oldGroup); // check if the group has been updated, if so remove the old instance if (oldGroup.isUpdated(group)) { contentList.Remove(group); } } // add the group to the appropriate list based on the number of group members if (group.group.GroupMembers.Count == 1 && !journalList.Contains(group)) { journalList.Add(group); } else if (group.group.GroupMembers.Count > 1 && !convoList.Contains(group)) { convoList.Add(group); } }
public CanvasPageViewModel(CanvasElements elements, GroupsContent group) { sendCommand = new DelegateCommand(send); clearButtonCommand = new DelegateCommand(CanvasClear); imageButtonCommand = new DelegateCommand(loadImageAsync); showToolbarButtonCommand = new DelegateCommand(ShowToolbar); model = new CanvasPageModel(); navService = NavigationService.getNavigationServiceInstance(); canvasElements = elements; canvasElements.canvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Mouse | Windows.UI.Core.CoreInputDeviceTypes.Pen | Windows.UI.Core.CoreInputDeviceTypes.Touch; this.group = group; canvasSize = 1080; }
/// <summary> /// Add all groups associated with user to the GroupsList if user is logged in /// </summary> public async void retrieveGroupsFromServer() { System.Diagnostics.Debug.WriteLine("Retrieving groups"); if (App.User != null) { GroupChatApi api = GroupChatApi.getInstance(); IEnumerable <GroupChat> groups = await api.getGroupsForUser(App.User.id); LoadingIndicator = true; foreach (GroupChat g in groups) { string members = await getGroupMemberNames(g); GroupsContent group = new GroupsContent(g, members); groupsListUpdate(group); } LoadingIndicator = false; } }
public async void deleteGroup(GroupsContent groupContent) { int numMembers = groupContent.group.GroupMembers.Count; Boolean leaveOrDeleteGroup = false; // If there are more than 1 members in this group, we leave the chat if (numMembers > 1) { leaveOrDeleteGroup = await createLeaveGroupWarningDialog(); } // If you are the last member in the group, we delete the group else { leaveOrDeleteGroup = await createDeleteGroupWarningDialog(); } // Make rest call and refresh gui if (leaveOrDeleteGroup) { var res = await deleteGroupChat(groupContent.group); GroupsList.Remove(groupContent); // clear the right frame if the user is currently looking at the deleted group if (RightFrameNavigator.GetLastContext() != null && RightFrameNavigator.GetLastContext().Equals(groupContent.messageHistoryViewModel)) { RightFrameNavigator.Navigate(typeof(MessageHistoryView)); } } // refresh gui else { // Preserve ordering int originalIndex = getGroupsContentIndex(groupContent.group.id); GroupsList.Remove(groupContent); GroupsList.Insert(originalIndex, groupContent); //retrieveGroupsFromServer(); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { // updates the GroupsView when a group is changed (when a user is added to the group) if (e.Parameter is GroupsContent) { GroupsContent updatedContent = (GroupsContent)e.Parameter; // Need to first remove the GroupsContent, then display the new group content if (viewModel.GroupsList.Contains(updatedContent)) { viewModel.GroupsList.Remove(updatedContent); } viewModel.displayNewGroup(updatedContent); } else if (e.Parameter is string) { string selectedList = (string)e.Parameter; switch (selectedList) { case "groups": viewModel.switchToGroups(); break; case "journal": viewModel.switchToJournal(); break; default: viewModel.resetGroups(); viewModel.switchToGroups(); break; } } }
private async void addGroup() { GroupsContent group; // Groups can only be retrieved if user is logged in if (App.User != null) { Boolean cancelled = false; String groupName = ""; String groupMembers = ""; //enterGroupNameDialog reference: // https://www.reflectionit.nl/blog/2015/windows-10-xaml-tips-messagedialog-and-contentdialog ContentDialog enterGroupNameDialog = new ContentDialog() { Title = "Create a new group" }; var panel = new StackPanel(); // create the text box for user to set a group name TextBox groupNameBox = setTextBox("Enter a group name (max 20 characters)", ""); // create the text box for user to add initial group members TextBox groupMemberBox = setTextBox("Enter user emails", "Separate multiple emails with a space..."); // add the textboxes to the stackpanel panel.Children.Add(groupNameBox); panel.Children.Add(groupMemberBox); enterGroupNameDialog.Content = panel; enterGroupNameDialog.PrimaryButtonText = "Create"; enterGroupNameDialog.PrimaryButtonClick += delegate { groupName = groupNameBox.Text; groupMembers = groupMemberBox.Text; }; enterGroupNameDialog.SecondaryButtonText = "Cancel"; enterGroupNameDialog.SecondaryButtonClick += delegate { cancelled = true; }; await ContentDialogHelper.CreateContentDialogAsync(enterGroupNameDialog, true); if (!cancelled) { if (groupName != "") { // initial list of users in group includes the logged in user and the groupMembers specified in groupMemberBox List <string> users = await setInitialUserList(groupMembers); GroupChat newGroup = new PenscribCommon.Models.GroupChat { GroupMembers = users, CreationDate = DateTime.Now, Name = groupName }; GroupChatApi api = GroupChatApi.getInstance(); GroupChat createdGroup = await api.postGroupChat(newGroup); // Show error if group was unable to be posted to the server if (createdGroup == null) { ContentDialog errorDialog = new ContentDialog() { Title = "Unable to sync group with server", Content = "You are not connected to the server and so the group could not be pushed", PrimaryButtonText = "Ok" }; await ContentDialogHelper.CreateContentDialogAsync(errorDialog, true); group = new GroupsContent(defaultGroup, ""); } else { string members = await getGroupMemberNames(createdGroup); group = new GroupsContent(createdGroup, members); } // update the content in the view //displayNewGroup(group); LeftFrameNavigator.Navigate(typeof(GroupsView), group); } else { ContentDialog invalidGroupNameDialog = new ContentDialog() { Title = "Invalid group name", Content = "Please enter a group name", PrimaryButtonText = "Ok" }; await ContentDialogHelper.CreateContentDialogAsync(invalidGroupNameDialog, true); addGroup(); } } } else { ContentDialog notLoggedInDialog = new ContentDialog() { Title = "Not logged in", Content = "You are not logged in and cannot sync with the server", PrimaryButtonText = "Ok" }; await ContentDialogHelper.CreateContentDialogAsync(notLoggedInDialog, true); group = new GroupsContent(defaultGroup, ""); // update the content in the view //displayNewGroup(group); LeftFrameNavigator.Navigate(typeof(GroupsView), defaultGroup); } }
/// <summary> /// Add users to the group (helper for testability reasons) /// </summary> public virtual async void addUsers(string usersToAdd) { if (usersToAdd != "") { // separate input based on space char[] separators = { ' ', '\t', '\n' }; String[] users = usersToAdd.Split(separators); bool newUsers = false; GroupChat updatedGroup = null; // Look at each potential user foreach (String user in users) { // Add user to the group if a valid email address is provided and user is not already in group // possibly perform a different check here? (check database for matching email?) if (isValidEmail(user)) { // Need to perform check to see if email is in db User dbUser = await getUserFromEmail(user); //User dbUser = theUserFromEmail; // Display a dialog stating the user does not exist if (dbUser == null) { displayContentDialogDispatch(contentDialogType.DNE, user); } // Display a dialog stating the user has already been added to the group else if (group.group.GroupMembers.Contains(dbUser.id)) { displayContentDialogDispatch(contentDialogType.RepeatMember, user); } else { group.group.GroupMembers.Add(dbUser.id); //GroupChat updatedGroup = await GroupChatApi.getInstance().updateGroupChat(group); updatedGroup = await updateGroupChat(group.group); // Display a dialog stating the user is already in the group if (updatedGroup == null) { displayContentDialogDispatch(contentDialogType.NoServer, user); group.group.GroupMembers.Remove(dbUser.id); } else { displayContentDialogDispatch(contentDialogType.SuccessfulAdd, user); newUsers = true; } } } // Display a dialog stating the input is not a valid email address form else { displayContentDialogDispatch(contentDialogType.InvalidEmail, user); } } // after all users have been checked, if at least one was successful then we need to update // the views if (newUsers) { string members = await getGroupMemberNames(updatedGroup); GroupsContent updatedContent = new GroupsContent(updatedGroup, members); updatedContent.updateCanvasFrom(group); // call needed to update the group lists in the GroupsViewModel LeftFrameNavigator.Navigate(typeof(GroupsView), updatedContent); } } }