Skip to content

Commit e1fe8a8

Browse files
authored
Баг: показывать телеграм в профиле, даже если нет аватарки (#3301)
fixes #3286
1 parent ba2f54a commit e1fe8a8

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/JoinRpg.Portal/Infrastructure/Authentication/ExternalLoginProfileExtractor.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public async Task TryExtractTelegramProfile(JoinIdentityUser user, Dictionary<st
4545

4646
await userService.SetNameIfNotSetWithoutAccessChecks(user.Id, userFullName);
4747

48-
var avatar = loginInfo.GetValueOrDefault("photo_url");
48+
var avatar = AvatarInfo.FromOptional(loginInfo.GetValueOrDefault("photo_url"), 50);
4949

50-
if (avatar is not null)
51-
{
52-
await userService.SetTelegramIfNotSetWithoutAccessChecks(user.Id, new TelegramId(long.Parse(loginInfo["id"]), prefferedName), new AvatarInfo(new Uri(avatar), 50, 50));
53-
}
50+
var telegramId = new TelegramId(long.Parse(loginInfo["id"]), prefferedName);
51+
52+
await userService.SetTelegramIfNotSetWithoutAccessChecks(user.Id, telegramId, avatar);
5453
}
5554

5655
private static UserFullName TryGetUserName(ExternalLoginInfo loginInfo)

src/JoinRpg.PrimitiveTypes/AvatarInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public AvatarInfo(Uri uri, int size)
77
{
88

99
}
10+
11+
public static AvatarInfo? FromOptional(string? uri, int size) => uri is null ? null : new AvatarInfo(new Uri(uri), size);
1012
}

src/JoinRpg.Services.Impl/UserServiceImpl.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,18 @@ async Task IUserService.SetVkIfNotSetWithoutAccessChecks(int userId, VkId vkId,
143143
await UnitOfWork.SaveChangesAsync();
144144
}
145145

146-
async Task IUserService.SetTelegramIfNotSetWithoutAccessChecks(int userId, TelegramId telegramId, AvatarInfo avatarInfo)
146+
async Task IUserService.SetTelegramIfNotSetWithoutAccessChecks(int userId, TelegramId telegramId, AvatarInfo? avatarInfo)
147147
{
148148
logger.LogInformation("About to link user: {userId} to {telegramId}", userId, telegramId);
149149
var user = await UserRepository.WithProfile(userId);
150150

151151
user.Extra ??= new UserExtra();
152152
user.Extra.Telegram = string.IsNullOrWhiteSpace(telegramId.UserName?.Value) ? user.Extra.Telegram : telegramId.UserName;
153153

154-
await AddSocialAvatarImplAsync(avatarInfo, user, "telegram");
154+
if (avatarInfo is not null)
155+
{
156+
await AddSocialAvatarImplAsync(avatarInfo, user, "telegram");
157+
}
155158

156159
await UnitOfWork.SaveChangesAsync();
157160
}

src/JoinRpg.Services.Interfaces/IUserService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using JoinRpg.DataModel;
2-
using JoinRpg.PrimitiveTypes;
32

43
namespace JoinRpg.Services.Interfaces;
54

@@ -22,7 +21,7 @@ public interface IUserService
2221
Task SetVkIfNotSetWithoutAccessChecks(int id, VkId vkId, AvatarInfo avatarInfo);
2322

2423

25-
Task SetTelegramIfNotSetWithoutAccessChecks(int id, TelegramId telegramId, AvatarInfo avatarInfo);
24+
Task SetTelegramIfNotSetWithoutAccessChecks(int id, TelegramId telegramId, AvatarInfo? avatarInfo);
2625
Task RemoveVkFromProfile(int id);
2726
Task RemoveTelegramFromProfile(int id);
2827
}

0 commit comments

Comments
 (0)