Beispiel #1
0
        /// <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;
            }
        }
Beispiel #2
0
 protected virtual async Task <HttpResponseMessage> deleteGroupChat(GroupChat group)
 {
     return(await GroupChatApi.getInstance().leaveGroupChat(group, App.User.id));
 }
Beispiel #3
0
 protected virtual async Task <GroupChat> updateGroupChat(GroupChat group)
 {
     return(await GroupChatApi.getInstance().updateGroupChat(group));
 }
Beispiel #4
0
 protected virtual async Task <GroupChat> renameGroupChat(GroupChat group, string newName)
 {
     return(await GroupChatApi.getInstance().renameGroupChat(group, newName));
 }
        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);
            }
        }