Managing account aliases and profile synchronization for outlook and gmail.

This commit is contained in:
Burak Kaan Köse
2024-08-17 03:43:37 +02:00
parent f1154058ba
commit abff850427
46 changed files with 949 additions and 272 deletions
+12 -53
View File
@@ -23,6 +23,7 @@ using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Exceptions;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Accounts;
using Wino.Core.Domain.Models.MailItem;
using Wino.Core.Domain.Models.Requests;
using Wino.Core.Domain.Models.Synchronization;
@@ -479,70 +480,28 @@ namespace Wino.Core.Synchronizers
/// <returns>Base64 encoded profile picture.</returns>
private async Task<string> GetUserProfilePictureAsync()
{
try
{
var photoStream = await _graphClient.Me.Photos["48x48"].Content.GetAsync();
var photoStream = await _graphClient.Me.Photos["48x48"].Content.GetAsync();
using var memoryStream = new MemoryStream();
await photoStream.CopyToAsync(memoryStream);
var byteArray = memoryStream.ToArray();
using var memoryStream = new MemoryStream();
await photoStream.CopyToAsync(memoryStream);
var byteArray = memoryStream.ToArray();
return Convert.ToBase64String(byteArray);
}
catch (Exception ex)
{
Log.Error(ex, "Error occurred while getting user profile picture.");
return string.Empty;
}
return Convert.ToBase64String(byteArray);
}
private async Task<string> GetSenderNameAsync()
{
try
{
var userInfo = await _graphClient.Users["me"].GetAsync();
var userInfo = await _graphClient.Users["me"].GetAsync();
return userInfo.DisplayName;
}
catch (Exception ex)
{
Log.Error(ex, "Failed to get sender name.");
return string.Empty;
}
return userInfo.DisplayName;
}
protected override async Task SynchronizeProfileInformationAsync()
public override async Task<ProfileInformation> SynchronizeProfileInformationAsync()
{
try
{
// Outlook profile info synchronizes Sender Name and Profile Picture.
string senderName = Account.SenderName, base64ProfilePicture = Account.ProfilePictureBase64;
var profilePictureData = await GetUserProfilePictureAsync().ConfigureAwait(false);
var senderName = await GetSenderNameAsync().ConfigureAwait(false);
var profilePictureData = await GetUserProfilePictureAsync().ConfigureAwait(false);
senderName = await GetSenderNameAsync().ConfigureAwait(false);
bool shouldUpdateAccountProfile = (!string.IsNullOrEmpty(senderName) && Account.SenderName != senderName)
|| (!string.IsNullOrEmpty(profilePictureData) && Account.ProfilePictureBase64 != base64ProfilePicture);
if (!string.IsNullOrEmpty(profilePictureData) && Account.ProfilePictureBase64 != profilePictureData)
{
Account.ProfilePictureBase64 = profilePictureData;
}
if (!string.IsNullOrEmpty(senderName) && Account.SenderName != senderName)
{
Account.SenderName = senderName;
}
if (shouldUpdateAccountProfile)
{
await _outlookChangeProcessor.UpdateAccountAsync(Account).ConfigureAwait(false);
}
}
catch (Exception ex)
{
Log.Error(ex, "Failed to synchronize profile information for {Name}", Account.Name);
}
return new ProfileInformation(senderName, profilePictureData);
}
#region Mail Integration