/// <summary> /// Remove a specific friend request "From or To" /// </summary> /// <param name="id">The specific friend Id</param> public async Task <FriendRequest> RemoveFriendRequestByIdAsync(string requestId) { var friendRequests = await FriendRequests .Include(r => r.FromUser) .Include(r => r.ToUser) .Where(r => r.FromUser.Id == CurrentUser.Id || r.ToUser.Id == CurrentUser.Id).ToListAsync(); var request = friendRequests?.SingleOrDefault(r => r.Id == requestId); if (request == null) { return(null); } var user = (request.ToUserId == CurrentUser.Id) ? request.ToUser : request.FromUser; (FriendRequests.Remove(request)).State = EntityState.Deleted; friendRequests.Remove(request); user.HasFriendRequest = friendRequests.Any(r => r.ToUser.Id == user.Id); Db.Entry(user).State = EntityState.Modified; await Db.SaveChangesAsync(); return(request); }
async Task ApproveFriendRequest(PendingFriendRequest pendingFriendRequest) { if (IsBusy) { return; } if (!(await CheckConnectivity("Check connectivity", "Unable to update profile, please check internet and try again"))) { return; } if (!await DisplayAlert("Approve friend request?", $"Are you sure you want to approve {pendingFriendRequest.Name}'s request?", "Yes, approve", "Cancel")) { return; } Analytics.TrackEvent("FriendRequest", new Dictionary <string, string> { ["type"] = "approve" }); IsBusy = true; try { await DataService.ApproveFriendRequestAsync(pendingFriendRequest.RequesterPublicKey); FriendRequests.Remove(pendingFriendRequest); DataService.ClearCache(DataService.FriendRequestKey); forceRefresh = true; SettingsService.FriendRequestCount = FriendRequests.Count == 0 ? string.Empty : FriendRequests.Count.ToString(); SettingsService.ForceRefreshFriends = true; } catch (HttpResponseException hrex) when(!string.IsNullOrWhiteSpace(hrex.Message)) { await DisplayAlert("Uh oh, turbulence", hrex.Message); } catch (Exception ex) { await DisplayAlert("Uh oh, turbulence", "Looks like something went wrong. Check internet and try again."); Crashes.TrackError(ex); } finally { IsBusy = false; } OnPropertyChanged(nameof(ShowNoFriends)); }