Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email to user information display #932

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/DesktopClient/PresenceLight/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private async Task InteractWithLights()
{
if (_appState.User == null || string.IsNullOrEmpty(_appState.User.DisplayName))
{
var (profile, presence) = await _mediator.Send(new Core.GraphServices.GetProfileAndPresenceCommand());
var (profile, presence, email) = await _mediator.Send(new Core.GraphServices.GetProfileAndPresenceCommand());

var photo = await GetPhoto();

Expand All @@ -506,6 +506,8 @@ private async Task InteractWithLights()
MapUI(presence);
_appState.SetUserInfo(profile, presence, $"data:image/gif;base64,{Convert.ToBase64String(photo)}");
}

_appState.Email = email;
}
await Task.Delay(Convert.ToInt32(_appState.Config.LightSettings.PollingInterval * 1000));

Expand Down
6 changes: 6 additions & 0 deletions src/PresenceLight.Core/Configuration/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public class AppState
/// </summary>
public BaseConfig Config { get; set; } = new BaseConfig();

/// <summary>
/// Gets or sets the user's email.
/// </summary>
public string Email { get; set; }

/// <summary>
/// Sets the configuration.
/// </summary>
Expand All @@ -135,6 +140,7 @@ public void SetUserInfo(User? user, Presence? presence, string? photo = null)
User = user;
Presence = presence;
ProfileImage = photo;
Email = user?.Mail;
NotifyStateChanged();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using MediatR;
using Microsoft.Graph.Models;
using System.Threading;
using System.Threading.Tasks;

namespace PresenceLight.Core.GraphServices
{
internal class GetProfileAndPresenceHandler : IRequestHandler<GetProfileAndPresenceCommand, (User User, Presence Presence, string Email)>
{
GraphWrapper _graph;

public GetProfileAndPresenceHandler(GraphWrapper graph)
{
_graph = graph;
}

public async Task<(User User, Presence Presence, string Email)> Handle(GetProfileAndPresenceCommand command, CancellationToken cancellationToken)
{
var (user, presence) = await _graph.GetProfileAndPresence(cancellationToken);
var email = user.Mail;
return (user, presence, email);
}
}
}
4 changes: 2 additions & 2 deletions src/PresenceLight.Razor/Components/Shared/LoginDisplay.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
<MudMenu AnchorOrigin="Origin.CenterCenter" Dense="true" Class="mt-1 ml-4">
<ActivatorContent>
<MudText Typo="Typo.body2" Class="px-4 py-2"> Hello, @appState.User.DisplayName!</MudText>
<MudText Typo="Typo.body2" Class="px-4 py-2"> Hello, @appState.User.DisplayName! (@appState.Email)</MudText>
</ActivatorContent>
<ChildContent>
<MudListItem Text="Logout" Icon="@Icons.Material.Filled.Logout" OnClick="SignOut" />
Expand Down Expand Up @@ -80,4 +80,4 @@ else
{
InvokeAsync(StateHasChanged);
}
}
}
Loading