Пример #1
0
        public async Task Test3_DeleteNotificationAsync()
        {
            string user_id = "ryZJ4v8INRes4o2ZxEaNOPDtqgo2";
            string team_id = "1fhFeGGSZsIyQqwPkuMA";

            //Act
            //Notification ID  =  User ID  + Team ID   --> To create 1-1 mapping, avoid users to request multiple times
            await NotificationsFirestore.DeleteNotificationAsync(user_id + team_id);

            var notification = await NotificationsFirestore.GetNotificationByIdAsync(user_id + team_id);

            //Assert
            Assert.Null(notification);
        }
        async void JoinButtonClicked(object sender, EventArgs args)
        {
            switch (userStatus)
            {
            case (sbyte)relationshipType.isInside:
                var answer = await DisplayAlert("Exit", "Do you really want to leave your group ?", "Leave", "Cancel");

                if (answer)
                {
                    //If is already inside Team, then button is for leaving the team
                    await TeamsFirestore.RemoveUserFromTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                    await UsersFirestore.RemoveTeamFromUserAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                    //Remove notifications in database
                    await NotificationsFirestore.DeleteNotificationAsync(UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id);

                    joinTeamButton.Text = "Join Team";
                    userStatus          = (sbyte)relationshipType.isOutside;
                }

                break;

            case (sbyte)relationshipType.isRequesting:
                //If is requesting, then button is for cancelled
                await TeamsFirestore.RemoveUserRequestFromTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                //Remove arised notification
                await NotificationsFirestore.DeleteNotificationAsync(UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id);

                await UsersFirestore.RemoveNotificationFromUserAsync(teamDetailsPageViewModel.Team.team_leader
                                                                     , /*Generate ID = User_id + Team_id*/ UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id);

                joinTeamButton.Text = "Join Team";
                userStatus          = (sbyte)relationshipType.isOutside;
                break;

            case (sbyte)relationshipType.isOutside:
                //If is outside, then button is for request joining team
                await TeamsFirestore.AddUserRequestToTeamAsync(UsersFirestore.myProfile.Id, teamDetailsPageViewModel.Team);

                // Create a notification
                Notification notification = new Notification
                {
                    Id      = UsersFirestore.myProfile.Id + teamDetailsPageViewModel.Team.Id,
                    team_id = teamDetailsPageViewModel.Team.Id,
                    user_id = UsersFirestore.myProfile.Id,
                    status  = "",
                    type    = "member_request"
                };

                // Arise a notification to the team leader of that team
                await UsersFirestore.AddNotificationToUserAsync(teamDetailsPageViewModel.Team.team_leader, notification.Id);

                //Push notification online
                await NotificationsFirestore.CreateNotificationAsync(notification);

                joinTeamButton.Text            = "✔️ Requested";
                joinTeamButton.BackgroundColor = Color.FromHex("#D3D3D3");
                userStatus = (sbyte)relationshipType.isRequesting;
                break;
            }
        }