Example #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);
                        }
                    }
                }
            }
        }
Example #2
0
        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();
            }
        }