Skip to content

Commit

Permalink
Chat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Jacobsen Work committed Nov 7, 2023
1 parent 767d828 commit 28a8678
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 21 deletions.
9 changes: 2 additions & 7 deletions BLAZAM/BLAZAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>false</ServerGarbageCollection>
<AssemblyVersion>0.8.4</AssemblyVersion>
<Version>2023.11.02.1837</Version>
<Version>2023.11.07.1459</Version>
<RootNamespace>BLAZAM</RootNamespace>
<GenerateDocumentationFile>False</GenerateDocumentationFile>

</PropertyGroup>

<ItemGroup>
<Compile Remove="Exceptions\**" />
<Content Remove="Exceptions\**" />
<EmbeddedResource Remove="Exceptions\**" />
<None Remove="Exceptions\**" />
</ItemGroup>


<ItemGroup>
<None Remove="nssm.exe" />
Expand Down
4 changes: 3 additions & 1 deletion BLAZAMActiveDirectory/Adapters/DirectoryEntryAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using System.Reflection;
using MudBlazor;
using System.DirectoryServices.ActiveDirectory;

namespace BLAZAM.ActiveDirectory.Adapters
{
Expand Down Expand Up @@ -855,7 +856,8 @@ private void FetchDirectoryEntry()
protected virtual List<T?> GetNonReplicatedProperty<T>(string propertyName)
{
var list = new List<T?>();
foreach (var dc in Directory.DomainControllers)
var dcs = new List<DomainController>(Directory.DomainControllers);
foreach (var dc in dcs)
{
try
{
Expand Down
3 changes: 3 additions & 0 deletions BLAZAMGui/BLAZAMGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
</ItemGroup>

<ItemGroup>
<Content Update="UI\Chat\EntrySpecificChat.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
<Content Update="UI\FlexContainer.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
Expand Down
3 changes: 3 additions & 0 deletions BLAZAMGui/Layouts/LoginLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
@if (monitor.DirectoryConnected == ServiceConnectionState.Connecting)
{
<MudProgressLinear Color="Color.Warning" Indeterminate=true />
<MudAlert Style="left:25px;right:25px;" Class="absolute mud-alert-filled-warning">Directory is connecting... Local admin login only...</MudAlert>

}

</div>
</Row>
</MudMainContent>
Expand Down
8 changes: 4 additions & 4 deletions BLAZAMGui/UI/Chat/AppChatRoom.razor
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
{
if (message.ChatRoomId == ChatRoom?.Id)
{
if (message.User != CurrentUser.State.Preferences)
{
//if (message.User != CurrentUser.State.Preferences)
//{
await Task.Delay(100);
//ChatRoom.Messages.Add(message);
ChatRoom.Messages.Add(message);
await InvokeAsync(StateHasChanged);

}
//}
ScrollToBottom();

}
Expand Down
153 changes: 153 additions & 0 deletions BLAZAMGui/UI/Chat/EntrySpecificChat.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
@inherits ChatComponentBase

<Audio Src="/audio/messagePop.mp3" @bind-Playing=@playingPop />
<Audio Src="/audio/bell.wav" @bind-Playing=@playingBell />
@if (AlwaysShowChatButton || ChatMessages!=null && ChatMessages.Count() > 0)
{
<ChatButton ChatRoom=ChatRoom OnClick="@(()=>{_chatOpen=!_chatOpen;})" />
}
@if (AlwaysShowPageViewersButton || (ShowPageViewersButton && Viewers.ContainsKey(ChatUri) && Viewers[ChatUri].Count > 1))
{
var otherViewers = Viewers[ChatUri].Where(us => !us.Equals(currentUserState));
<OtherViewersButton ChatRoom=ChatRoom
OnClick=@(()=>{_chatOpen=true;})
OtherViewers="otherViewers" />

}

<MudPopover Style="width:300px"
Open="@_chatOpen"
Fixed="true"
Class="px-1 pt-4">
<AppChatRoom
OnCloseClicked=@(()=>{_chatOpen=!_chatOpen;})
ChatRoom="ChatRoom" />
</MudPopover>

@code {

bool _chatOpen;
[Parameter]
public IDirectoryEntryAdapter? Entry { get; set; }
[Parameter]
public bool ShowPageViewersButton { get; set; } = true;
[Parameter]
public bool AlwaysShowChatButton { get; set; }
[Parameter]
public bool AlwaysShowPageViewersButton { get; set; }
IApplicationUserState currentUserState;

/// <summary>
/// A single system wide singleton static dictionary of every
/// viewer on every page this component is placed
/// </summary>
static Dictionary<string, List<IApplicationUserState>> Viewers = new Dictionary<string, List<IApplicationUserState>>();

delegate void CallbackEvent();
static CallbackEvent ViewersChanged;


bool playingPop;
bool playingBell;


public IEnumerable<ChatMessage> ChatMessages => ChatRoom?.Messages;
delegate void ChatMessageCallbackEvent(ChatMessage message);

protected override async Task OnInitializedAsync()
{

await base.OnInitializedAsync();


if (ChatUri.IsNullOrEmpty())
{


//ChatUri = Nav.ToBaseRelativePath(Nav.Uri);
ChatUri = Entry.DN;
Nav.LocationChanged += ((state, args) =>
{
if (Nav.ToBaseRelativePath(args.Location) != ChatUri)
{
RemoveThisViewer();
}
});
}
var chatRoom = Context.ChatRooms.Where(cr=>cr.Name.Equals(ChatUri)).FirstOrDefault();
if (chatRoom is null)
{
chatRoom = new() { CreatedAt = DateTime.Now, IsPublic = true, Name=ChatUri };
Chat.CreateChatRoom(chatRoom);

}
ChatRoom = chatRoom;

// await RefreshChatRooms();
//Setup other viewers button listeners
ViewersChanged += (async () =>
{
// await RefreshChatRooms();
await InvokeAsync(StateHasChanged);

});
currentUserState = CurrentUser.State;
AddThisViewer();




//Setup chat message listeners
Chat.OnMessagePosted += ((ChatMessage message) =>
{
if (message.User != currentUserState.Preferences)
{
if (_chatOpen && !playingPop)
{
playingPop = true;

}
else if (!_chatOpen && !playingBell)
{
playingBell = true;
}

InvokeAsync(StateHasChanged);
}
});


}



private void AddThisViewer()
{
if (!Viewers.ContainsKey(ChatUri))
Viewers.Add(ChatUri, new());

if (!Viewers[ChatUri].Contains(currentUserState))
{
Viewers[ChatUri].Add(currentUserState);
ViewersChanged?.Invoke();
}
}


private void RemoveThisViewer()
{
if (!Viewers.ContainsKey(ChatUri))
return;

if (Viewers[ChatUri].Contains(currentUserState))
{
Viewers[ChatUri].Remove(currentUserState);
ViewersChanged.Invoke();

}
}

}
19 changes: 11 additions & 8 deletions BLAZAMGui/UI/Chat/OtherViewersButton.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@


<MudBadge Color="Color.Info" Content="@OtherViewers.Count()" Overlap=true>
<MudMenu AnchorOrigin="@Origin.BottomLeft"
<MudMenu AnchorOrigin="@Origin.BottomRight"
TransformOrigin=Origin.TopRight
Icon="@Icons.Material.Filled.People">
@if (ChatRoom?.Messages.Count < 1)
{
<MudMenuItem IconSize=Size.Small
Icon="@Icons.Material.Filled.ChatBubble"
OnClick="@OnClick">
Icon="@Icons.Material.Filled.ChatBubble"
OnClick="@OnClick">
Start Chat
</MudMenuItem>
}
<MudText>Other Viewers:</MudText>
@foreach (var user in OtherViewers)
{
<MudText>@user.Username</MudText>
<MudList>
<MudListSubheader>Other Viewers:</MudListSubheader>
@foreach (var user in OtherViewers)
{
<MudListItem>@user.Username</MudListItem>

}
</MudList>

}
</MudMenu>
</MudBadge>
@code {
Expand Down
1 change: 1 addition & 0 deletions BLAZAMGui/UI/Chat/PageSpecificChat.razor
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
{
chatRoom = new() { CreatedAt = DateTime.Now, IsPublic = true, Name=ChatUri };
ChatRooms.Add(ChatUri,chatRoom);
await Context.SaveChangesAsync();
}
ChatRoom = chatRoom;

Expand Down
3 changes: 2 additions & 1 deletion BLAZAMGui/UI/DirectoryEntryViewHeader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
</MudToolBar>
</MudHidden>
<MudSpacer />
<PageSpecificChat />
@* <PageSpecificChat /> *@
<EntrySpecificChat Entry="DirectoryEntry"/>
<MudHidden Breakpoint="Breakpoint.SmAndUp">

<MudMenu Class="align-self-end" StartIcon="@Icons.Material.Filled.Settings">
Expand Down

0 comments on commit 28a8678

Please sign in to comment.