fix total user count in syncshell (distinct by UIDs)

This commit is contained in:
rootdarkarchon
2023-10-24 01:57:31 +02:00
parent 18d089d693
commit 82cca2e035
5 changed files with 17 additions and 13 deletions

View File

@@ -8,16 +8,16 @@ namespace MareSynchronos.UI.Components;
public abstract class DrawFolderBase : IDrawFolder
{
protected readonly IEnumerable<DrawUserPair> _drawPairs;
public IEnumerable<DrawUserPair> DrawPairs { get; private set; }
protected readonly string _id;
protected readonly TagHandler _tagHandler;
private float _menuWidth = -1;
public int OnlinePairs => _drawPairs.Count(u => u.Pair.IsOnline);
public int OnlinePairs => DrawPairs.Count(u => u.Pair.IsOnline);
public int TotalPairs { get; }
protected DrawFolderBase(string id, IEnumerable<DrawUserPair> drawPairs, TagHandler tagHandler, int totalPairs)
{
_id = id;
_drawPairs = drawPairs;
DrawPairs = drawPairs;
_tagHandler = tagHandler;
TotalPairs = totalPairs;
}
@@ -27,7 +27,7 @@ public abstract class DrawFolderBase : IDrawFolder
public void Draw()
{
if (!RenderIfEmpty && !_drawPairs.Any()) return;
if (!RenderIfEmpty && !DrawPairs.Any()) return;
using var id = ImRaii.PushId("folder_" + _id);
@@ -57,9 +57,9 @@ public abstract class DrawFolderBase : IDrawFolder
if (_tagHandler.IsTagOpen(_id))
{
using var indent = ImRaii.PushIndent(20f);
if (_drawPairs.Any())
if (DrawPairs.Any())
{
foreach (var item in _drawPairs)
foreach (var item in DrawPairs)
{
item.DrawPairedClient();
}

View File

@@ -98,7 +98,7 @@ public class DrawFolderGroup : DrawFolderBase
if (UiSharedService.IconTextButton(FontAwesomeIcon.StickyNote, "Copy Notes", menuWidth, true))
{
ImGui.CloseCurrentPopup();
ImGui.SetClipboardText(UiSharedService.GetNotes(_drawPairs.Select(k => k.Pair).ToList()));
ImGui.SetClipboardText(UiSharedService.GetNotes(DrawPairs.Select(k => k.Pair).ToList()));
}
UiSharedService.AttachToolTip("Copies all your notes for all users in this Syncshell to the clipboard." + Environment.NewLine + "They can be imported via Settings -> Privacy -> Import Notes from Clipboard");

View File

@@ -51,7 +51,7 @@ public class DrawFolderTag : DrawFolderBase
TagHandler.CustomAllTag => false,
TagHandler.CustomOfflineSyncshellTag => false,
_ => true,
} && _drawPairs.Any();
} && DrawPairs.Any();
private bool RenderCount => _id switch
{
@@ -135,7 +135,7 @@ public class DrawFolderTag : DrawFolderBase
{
if (!RenderPause) return currentRightSideX;
var allArePaused = _drawPairs.All(pair => pair.UserPair!.OwnPermissions.IsPaused());
var allArePaused = DrawPairs.All(pair => pair.UserPair!.OwnPermissions.IsPaused());
var pauseButton = allArePaused ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause;
var pauseButtonX = UiSharedService.GetIconButtonSize(pauseButton).X;
@@ -145,11 +145,11 @@ public class DrawFolderTag : DrawFolderBase
{
if (allArePaused)
{
ResumeAllPairs(_drawPairs);
ResumeAllPairs(DrawPairs);
}
else
{
PauseRemainingPairs(_drawPairs);
PauseRemainingPairs(DrawPairs);
}
}
if (allArePaused)

View File

@@ -9,7 +9,8 @@ public class DrawGroupedGroupFolder : IDrawFolder
{
private readonly IEnumerable<IDrawFolder> _groups;
private readonly TagHandler _tagHandler;
public int OnlinePairs => _groups.Sum(g => g.OnlinePairs);
public IEnumerable<DrawUserPair> DrawPairs => throw new NotSupportedException();
public int OnlinePairs => _groups.SelectMany(g => g.DrawPairs).Where(g => g.Pair.IsOnline).DistinctBy(g => g.UID).Count();
public int TotalPairs => _groups.Sum(g => g.TotalPairs);
public DrawGroupedGroupFolder(IEnumerable<IDrawFolder> groups, TagHandler tagHandler)

View File

@@ -1,8 +1,11 @@
namespace MareSynchronos.UI.Components;

namespace MareSynchronos.UI.Components;
public interface IDrawFolder
{
int TotalPairs { get; }
int OnlinePairs { get; }
IEnumerable<DrawUserPair> DrawPairs { get; }
void Draw();
}