Skip to content

Commit 0cf2bb1

Browse files
fix #349: Remove Twitter as profile image source option due to API restrictions (#541)
* fix: Remove Twitter as profile image source option due to API restrictions * Use a direct enum comparison (e.g., imageType != ImageType.Twitter) instead of string matching on ToString() Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Initiate helper method SanitizeImageType * Comparing enum values via ToString() is fragile and incurs allocations; use a direct enum check (imageType == ImageType.Twitter) instead. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * TO fix warning - Moved static method before instance methods * Converts Twitter ImageType to Anonymous * Use Linq where statement instead if - to exclude twitter from options --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 511cc7e commit 0cf2bb1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

headapps/MvpSite/MvpSite.Rendering/ViewComponents/Any/MyDataEditViewComponent.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public override async Task<IViewComponentResult> InvokeAsync()
2828
Name = model.Name ?? string.Empty,
2929
Email = model.Email ?? string.Empty,
3030
Country = new Country(model.CountryId),
31-
ImageType = model.ImageType
31+
32+
// Clear Twitter ImageType if selected, as Twitter API is no longer available
33+
ImageType = SanitizeImageType(model.ImageType)
3234
};
3335

3436
userResponse = await Client.UpdateCurrentUserAsync(updatedUser);
@@ -44,7 +46,9 @@ public override async Task<IViewComponentResult> InvokeAsync()
4446
model.Name = user.Name;
4547
model.Email = user.Email;
4648
model.CountryId = user.Country?.Id ?? 0;
47-
model.ImageType = user.ImageType;
49+
50+
// Clear Twitter ImageType if selected, as Twitter API is no longer available
51+
model.ImageType = SanitizeImageType(user.ImageType);
4852
model.ImageUri = user.ImageUri;
4953
ModelState.Clear();
5054
}
@@ -71,6 +75,12 @@ public override async Task<IViewComponentResult> InvokeAsync()
7175
return result;
7276
}
7377

78+
/// Converts Twitter ImageType to Anonymous as Twitter API is no longer available
79+
private static ImageType SanitizeImageType(ImageType imageType)
80+
{
81+
return imageType == ImageType.Twitter ? ImageType.Anonymous : imageType;
82+
}
83+
7484
private async Task LoadCountries(MyDataEditModel model)
7585
{
7686
Response<IList<Country>> countryResponse = await Client.GetCountriesAsync(1, short.MaxValue);

headapps/MvpSite/MvpSite.Rendering/Views/Shared/Components/AnyMyDataEdit/Default.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
</label>
4646
<span class="text-danger">*</span>
4747
<select asp-for="ImageType" class="form-control" required>
48-
@foreach (ImageType imageType in Enum.GetValues<ImageType>())
48+
@* Exclude Twitter option as Twitter API is no longer available *@
49+
@foreach (ImageType imageType in Enum.GetValues<ImageType>().Where(x => x != ImageType.Twitter))
4950
{
5051
<option value="@imageType">@imageType</option>
5152
}

0 commit comments

Comments
 (0)