Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeViper committed Nov 20, 2024
1 parent 1e490dd commit d4204bb
Show file tree
Hide file tree
Showing 75 changed files with 6,128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@code {

public static RenderFragment PlanetContent =>
@<div style="border: 1px solid black">
Planet
</div>;

public static RenderFragment CategoryContent =>
@<div style="border: 1px solid black">
Category
</div>;

public static RenderFragment ChatChannelContent =>
@<div style="border: 1px solid black">
Chat Channel
</div>;

public static RenderFragment VoiceChannelContent =>
@<div style="border: 1px solid black">
Voice Channel
</div>;

}
31 changes: 31 additions & 0 deletions Valour/Client/Components/PlanetsList/PlanetListItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Valour.Client.Components.Utility.DragList;
using Valour.Sdk.Models;
using Valour.Shared.Models;

namespace Valour.Client.Components.PlanetsList;

public class PlanetListItem : DragListItem
{
public Planet Planet { get; set; }

public override uint Depth => 0u;
public override uint Position => Planet.Name.FirstOrDefault();

public PlanetListItem(Planet planet)
{
Planet = planet;
}
}

public class ChannelListItem : DragListItem
{
public Channel Channel { get; set; }

public override uint Depth => Channel.Position.Depth;
public override uint Position => Channel.RawPosition;

public ChannelListItem(Channel channel)
{
Channel = channel;
}
}
63 changes: 63 additions & 0 deletions Valour/Client/Components/Utility/DragList/DragListComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@inherits ControlledRenderComponentBase

@{
if (_items is null)
{
return;
}

foreach (var item in _items)
{
<Virtualize Items="@_items" ItemSize="@ItemHeight">
<div style="height: @ItemHeight; max-height: @ItemHeight; margin-left: @(NestingMargin * @item.Depth)px">
@item.Content
</div>
</Virtualize>

}
}

@code {

[Parameter]
public float NestingMargin { get; set; } = 8f;

[Parameter]
public float ItemHeight { get; set; } = 24f;

// all items, sorted for render
private List<DragListItem> _items = new();

/// <summary>
/// Sets the items of this drag list. Note that changes to the list will
/// pass down (stored by reference) but you must manually trigger rebuilds.
/// </summary>
public void SetTopLevelItems(List<DragListItem> items)
{
_items = items;
}

/// <summary>
/// Orders,
/// </summary>
public void Rebuild(bool render = true)
{
OrderItems();

if (render)
{
ReRender();
}
}

// Orders the items for display
private void OrderItems()
{
if (_items is null || _items.Count == 0)
{
return;
}

_items.Sort(DragListItem.Compare);
}
}
55 changes: 55 additions & 0 deletions Valour/Client/Components/Utility/DragList/DragListItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Components;

namespace Valour.Client.Components.Utility.DragList;

public abstract class DragListItem
{
/// <summary>
/// The drag list this item belongs to
/// </summary>
public DragListComponent DragList { get; set; }

/// <summary>
/// True if this item can contain other items
/// </summary>
public bool Container { get; set; }

/// <summary>
/// True if this item is opened. Only applies to containers.
/// </summary>
public bool Open { get; set; }

/// <summary>
/// The amount of margin to apply to children. Only applies to containers.
/// </summary>
public int ChildMargin { get; set; }

public abstract uint Depth { get; }

public abstract uint Position { get; }

public virtual Task OnClick()
{
if (Container)
{
// Switch the open state
Open = !Open;

// Re-render drag list
DragList.ReRender();
}

return Task.CompletedTask;
}

/// <summary>
/// The content to render for this item
/// </summary>
public RenderFragment Content { get; set; }

public static int Compare(DragListItem a, DragListItem b)
{
// Compare position
return a.Position.CompareTo(b.Position);
}
}
14 changes: 14 additions & 0 deletions Valour/Client/Utility/ModelQueryEngineExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Components.Web.Virtualization;
using Valour.Sdk.ModelLogic;

namespace Valour.Client.Utility;

public static class ModelQueryEngineExtensions
{
public static async ValueTask<ItemsProviderResult<TModel>> GetVirtualizedItemsAsync<TModel>(this ModelQueryEngine<TModel> engine, ItemsProviderRequest request)
where TModel : ClientModel<TModel>
{
var queryData = await engine.GetItemsAsync(request.StartIndex, request.Count);
return new ItemsProviderResult<TModel>(queryData.Items, queryData.TotalCount);
}
}
1 change: 1 addition & 0 deletions Valour/Client/wwwroot/js/dayjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Valour/Client/wwwroot/js/dayjs.timezones.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Valour/Client/wwwroot/js/jquery-3.7.1.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Valour/Client/wwwroot/js/protoo-client.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Valour/Client/wwwroot/js/twemoji.min.js

Large diffs are not rendered by default.

Binary file added Valour/Client/wwwroot/media/logo/logo-128.webp
Binary file not shown.
Binary file added Valour/Client/wwwroot/media/logo/logo-256.webp
Binary file not shown.
Binary file added Valour/Client/wwwroot/media/logo/logo-512.webp
Binary file not shown.
Binary file added Valour/Client/wwwroot/media/logo/logo-64.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
63 changes: 63 additions & 0 deletions Valour/Database/Extensions/ChannelExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Runtime.CompilerServices;
using Valour.Shared.Models;

namespace Valour.Database.Extensions;

public static class ChannelExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IQueryable<Channel> InPlanet(this IQueryable<Channel> channels, long? planetId)
{
return channels.Where(x => x.PlanetId == planetId);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IQueryable<Channel> InParent(this IQueryable<Channel> channels, long? parentId)
{
return channels.Where(x => x.ParentId == parentId);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IQueryable<Channel> DirectChildrenOf(this IQueryable<Channel> channels, ISharedChannel channel)
{
return DirectChildrenOf(channels, channel.PlanetId, channel.RawPosition);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IQueryable<Channel> DirectChildrenOf(this IQueryable<Channel> channels, long? planetId, uint position)
{
// In this case we return nothing
if (planetId is null)
return channels.Where(x => false);

var depth = ChannelPosition.GetDepth(position);
var bounds = ChannelPosition.GetDescendentBounds(position, depth);
var directChildMask = ChannelPosition.GetDirectChildMaskByDepth(depth);

return channels.Where(x =>
x.PlanetId == planetId &&
x.RawPosition >= bounds.lower &&
x.RawPosition < bounds.upper &&
(x.RawPosition & directChildMask) == position);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IQueryable<Channel> DescendantsOf(this IQueryable<Channel> channels, ISharedChannel channel)
{
return DescendantsOf(channels, channel.PlanetId, channel.RawPosition);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static IQueryable<Channel> DescendantsOf(this IQueryable<Channel> channels, long? planetId, uint position)
{
// In this case we return nothing
if (planetId is null)
return channels.Where(x => false);

var bounds = ChannelPosition.GetDescendentBounds(position);
return channels.Where(x =>
x.PlanetId == planetId &&
x.RawPosition >= bounds.lower &&
x.RawPosition < bounds.upper);
}
}
83 changes: 83 additions & 0 deletions Valour/Sdk/Client/ModelCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Collections.Concurrent;
using Valour.Sdk.ModelLogic;
using Valour.Sdk.Services;

namespace Valour.Sdk.Client;

/* Valour (TM) - A free and secure chat client
* Copyright (C) 2024 Valour Software LLC
* This program is subject to the GNU Affero General Public license
* A copy of the license should be included - if not, see <http://www.gnu.org/licenses/>
*/

public class ModelCache<TModel, TId>
where TModel : ClientModel<TModel, TId>
where TId : IEquatable<TId>
{
private readonly ConcurrentDictionary<TId, TModel> _innerCache = new();

/// <summary>
/// Places an item into the cache. Returns if the item already exists and should be updated.
/// </summary>
public TModel Put(TId id, TModel model)
{
// Empty object is ignored
if (model is null)
return null;

if (!_innerCache.TryAdd(id, model)) // Fails if already exists
{
return _innerCache[id];
}

return null;
}

/// <summary>
/// Places an item into the cache, and replaces the item if it already exists
/// </summary>
public void PutReplace(TId id, TModel model)
{
_innerCache[id] = model;
}

/// <summary>
/// Returns true if the cache contains the item
/// </summary>
public bool Contains(TId id)
{
return _innerCache.ContainsKey(id);
}

/// <summary>
/// Returns all the items of the given type. You can use Linq functions like .Where on this function.
/// </summary>
public IEnumerable<TModel> GetAll()
{
return _innerCache.Values;
}


/// <summary>
/// Returns the item for the given id, or null if it does not exist
/// </summary>
public bool TryGet(TId id, out TModel model)
{
return _innerCache.TryGetValue(id, out model);
}

/// <summary>
/// Removes an item if present in the cache
/// </summary>
public void Remove(TId id)
{
_innerCache.TryRemove(id, out var _);
}

public TModel TakeAndRemove(TId id)
{
_innerCache.TryRemove(id, out var model);
return model;
}
}

Loading

0 comments on commit d4204bb

Please sign in to comment.