Ejemplo n.º 1
0
        /// <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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        /// <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);
                }
            }
        }