mirror of
				https://github.com/chylex/Discord-History-Tracker.git
				synced 2025-11-04 03:40:12 +01:00 
			
		
		
		
	Compare commits
	
		
			21 Commits
		
	
	
		
			app-json-2
			...
			8aeb590bb3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						8aeb590bb3
	
				 | 
					
					
						|||
| 
						
						
							
						
						8dc1adc9f0
	
				 | 
					
					
						|||
| 
						
						
							
						
						ddf70b02e7
	
				 | 
					
					
						|||
| 
						
						
							
						
						ef59fd992e
	
				 | 
					
					
						|||
| 
						
						
							
						
						d044627fac
	
				 | 
					
					
						|||
| a624745602 | |||
| 6da3c185e5 | |||
| 
						
						
							
						
						d4d14cab97
	
				 | 
					
					
						|||
| 
						
						
							
						
						095c9a061a
	
				 | 
					
					
						|||
| 
						
						
							
						
						d01f9ed218
	
				 | 
					
					
						|||
| 
						
						
							
						
						dd6f121059
	
				 | 
					
					
						|||
| 
						
						
							
						
						8bba33d815
	
				 | 
					
					
						|||
| 
						
						
							
						
						9eab8ac92a
	
				 | 
					
					
						|||
| 
						
						
							
						
						fe588686fc
	
				 | 
					
					
						|||
| 
						
						
							
						
						7392987165
	
				 | 
					
					
						|||
| 
						
						
							
						
						492dddb35d
	
				 | 
					
					
						|||
| 
						
						
							
						
						d35280a6a6
	
				 | 
					
					
						|||
| 
						
						
							
						
						ae8a34f938
	
				 | 
					
					
						|||
| 
						
						
							
						
						18f5823f2a
	
				 | 
					
					
						|||
| 
						
						
							
						
						37640c97b0
	
				 | 
					
					
						|||
| 
						
						
							
						
						3cc5c75c48
	
				 | 
					
					
						
							
								
								
									
										16
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								README.md
									
									
									
									
									
								
							@@ -16,7 +16,6 @@ Fork the repository and clone it to your computer (if you've never used git, you
 | 
			
		||||
 | 
			
		||||
Folder organization:
 | 
			
		||||
* `app/` contains a Visual Studio solution for the desktop app
 | 
			
		||||
* `lib/` contains utilities required to build the project
 | 
			
		||||
* `web/` contains source code of the [official website](https://dht.chylex.com), which can be used as a template when making your own website
 | 
			
		||||
 | 
			
		||||
To start editing source code for the desktop app, install the [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0), and then open `app/DiscordHistoryTracker.sln` in [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [Rider](https://www.jetbrains.com/rider/).
 | 
			
		||||
@@ -29,22 +28,13 @@ To build a `Release` version of the desktop app, follow the instructions for you
 | 
			
		||||
 | 
			
		||||
#### Release – Windows (64-bit)
 | 
			
		||||
 | 
			
		||||
1. Install [Python 3](https://www.python.org/downloads), and ensure the `python` executable is in your `PATH`
 | 
			
		||||
2. Install [Powershell 5](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows) or newer (on Windows 10, the included version of Powershell should be enough)
 | 
			
		||||
 | 
			
		||||
The `lib/` folder contains an installation of [Node](https://nodejs.org/en) and [uglify-js](https://www.npmjs.com/package/uglify-js), which are used to minify the tracking script. This installation will only work on 64-bit Windows; building on 32-bit Windows is not supported, but you can try.
 | 
			
		||||
1. Install [Powershell 5](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows) or newer (on Windows 10, the included version of Powershell should be enough)
 | 
			
		||||
 | 
			
		||||
Run the `app/build.bat` script, and read the [Distribution](#distribution) section below.
 | 
			
		||||
 | 
			
		||||
#### Release – Other Operating Systems
 | 
			
		||||
 | 
			
		||||
1. Install [Python 3](https://www.python.org/downloads), and ensure the `python` executable exists and launches Python 3
 | 
			
		||||
   - On Debian and derivatives, you can install `python-is-python3`
 | 
			
		||||
   - On other distributions, you can create a link manually, for ex. `ln -s /usr/bin/python3 /usr/bin/python`
 | 
			
		||||
   - If you don't want `python` to mean Python 3, then edit `Desktop.csproj` and change `python` to `python3`
 | 
			
		||||
2. Install [Node + npm](https://nodejs.org/en)
 | 
			
		||||
3. Install [uglify-js](https://www.npmjs.com/package/uglify-js) globally (`npm install -g uglify-js`)
 | 
			
		||||
4. Install the `zip` package from your repository
 | 
			
		||||
1. Install the `zip` package from your repository
 | 
			
		||||
 | 
			
		||||
Run the `app/build.sh` script, and read the [Distribution](#distribution) section below.
 | 
			
		||||
 | 
			
		||||
@@ -52,4 +42,4 @@ Run the `app/build.sh` script, and read the [Distribution](#distribution) sectio
 | 
			
		||||
 | 
			
		||||
The mentioned build scripts will prepare `Release` builds ready for distribution. Once the script finishes, the `app/bin` folder will contain self-contained executables for each major operating system, and a portable version that works on all other systems but requires .NET 8 to be installed.
 | 
			
		||||
 | 
			
		||||
Note that when building on Windows, the generated `.zip` files for Linux and Mac will not have correct file permissions, so it will not be possible to run them by double-clicking `DiscordHistoryTracker`. I tried using Python to re-create the archives with correct file permissions, but found that Linux `zip` tools could not see them. The only working solution is building the Windows + portable version on Windows, and Linux + Mac version on Linux.
 | 
			
		||||
Note that when building on Windows, the generated `.zip` files for Linux and Mac will not have correct file permissions, so it will not be possible to run them by double-clicking the executable. Since .NET 8 fixed several issues with publishing Windows executables on Linux, I recommend using Linux to build the app for all operating systems.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								app/.idea/.idea.DiscordHistoryTracker/.idea/avalonia.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								app/.idea/.idea.DiscordHistoryTracker/.idea/avalonia.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="AvaloniaProject">
 | 
			
		||||
    <option name="projectPerEditor">
 | 
			
		||||
      <map>
 | 
			
		||||
        <entry key="Desktop/App.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Dialogs/CheckBox/CheckBoxDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Dialogs/Message/MessageDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Dialogs/Progress/ProgressDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Dialogs/TextBox/TextBoxDialog.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/AboutWindow.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Controls/AttachmentFilterPanel.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Controls/MessageFilterPanel.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Controls/ServerConfigurationPanel.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Controls/StatusBar.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/MainWindow.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Pages/AdvancedPage.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Pages/AttachmentsPage.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Pages/DatabasePage.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Pages/DebugPage.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Pages/TrackingPage.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Pages/ViewerPage.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Screens/MainContentScreen.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
        <entry key="Desktop/Main/Screens/WelcomeScreen.axaml" value="Desktop/Desktop.csproj" />
 | 
			
		||||
      </map>
 | 
			
		||||
    </option>
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
@@ -29,9 +29,6 @@
 | 
			
		||||
    <H2CodeStyleSettings version="6">
 | 
			
		||||
      <option name="USE_GENERIC_STYLE" value="true" />
 | 
			
		||||
    </H2CodeStyleSettings>
 | 
			
		||||
    <H2CodeStyleSettings version="6">
 | 
			
		||||
      <option name="USE_GENERIC_STYLE" value="true" />
 | 
			
		||||
    </H2CodeStyleSettings>
 | 
			
		||||
    <HSQLCodeStyleSettings version="6">
 | 
			
		||||
      <option name="USE_GENERIC_STYLE" value="true" />
 | 
			
		||||
    </HSQLCodeStyleSettings>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
<component name="ProjectRunConfigurationManager">
 | 
			
		||||
  <configuration default="false" name="Desktop" type="DotNetProject" factoryName=".NET Project">
 | 
			
		||||
    <option name="EXE_PATH" value="$PROJECT_DIR$/Desktop/bin/Debug/net5.0/DiscordHistoryTracker.exe" />
 | 
			
		||||
    <option name="EXE_PATH" value="$PROJECT_DIR$/.artifacts/bin/Desktop/debug/DiscordHistoryTracker.exe" />
 | 
			
		||||
    <option name="PROGRAM_PARAMETERS" value="" />
 | 
			
		||||
    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Desktop/bin/Debug/net5.0" />
 | 
			
		||||
    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.artifacts/bin/Desktop/debug" />
 | 
			
		||||
    <option name="PASS_PARENT_ENVS" value="1" />
 | 
			
		||||
    <option name="USE_EXTERNAL_CONSOLE" value="0" />
 | 
			
		||||
    <option name="USE_MONO" value="0" />
 | 
			
		||||
@@ -12,7 +12,7 @@
 | 
			
		||||
    <option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
 | 
			
		||||
    <option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
 | 
			
		||||
    <option name="PROJECT_KIND" value="DotNetCore" />
 | 
			
		||||
    <option name="PROJECT_TFM" value="net5.0" />
 | 
			
		||||
    <option name="PROJECT_TFM" value="net8.0" />
 | 
			
		||||
    <method v="2">
 | 
			
		||||
      <option name="Build" />
 | 
			
		||||
    </method>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
<component name="ProjectRunConfigurationManager">
 | 
			
		||||
  <configuration default="false" name="Minify" type="PythonConfigurationType" factoryName="Python">
 | 
			
		||||
    <module name="rider.module" />
 | 
			
		||||
    <option name="INTERPRETER_OPTIONS" value="" />
 | 
			
		||||
    <option name="PARENT_ENVS" value="true" />
 | 
			
		||||
    <envs>
 | 
			
		||||
      <env name="PYTHONUNBUFFERED" value="1" />
 | 
			
		||||
    </envs>
 | 
			
		||||
    <option name="SDK_HOME" value="" />
 | 
			
		||||
    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
 | 
			
		||||
    <option name="IS_MODULE_SDK" value="false" />
 | 
			
		||||
    <option name="ADD_CONTENT_ROOTS" value="false" />
 | 
			
		||||
    <option name="ADD_SOURCE_ROOTS" value="false" />
 | 
			
		||||
    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/minify.py" />
 | 
			
		||||
    <option name="PARAMETERS" value="" />
 | 
			
		||||
    <option name="SHOW_COMMAND_LINE" value="false" />
 | 
			
		||||
    <option name="EMULATE_TERMINAL" value="false" />
 | 
			
		||||
    <option name="MODULE_MODE" value="false" />
 | 
			
		||||
    <option name="REDIRECT_INPUT" value="false" />
 | 
			
		||||
    <option name="INPUT_FILE" value="" />
 | 
			
		||||
    <method v="2" />
 | 
			
		||||
  </configuration>
 | 
			
		||||
</component>
 | 
			
		||||
@@ -1,8 +1,9 @@
 | 
			
		||||
<Application xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:common="clr-namespace:DHT.Desktop.Common"
 | 
			
		||||
             xmlns:system="clr-namespace:System;assembly=System.Runtime"
 | 
			
		||||
             xmlns:common="clr-namespace:DHT.Desktop.App.Common"
 | 
			
		||||
             x:Class="DHT.Desktop.App.App">
 | 
			
		||||
             x:Class="DHT.Desktop.App"
 | 
			
		||||
             RequestedThemeVariant="Light">
 | 
			
		||||
 | 
			
		||||
    <Application.Styles>
 | 
			
		||||
 | 
			
		||||
@@ -2,9 +2,9 @@ using System;
 | 
			
		||||
using Avalonia;
 | 
			
		||||
using Avalonia.Controls.ApplicationLifetimes;
 | 
			
		||||
using Avalonia.Markup.Xaml;
 | 
			
		||||
using DHT.Desktop.App.Windows;
 | 
			
		||||
using DHT.Desktop.Main;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App;
 | 
			
		||||
namespace DHT.Desktop;
 | 
			
		||||
 | 
			
		||||
sealed class App : Application {
 | 
			
		||||
	public override void Initialize() {
 | 
			
		||||
@@ -1,59 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Logging;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Pages; 
 | 
			
		||||
 | 
			
		||||
sealed class DatabasePageModel : BaseModel {
 | 
			
		||||
	private static readonly Log Log = Log.ForType<DatabasePageModel>();
 | 
			
		||||
 | 
			
		||||
	public IDatabaseFile Db { get; }
 | 
			
		||||
 | 
			
		||||
	public event EventHandler? DatabaseClosed;
 | 
			
		||||
 | 
			
		||||
	private readonly Window window;
 | 
			
		||||
 | 
			
		||||
	[Obsolete("Designer")]
 | 
			
		||||
	public DatabasePageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
	public DatabasePageModel(Window window, IDatabaseFile db) {
 | 
			
		||||
		this.window = window;
 | 
			
		||||
		this.Db = db;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void OpenDatabaseFolder() {
 | 
			
		||||
		string file = Db.Path;
 | 
			
		||||
		string? folder = Path.GetDirectoryName(file);
 | 
			
		||||
 | 
			
		||||
		if (folder == null) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		switch (Environment.OSVersion.Platform) {
 | 
			
		||||
			case PlatformID.Win32NT:
 | 
			
		||||
				Process.Start("explorer.exe", "/select,\"" + file + "\"");
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case PlatformID.Unix:
 | 
			
		||||
				Process.Start("xdg-open", new string[] { folder });
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case PlatformID.MacOSX:
 | 
			
		||||
				Process.Start("open", new string[] { folder });
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			default:
 | 
			
		||||
				await Dialog.ShowOk(window, "Feature Not Supported", "This feature is not supported for your operating system.");
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void CloseDatabase() {
 | 
			
		||||
		DatabaseClosed?.Invoke(this, EventArgs.Empty);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -2,7 +2,7 @@ using System;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using Avalonia.Data.Converters;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Common;
 | 
			
		||||
namespace DHT.Desktop.Common;
 | 
			
		||||
 | 
			
		||||
sealed class BytesValueConverter : IValueConverter {
 | 
			
		||||
	private sealed class Unit {
 | 
			
		||||
@@ -4,14 +4,14 @@ using System.IO;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Platform.Storage;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.File;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.File;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Database.Exceptions;
 | 
			
		||||
using DHT.Server.Database.Sqlite;
 | 
			
		||||
using DHT.Utils.Logging;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Common;
 | 
			
		||||
namespace DHT.Desktop.Common;
 | 
			
		||||
 | 
			
		||||
static class DatabaseGui {
 | 
			
		||||
	private static readonly Log Log = Log.ForType(typeof(DatabaseGui));
 | 
			
		||||
@@ -2,7 +2,7 @@ using System;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using Avalonia.Data.Converters;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Common;
 | 
			
		||||
namespace DHT.Desktop.Common;
 | 
			
		||||
 | 
			
		||||
sealed class NumberValueConverter : IValueConverter {
 | 
			
		||||
	public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
namespace DHT.Desktop.App.Common;
 | 
			
		||||
namespace DHT.Desktop.Common;
 | 
			
		||||
 | 
			
		||||
static class TextFormat {
 | 
			
		||||
	public static string Format(this int number) {
 | 
			
		||||
@@ -1,67 +1,44 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <RootNamespace>DHT.Desktop</RootNamespace>
 | 
			
		||||
    <AssemblyName>DiscordHistoryTracker</AssemblyName>
 | 
			
		||||
    <PackageId>DiscordHistoryTracker</PackageId>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <OutputType>WinExe</OutputType>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
    <AssemblyName>DiscordHistoryTracker</AssemblyName>
 | 
			
		||||
    <RootNamespace>DHT.Desktop</RootNamespace>
 | 
			
		||||
    <PackageId>DiscordHistoryTracker</PackageId>
 | 
			
		||||
    <Authors>chylex</Authors>
 | 
			
		||||
    <Company>DiscordHistoryTracker</Company>
 | 
			
		||||
    <Product>DiscordHistoryTracker</Product>
 | 
			
		||||
    <ApplicationIcon>./Resources/icon.ico</ApplicationIcon>
 | 
			
		||||
    <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
 | 
			
		||||
    <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
 | 
			
		||||
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
 | 
			
		||||
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
 | 
			
		||||
    <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <DebugType>none</DebugType>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Avalonia" Version="11.0.0" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.0" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.0" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Desktop" Version="11.0.0" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Diagnostics" Version="11.0.0" Condition=" '$(Configuration)' == 'Debug' " />
 | 
			
		||||
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.0" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0" />
 | 
			
		||||
    <PackageReference Include="Avalonia" Version="11.0.6" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.6" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.0.6" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Diagnostics" Version="11.0.6" Condition=" '$(Configuration)' == 'Debug' " />
 | 
			
		||||
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.6" />
 | 
			
		||||
    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.6" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ProjectReference Include="..\Server\Server.csproj" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Include="..\Version.cs" Link="Version.cs" />
 | 
			
		||||
    <Compile Update="App\App.axaml.cs">
 | 
			
		||||
      <DependentUpon>App.axaml</DependentUpon>
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Update="App\Windows\AboutWindow.axaml.cs">
 | 
			
		||||
      <DependentUpon>AboutWindow.axaml</DependentUpon>
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Update="App\Windows\MainWindow.axaml.cs">
 | 
			
		||||
      <DependentUpon>MainWindow.axaml</DependentUpon>
 | 
			
		||||
    <Compile Update="Dialogs\TextBox\TextBoxDialog.axaml.cs">
 | 
			
		||||
      <DependentUpon>CheckBoxDialog.axaml</DependentUpon>
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <AvaloniaResource Include="Resources/icon.ico" />
 | 
			
		||||
    <EmbeddedResource Include="../Resources/Tracker/bootstrap.js">
 | 
			
		||||
      <LogicalName>Tracker\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
			
		||||
      <Link>Resources/Tracker/%(RecursiveDir)%(Filename)%(Extension)</Link>
 | 
			
		||||
      <Visible>false</Visible>
 | 
			
		||||
    </EmbeddedResource>
 | 
			
		||||
    <EmbeddedResource Include="../Resources/Tracker/scripts/**" Condition=" '$(Configuration)' == 'Debug' ">
 | 
			
		||||
      <LogicalName>Tracker\scripts\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
			
		||||
      <Link>Resources/Tracker/scripts/%(RecursiveDir)%(Filename)%(Extension)</Link>
 | 
			
		||||
      <Visible>false</Visible>
 | 
			
		||||
    </EmbeddedResource>
 | 
			
		||||
    <EmbeddedResource Include="../Resources/Tracker/styles/**">
 | 
			
		||||
      <LogicalName>Tracker\styles\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
			
		||||
      <Link>Resources/Tracker/styles/%(RecursiveDir)%(Filename)%(Extension)</Link>
 | 
			
		||||
      <Visible>false</Visible>
 | 
			
		||||
    <EmbeddedResource Include="Resources/tracker-loader.js">
 | 
			
		||||
      <LogicalName>tracker-loader.js</LogicalName>
 | 
			
		||||
    </EmbeddedResource>
 | 
			
		||||
    <EmbeddedResource Include="../Resources/Viewer/**">
 | 
			
		||||
      <LogicalName>Viewer\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
 | 
			
		||||
@@ -69,39 +46,5 @@
 | 
			
		||||
      <Visible>false</Visible>
 | 
			
		||||
    </EmbeddedResource>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <AdditionalFiles Include="App\Controls\ServerConfigurationPanel.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Controls\StatusBar.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Dialogs\CheckBox\CheckBoxDialog.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Dialogs\Message\MessageDialog.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Dialogs\Progress\ProgressDialog.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Dialogs\TextBox\TextBoxDialog.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Pages\AdvancedPage.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Pages\DatabasePage.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Pages\TrackingPage.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Screens\MainContentScreen.axaml" />
 | 
			
		||||
    <AdditionalFiles Include="App\Screens\WelcomeScreen.axaml" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <UpToDateCheckInput Remove="Main\Pages\AdvancedPage.axaml" />
 | 
			
		||||
    <UpToDateCheckInput Remove="Main\Pages\DatabasePage.axaml" />
 | 
			
		||||
    <UpToDateCheckInput Remove="Main\Pages\TrackingPage.axaml" />
 | 
			
		||||
    <UpToDateCheckInput Remove="Main\Screens\MainContentScreen.axaml" />
 | 
			
		||||
    <UpToDateCheckInput Remove="Main\Screens\WelcomeScreen.axaml" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Target Name="MinifyResources" BeforeTargets="PrepareForBuild" Condition=" '$(Configuration)' == 'Release' ">
 | 
			
		||||
    <PropertyGroup>
 | 
			
		||||
      <MinifiedResourceDir>$(ProjectDir)bin/.res/scripts</MinifiedResourceDir>
 | 
			
		||||
    </PropertyGroup>
 | 
			
		||||
    <ItemGroup>
 | 
			
		||||
      <UpToDateCheckInput Include="$(ProjectDir)../Resources/Tracker/scripts/**" Visible="false" />
 | 
			
		||||
      <EmbeddedResource Include="$(MinifiedResourceDir)/discord.js" LogicalName="Tracker\scripts\discord.js" Visible="false" />
 | 
			
		||||
      <EmbeddedResource Include="$(MinifiedResourceDir)/dom.js" LogicalName="Tracker\scripts\dom.js" Visible="false" />
 | 
			
		||||
      <EmbeddedResource Include="$(MinifiedResourceDir)/gui.js" LogicalName="Tracker\scripts\gui.js" Visible="false" />
 | 
			
		||||
      <EmbeddedResource Include="$(MinifiedResourceDir)/settings.js" LogicalName="Tracker\scripts\settings.js" Visible="false" />
 | 
			
		||||
      <EmbeddedResource Include="$(MinifiedResourceDir)/state.js" LogicalName="Tracker\scripts\state.js" Visible="false" />
 | 
			
		||||
    </ItemGroup>
 | 
			
		||||
    <RemoveDir Directories="$(ProjectDir)bin/.res/scripts" />
 | 
			
		||||
    <Exec Command="python $(ProjectDir)../Resources/minify.py" WorkingDirectory="$(ProjectDir)../Resources" IgnoreExitCode="false" />
 | 
			
		||||
  </Target>
 | 
			
		||||
  
 | 
			
		||||
</Project>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,16 +2,16 @@
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:checkBox="clr-namespace:DHT.Desktop.App.Dialogs.CheckBox"
 | 
			
		||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.CheckBox"
 | 
			
		||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
			
		||||
        x:Class="DHT.Desktop.App.Dialogs.CheckBox.CheckBoxDialog"
 | 
			
		||||
        x:Class="DHT.Desktop.Dialogs.CheckBox.CheckBoxDialog"
 | 
			
		||||
        Title="{Binding Title}"
 | 
			
		||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
			
		||||
        Width="500" SizeToContent="Height" CanResize="False"
 | 
			
		||||
        WindowStartupLocation="CenterOwner">
 | 
			
		||||
 | 
			
		||||
    <Window.DataContext>
 | 
			
		||||
        <checkBox:CheckBoxDialogModel />
 | 
			
		||||
        <namespace:CheckBoxDialogModel />
 | 
			
		||||
    </Window.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Window.Styles>
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Interactivity;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.CheckBox;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.CheckBox;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class CheckBoxDialog : Window {
 | 
			
		||||
@@ -4,7 +4,7 @@ using System.ComponentModel;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.CheckBox;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.CheckBox;
 | 
			
		||||
 | 
			
		||||
class CheckBoxDialogModel : BaseModel {
 | 
			
		||||
	public string Title { get; init; } = "";
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.CheckBox;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.CheckBox;
 | 
			
		||||
 | 
			
		||||
class CheckBoxItem : BaseModel {
 | 
			
		||||
	public string Title { get; init; } = "";
 | 
			
		||||
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Platform.Storage;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.File;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.File;
 | 
			
		||||
 | 
			
		||||
static class FileDialogs {
 | 
			
		||||
	public static async Task<string[]> OpenFiles(this IStorageProvider storageProvider, FilePickerOpenOptions options) {
 | 
			
		||||
@@ -2,7 +2,7 @@ using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Threading;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Message;
 | 
			
		||||
 | 
			
		||||
static class Dialog {
 | 
			
		||||
	public static async Task ShowOk(Window owner, string title, string message) {
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Message;
 | 
			
		||||
 | 
			
		||||
static class DialogResult {
 | 
			
		||||
	public enum All {
 | 
			
		||||
@@ -2,16 +2,16 @@
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:message="clr-namespace:DHT.Desktop.App.Dialogs.Message"
 | 
			
		||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.Message"
 | 
			
		||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
			
		||||
        x:Class="DHT.Desktop.App.Dialogs.Message.MessageDialog"
 | 
			
		||||
        x:Class="DHT.Desktop.Dialogs.Message.MessageDialog"
 | 
			
		||||
        Title="{Binding Title}"
 | 
			
		||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
			
		||||
        Width="500" SizeToContent="Height" CanResize="False"
 | 
			
		||||
        WindowStartupLocation="CenterOwner">
 | 
			
		||||
 | 
			
		||||
    <Window.DataContext>
 | 
			
		||||
        <message:MessageDialogModel />
 | 
			
		||||
        <namespace:MessageDialogModel />
 | 
			
		||||
    </Window.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Window.Styles>
 | 
			
		||||
@@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Interactivity;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Message;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class MessageDialog : Window {
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Message;
 | 
			
		||||
 | 
			
		||||
sealed class MessageDialogModel {
 | 
			
		||||
	public string Title { get; init; } = "";
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Progress;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Progress;
 | 
			
		||||
 | 
			
		||||
interface IProgressCallback {
 | 
			
		||||
	Task Update(string message, int finishedItems, int totalItems);
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:progress="clr-namespace:DHT.Desktop.App.Dialogs.Progress"
 | 
			
		||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.Progress"
 | 
			
		||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
			
		||||
        x:Class="DHT.Desktop.App.Dialogs.Progress.ProgressDialog"
 | 
			
		||||
        x:Class="DHT.Desktop.Dialogs.Progress.ProgressDialog"
 | 
			
		||||
        Title="{Binding Title}"
 | 
			
		||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
			
		||||
        Opened="OnOpened"
 | 
			
		||||
@@ -13,7 +13,7 @@
 | 
			
		||||
        WindowStartupLocation="CenterOwner">
 | 
			
		||||
 | 
			
		||||
    <Window.DataContext>
 | 
			
		||||
        <progress:ProgressDialogModel />
 | 
			
		||||
        <namespace:ProgressDialogModel />
 | 
			
		||||
    </Window.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Window.Styles>
 | 
			
		||||
@@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Progress;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Progress;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class ProgressDialog : Window {
 | 
			
		||||
@@ -1,10 +1,10 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Threading;
 | 
			
		||||
using DHT.Desktop.App.Common;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.Progress;
 | 
			
		||||
namespace DHT.Desktop.Dialogs.Progress;
 | 
			
		||||
 | 
			
		||||
sealed class ProgressDialogModel : BaseModel {
 | 
			
		||||
	public string Title { get; init; } = "";
 | 
			
		||||
@@ -2,16 +2,16 @@
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:textBox="clr-namespace:DHT.Desktop.App.Dialogs.TextBox"
 | 
			
		||||
        xmlns:namespace="clr-namespace:DHT.Desktop.Dialogs.TextBox"
 | 
			
		||||
        mc:Ignorable="d" d:DesignWidth="500"
 | 
			
		||||
        x:Class="DHT.Desktop.App.Dialogs.TextBox.TextBoxDialog"
 | 
			
		||||
        x:Class="DHT.Desktop.Dialogs.TextBox.TextBoxDialog"
 | 
			
		||||
        Title="{Binding Title}"
 | 
			
		||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
			
		||||
        Width="500" SizeToContent="Height" CanResize="False"
 | 
			
		||||
        WindowStartupLocation="CenterOwner">
 | 
			
		||||
 | 
			
		||||
    <Window.DataContext>
 | 
			
		||||
        <textBox:TextBoxDialogModel />
 | 
			
		||||
        <namespace:TextBoxDialogModel />
 | 
			
		||||
    </Window.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Window.Styles>
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Interactivity;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.TextBox; 
 | 
			
		||||
namespace DHT.Desktop.Dialogs.TextBox; 
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class TextBoxDialog : Window {
 | 
			
		||||
@@ -4,7 +4,7 @@ using System.ComponentModel;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.TextBox; 
 | 
			
		||||
namespace DHT.Desktop.Dialogs.TextBox; 
 | 
			
		||||
 | 
			
		||||
class TextBoxDialogModel : BaseModel {
 | 
			
		||||
	public string Title { get; init; } = "";
 | 
			
		||||
@@ -3,7 +3,7 @@ using System.Collections;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Dialogs.TextBox; 
 | 
			
		||||
namespace DHT.Desktop.Dialogs.TextBox; 
 | 
			
		||||
 | 
			
		||||
class TextBoxItem : BaseModel, INotifyDataErrorInfo {
 | 
			
		||||
	public string Title { get; init; } = "";
 | 
			
		||||
@@ -40,7 +40,9 @@ static class DiscordAppSettings {
 | 
			
		||||
	public static async Task<bool?> AreDevToolsEnabled() {
 | 
			
		||||
		try {
 | 
			
		||||
			return AreDevToolsEnabled(await ReadSettingsJson());
 | 
			
		||||
		} catch (Exception) {
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			Log.Error("Cannot read settings file.");
 | 
			
		||||
			Log.Error(e);
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,16 +2,16 @@
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:windows="clr-namespace:DHT.Desktop.App.Windows"
 | 
			
		||||
        xmlns:main="clr-namespace:DHT.Desktop.Main"
 | 
			
		||||
        mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="295"
 | 
			
		||||
        x:Class="DHT.Desktop.App.Windows.AboutWindow"
 | 
			
		||||
        x:Class="DHT.Desktop.Main.AboutWindow"
 | 
			
		||||
        Title="About Discord History Tracker"
 | 
			
		||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
			
		||||
        Width="480" Height="295" CanResize="False"
 | 
			
		||||
        WindowStartupLocation="CenterOwner">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <windows:AboutWindowModel />
 | 
			
		||||
        <main:AboutWindowModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Window.Styles>
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Windows;
 | 
			
		||||
namespace DHT.Desktop.Main;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class AboutWindow : Window {
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Windows;
 | 
			
		||||
namespace DHT.Desktop.Main;
 | 
			
		||||
 | 
			
		||||
sealed class AboutWindowModel {
 | 
			
		||||
	public void ShowOfficialWebsite() {
 | 
			
		||||
							
								
								
									
										51
									
								
								app/Desktop/Main/Controls/AttachmentFilterPanel.axaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								app/Desktop/Main/Controls/AttachmentFilterPanel.axaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d"
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Controls.AttachmentFilterPanel">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <controls:AttachmentFilterPanelModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <UserControl.Styles>
 | 
			
		||||
        <Style Selector="WrapPanel > StackPanel">
 | 
			
		||||
            <Setter Property="Margin" Value="0 20 40 0" />
 | 
			
		||||
            <Setter Property="Spacing" Value="4" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="WrapPanel > StackPanel:nth-last-child(1)">
 | 
			
		||||
            <Setter Property="Margin" Value="0 20 0 0" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="Grid > Label">
 | 
			
		||||
            <Setter Property="VerticalAlignment" Value="Center" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="ComboBox">
 | 
			
		||||
            <Setter Property="Margin" Value="8 0 0 0" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="Button">
 | 
			
		||||
            <Setter Property="Margin" Value="0 0 0 8" />
 | 
			
		||||
        </Style>
 | 
			
		||||
    </UserControl.Styles>
 | 
			
		||||
 | 
			
		||||
    <StackPanel>
 | 
			
		||||
        <TextBlock Text="{Binding FilterStatisticsText}" />
 | 
			
		||||
        <WrapPanel>
 | 
			
		||||
            <StackPanel>
 | 
			
		||||
                <CheckBox IsChecked="{Binding LimitSize}">Limit Size</CheckBox>
 | 
			
		||||
                <StackPanel Orientation="Horizontal">
 | 
			
		||||
                    <TextBox Text="{Binding MaximumSize}" IsEnabled="{Binding LimitSize}" HorizontalContentAlignment="Right" />
 | 
			
		||||
                    <ComboBox IsEnabled="{Binding LimitSize}" ItemsSource="{Binding Units}" SelectedItem="{Binding MaximumSizeUnit}">
 | 
			
		||||
                        <ComboBox.ItemTemplate>
 | 
			
		||||
                            <DataTemplate>
 | 
			
		||||
                                <TextBlock Text="{Binding Name}" />
 | 
			
		||||
                            </DataTemplate>
 | 
			
		||||
                        </ComboBox.ItemTemplate>
 | 
			
		||||
                    </ComboBox>
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </WrapPanel>
 | 
			
		||||
    </StackPanel>
 | 
			
		||||
 | 
			
		||||
</UserControl>
 | 
			
		||||
							
								
								
									
										11
									
								
								app/Desktop/Main/Controls/AttachmentFilterPanel.axaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/Desktop/Main/Controls/AttachmentFilterPanel.axaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class AttachmentFilterPanel : UserControl {
 | 
			
		||||
	public AttachmentFilterPanel() {
 | 
			
		||||
		InitializeComponent();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										129
									
								
								app/Desktop/Main/Controls/AttachmentFilterPanelModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								app/Desktop/Main/Controls/AttachmentFilterPanelModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,129 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Server.Data.Filters;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
using DHT.Utils.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
sealed class AttachmentFilterPanelModel : BaseModel, IDisposable {
 | 
			
		||||
	public sealed record Unit(string Name, uint Scale);
 | 
			
		||||
 | 
			
		||||
	private static readonly Unit[] AllUnits = {
 | 
			
		||||
		new ("B", 1),
 | 
			
		||||
		new ("kB", 1024),
 | 
			
		||||
		new ("MB", 1024 * 1024)
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	private static readonly HashSet<string> FilterProperties = new () {
 | 
			
		||||
		nameof(LimitSize),
 | 
			
		||||
		nameof(MaximumSize),
 | 
			
		||||
		nameof(MaximumSizeUnit)
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	public string FilterStatisticsText { get; private set; } = "";
 | 
			
		||||
 | 
			
		||||
	private bool limitSize = false;
 | 
			
		||||
	private ulong maximumSize = 0L;
 | 
			
		||||
	private Unit maximumSizeUnit = AllUnits[0];
 | 
			
		||||
 | 
			
		||||
	public bool LimitSize {
 | 
			
		||||
		get => limitSize;
 | 
			
		||||
		set => Change(ref limitSize, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ulong MaximumSize {
 | 
			
		||||
		get => maximumSize;
 | 
			
		||||
		set => Change(ref maximumSize, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Unit MaximumSizeUnit {
 | 
			
		||||
		get => maximumSizeUnit;
 | 
			
		||||
		set => Change(ref maximumSizeUnit, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public IEnumerable<Unit> Units => AllUnits;
 | 
			
		||||
 | 
			
		||||
	private readonly IDatabaseFile db;
 | 
			
		||||
	private readonly string verb;
 | 
			
		||||
 | 
			
		||||
	private readonly AsyncValueComputer<long> matchingAttachmentCountComputer;
 | 
			
		||||
	private long? matchingAttachmentCount;
 | 
			
		||||
	private long? totalAttachmentCount;
 | 
			
		||||
 | 
			
		||||
	[Obsolete("Designer")]
 | 
			
		||||
	public AttachmentFilterPanelModel() : this(DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
	public AttachmentFilterPanelModel(IDatabaseFile db, string verb = "Matches") {
 | 
			
		||||
		this.db = db;
 | 
			
		||||
		this.verb = verb;
 | 
			
		||||
 | 
			
		||||
		this.matchingAttachmentCountComputer = AsyncValueComputer<long>.WithResultProcessor(SetAttachmentCounts).Build();
 | 
			
		||||
 | 
			
		||||
		UpdateFilterStatistics();
 | 
			
		||||
 | 
			
		||||
		PropertyChanged += OnPropertyChanged;
 | 
			
		||||
		db.Statistics.PropertyChanged += OnDbStatisticsChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose() {
 | 
			
		||||
		db.Statistics.PropertyChanged -= OnDbStatisticsChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) {
 | 
			
		||||
		if (e.PropertyName != null && FilterProperties.Contains(e.PropertyName)) {
 | 
			
		||||
			UpdateFilterStatistics();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
 | 
			
		||||
		if (e.PropertyName == nameof(DatabaseStatistics.TotalAttachments)) {
 | 
			
		||||
			totalAttachmentCount = db.Statistics.TotalAttachments;
 | 
			
		||||
			UpdateFilterStatistics();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateFilterStatistics() {
 | 
			
		||||
		var filter = CreateFilter();
 | 
			
		||||
		if (filter.IsEmpty) {
 | 
			
		||||
			matchingAttachmentCountComputer.Cancel();
 | 
			
		||||
			matchingAttachmentCount = totalAttachmentCount;
 | 
			
		||||
			UpdateFilterStatisticsText();
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			matchingAttachmentCount = null;
 | 
			
		||||
			UpdateFilterStatisticsText();
 | 
			
		||||
			matchingAttachmentCountComputer.Compute(() => db.CountAttachments(filter));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void SetAttachmentCounts(long matchingAttachmentCount) {
 | 
			
		||||
		this.matchingAttachmentCount = matchingAttachmentCount;
 | 
			
		||||
		UpdateFilterStatisticsText();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateFilterStatisticsText() {
 | 
			
		||||
		var matchingAttachmentCountStr = matchingAttachmentCount?.Format() ?? "(...)";
 | 
			
		||||
		var totalAttachmentCountStr = totalAttachmentCount?.Format() ?? "(...)";
 | 
			
		||||
 | 
			
		||||
		FilterStatisticsText = verb + " " + matchingAttachmentCountStr + " out of " + totalAttachmentCountStr + " attachment" + (totalAttachmentCount is null or 1 ? "." : "s.");
 | 
			
		||||
		OnPropertyChanged(nameof(FilterStatisticsText));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public AttachmentFilter CreateFilter() {
 | 
			
		||||
		AttachmentFilter filter = new();
 | 
			
		||||
 | 
			
		||||
		if (LimitSize) {
 | 
			
		||||
			try {
 | 
			
		||||
				filter.MaxBytes = maximumSize * maximumSizeUnit.Scale;
 | 
			
		||||
			} catch (ArithmeticException) {
 | 
			
		||||
				// set no size limit, because the overflown size is larger than any file could possibly be
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return filter;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										63
									
								
								app/Desktop/Main/Controls/MessageFilterPanel.axaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								app/Desktop/Main/Controls/MessageFilterPanel.axaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
			
		||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d"
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Controls.MessageFilterPanel">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <controls:MessageFilterPanelModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <UserControl.Styles>
 | 
			
		||||
        <Style Selector="WrapPanel > StackPanel">
 | 
			
		||||
            <Setter Property="Margin" Value="0 20 40 0" />
 | 
			
		||||
            <Setter Property="Spacing" Value="4" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="WrapPanel > StackPanel:nth-last-child(1)">
 | 
			
		||||
            <Setter Property="Margin" Value="0 20 0 0" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="Grid > Label">
 | 
			
		||||
            <Setter Property="VerticalAlignment" Value="Center" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="Grid > CalendarDatePicker">
 | 
			
		||||
            <Setter Property="CornerRadius" Value="0" />
 | 
			
		||||
            <Setter Property="HorizontalAlignment" Value="Stretch" />
 | 
			
		||||
            <Setter Property="HorizontalContentAlignment" Value="Center" />
 | 
			
		||||
            <Setter Property="VerticalAlignment" Value="Center" />
 | 
			
		||||
            <Setter Property="VerticalContentAlignment" Value="Center" />
 | 
			
		||||
            <Setter Property="IsTodayHighlighted" Value="True" />
 | 
			
		||||
            <Setter Property="SelectedDateFormat" Value="Short" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="Button">
 | 
			
		||||
            <Setter Property="Margin" Value="0 0 0 8" />
 | 
			
		||||
        </Style>
 | 
			
		||||
    </UserControl.Styles>
 | 
			
		||||
 | 
			
		||||
    <StackPanel>
 | 
			
		||||
        <TextBlock Text="{Binding FilterStatisticsText}" />
 | 
			
		||||
        <WrapPanel>
 | 
			
		||||
            <StackPanel>
 | 
			
		||||
                <CheckBox IsChecked="{Binding FilterByDate}">Filter by Date</CheckBox>
 | 
			
		||||
                <Grid ColumnDefinitions="Auto, 4, 125" RowDefinitions="Auto, 4, Auto" Margin="4 0">
 | 
			
		||||
                    <Label Grid.Row="0" Grid.Column="0">From:</Label>
 | 
			
		||||
                    <CalendarDatePicker Grid.Row="0" Grid.Column="2" x:Name="StartDatePicker" IsEnabled="{Binding FilterByDate}" SelectedDateChanged="CalendarDatePicker_OnSelectedDateChanged" />
 | 
			
		||||
                    <Label Grid.Row="2" Grid.Column="0">To:</Label>
 | 
			
		||||
                    <CalendarDatePicker Grid.Row="2" Grid.Column="2" x:Name="EndDatePicker" IsEnabled="{Binding FilterByDate}" SelectedDateChanged="CalendarDatePicker_OnSelectedDateChanged" />
 | 
			
		||||
                </Grid>
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
            <StackPanel>
 | 
			
		||||
                <CheckBox IsChecked="{Binding FilterByChannel}">Filter by Channel</CheckBox>
 | 
			
		||||
                <Button Command="{Binding OpenChannelFilterDialog}" IsEnabled="{Binding FilterByChannel}">Select Channels...</Button>
 | 
			
		||||
                <TextBlock Text="{Binding ChannelFilterLabel}" />
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
            <StackPanel>
 | 
			
		||||
                <CheckBox IsChecked="{Binding FilterByUser}">Filter by User</CheckBox>
 | 
			
		||||
                <Button Command="{Binding OpenUserFilterDialog}" IsEnabled="{Binding FilterByUser}">Select Users...</Button>
 | 
			
		||||
                <TextBlock Text="{Binding UserFilterLabel}" />
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </WrapPanel>
 | 
			
		||||
    </StackPanel>
 | 
			
		||||
 | 
			
		||||
</UserControl>
 | 
			
		||||
							
								
								
									
										26
									
								
								app/Desktop/Main/Controls/MessageFilterPanel.axaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/Desktop/Main/Controls/MessageFilterPanel.axaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class MessageFilterPanel : UserControl {
 | 
			
		||||
	public MessageFilterPanel() {
 | 
			
		||||
		InitializeComponent();
 | 
			
		||||
 | 
			
		||||
		var culture = Program.Culture;
 | 
			
		||||
		foreach (var picker in new CalendarDatePicker[] { StartDatePicker, EndDatePicker }) {
 | 
			
		||||
			picker.FirstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;
 | 
			
		||||
			picker.SelectedDateFormat = CalendarDatePickerFormat.Custom;
 | 
			
		||||
			picker.CustomDateFormatString = culture.DateTimeFormat.ShortDatePattern;
 | 
			
		||||
			picker.Watermark = culture.DateTimeFormat.ShortDatePattern;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void CalendarDatePicker_OnSelectedDateChanged(object? sender, SelectionChangedEventArgs e) {
 | 
			
		||||
		if (DataContext is MessageFilterPanelModel model) {
 | 
			
		||||
			model.StartDate = StartDatePicker.SelectedDate;
 | 
			
		||||
			model.EndDate = EndDatePicker.SelectedDate;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										285
									
								
								app/Desktop/Main/Controls/MessageFilterPanelModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										285
									
								
								app/Desktop/Main/Controls/MessageFilterPanelModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,285 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Desktop.Dialogs.CheckBox;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Server.Data;
 | 
			
		||||
using DHT.Server.Data.Filters;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
using DHT.Utils.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
sealed class MessageFilterPanelModel : BaseModel, IDisposable {
 | 
			
		||||
	private static readonly HashSet<string> FilterProperties = new () {
 | 
			
		||||
		nameof(FilterByDate),
 | 
			
		||||
		nameof(StartDate),
 | 
			
		||||
		nameof(EndDate),
 | 
			
		||||
		nameof(FilterByChannel),
 | 
			
		||||
		nameof(IncludedChannels),
 | 
			
		||||
		nameof(FilterByUser),
 | 
			
		||||
		nameof(IncludedUsers)
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	public string FilterStatisticsText { get; private set; } = "";
 | 
			
		||||
 | 
			
		||||
	public event PropertyChangedEventHandler? FilterPropertyChanged;
 | 
			
		||||
 | 
			
		||||
	public bool HasAnyFilters => FilterByDate || FilterByChannel || FilterByUser;
 | 
			
		||||
 | 
			
		||||
	private bool filterByDate = false;
 | 
			
		||||
	private DateTime? startDate = null;
 | 
			
		||||
	private DateTime? endDate = null;
 | 
			
		||||
	private bool filterByChannel = false;
 | 
			
		||||
	private HashSet<ulong>? includedChannels = null;
 | 
			
		||||
	private bool filterByUser = false;
 | 
			
		||||
	private HashSet<ulong>? includedUsers = null;
 | 
			
		||||
 | 
			
		||||
	public bool FilterByDate {
 | 
			
		||||
		get => filterByDate;
 | 
			
		||||
		set => Change(ref filterByDate, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DateTime? StartDate {
 | 
			
		||||
		get => startDate;
 | 
			
		||||
		set => Change(ref startDate, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DateTime? EndDate {
 | 
			
		||||
		get => endDate;
 | 
			
		||||
		set => Change(ref endDate, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool FilterByChannel {
 | 
			
		||||
		get => filterByChannel;
 | 
			
		||||
		set => Change(ref filterByChannel, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public HashSet<ulong> IncludedChannels {
 | 
			
		||||
		get => includedChannels ?? db.GetAllChannels().Select(static channel => channel.Id).ToHashSet();
 | 
			
		||||
		set => Change(ref includedChannels, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool FilterByUser {
 | 
			
		||||
		get => filterByUser;
 | 
			
		||||
		set => Change(ref filterByUser, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public HashSet<ulong> IncludedUsers {
 | 
			
		||||
		get => includedUsers ?? db.GetAllUsers().Select(static user => user.Id).ToHashSet();
 | 
			
		||||
		set => Change(ref includedUsers, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private string channelFilterLabel = "";
 | 
			
		||||
 | 
			
		||||
	public string ChannelFilterLabel {
 | 
			
		||||
		get => channelFilterLabel;
 | 
			
		||||
		set => Change(ref channelFilterLabel, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private string userFilterLabel = "";
 | 
			
		||||
 | 
			
		||||
	public string UserFilterLabel {
 | 
			
		||||
		get => userFilterLabel;
 | 
			
		||||
		set => Change(ref userFilterLabel, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private readonly Window window;
 | 
			
		||||
	private readonly IDatabaseFile db;
 | 
			
		||||
	private readonly string verb;
 | 
			
		||||
 | 
			
		||||
	private readonly AsyncValueComputer<long> exportedMessageCountComputer;
 | 
			
		||||
	private long? exportedMessageCount;
 | 
			
		||||
	private long? totalMessageCount;
 | 
			
		||||
 | 
			
		||||
	[Obsolete("Designer")]
 | 
			
		||||
	public MessageFilterPanelModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
	public MessageFilterPanelModel(Window window, IDatabaseFile db, string verb = "Matches") {
 | 
			
		||||
		this.window = window;
 | 
			
		||||
		this.db = db;
 | 
			
		||||
		this.verb = verb;
 | 
			
		||||
 | 
			
		||||
		this.exportedMessageCountComputer = AsyncValueComputer<long>.WithResultProcessor(SetExportedMessageCount).Build();
 | 
			
		||||
 | 
			
		||||
		UpdateFilterStatistics();
 | 
			
		||||
		UpdateChannelFilterLabel();
 | 
			
		||||
		UpdateUserFilterLabel();
 | 
			
		||||
 | 
			
		||||
		PropertyChanged += OnPropertyChanged;
 | 
			
		||||
		db.Statistics.PropertyChanged += OnDbStatisticsChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose() {
 | 
			
		||||
		db.Statistics.PropertyChanged -= OnDbStatisticsChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e) {
 | 
			
		||||
		if (e.PropertyName != null && FilterProperties.Contains(e.PropertyName)) {
 | 
			
		||||
			UpdateFilterStatistics();
 | 
			
		||||
			FilterPropertyChanged?.Invoke(sender, e);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (e.PropertyName is nameof(FilterByChannel) or nameof(IncludedChannels)) {
 | 
			
		||||
			UpdateChannelFilterLabel();
 | 
			
		||||
		}
 | 
			
		||||
		else if (e.PropertyName is nameof(FilterByUser) or nameof(IncludedUsers)) {
 | 
			
		||||
			UpdateUserFilterLabel();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
 | 
			
		||||
		if (e.PropertyName == nameof(DatabaseStatistics.TotalMessages)) {
 | 
			
		||||
			totalMessageCount = db.Statistics.TotalMessages;
 | 
			
		||||
			UpdateFilterStatistics();
 | 
			
		||||
		}
 | 
			
		||||
		else if (e.PropertyName == nameof(DatabaseStatistics.TotalChannels)) {
 | 
			
		||||
			UpdateChannelFilterLabel();
 | 
			
		||||
		}
 | 
			
		||||
		else if (e.PropertyName == nameof(DatabaseStatistics.TotalUsers)) {
 | 
			
		||||
			UpdateUserFilterLabel();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateFilterStatistics() {
 | 
			
		||||
		var filter = CreateFilter();
 | 
			
		||||
		if (filter.IsEmpty) {
 | 
			
		||||
			exportedMessageCountComputer.Cancel();
 | 
			
		||||
			exportedMessageCount = totalMessageCount;
 | 
			
		||||
			UpdateFilterStatisticsText();
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			exportedMessageCount = null;
 | 
			
		||||
			UpdateFilterStatisticsText();
 | 
			
		||||
			exportedMessageCountComputer.Compute(() => db.CountMessages(filter));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void SetExportedMessageCount(long exportedMessageCount) {
 | 
			
		||||
		this.exportedMessageCount = exportedMessageCount;
 | 
			
		||||
		UpdateFilterStatisticsText();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateFilterStatisticsText() {
 | 
			
		||||
		var exportedMessageCountStr = exportedMessageCount?.Format() ?? "(...)";
 | 
			
		||||
		var totalMessageCountStr = totalMessageCount?.Format() ?? "(...)";
 | 
			
		||||
 | 
			
		||||
		FilterStatisticsText = verb + " " + exportedMessageCountStr + " out of " + totalMessageCountStr + " message" + (totalMessageCount is null or 1 ? "." : "s.");
 | 
			
		||||
		OnPropertyChanged(nameof(FilterStatisticsText));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void OpenChannelFilterDialog() {
 | 
			
		||||
		var servers = db.GetAllServers().ToDictionary(static server => server.Id);
 | 
			
		||||
		var items = new List<CheckBoxItem<ulong>>();
 | 
			
		||||
		var included = IncludedChannels;
 | 
			
		||||
 | 
			
		||||
		foreach (var channel in db.GetAllChannels()) {
 | 
			
		||||
			var channelId = channel.Id;
 | 
			
		||||
			var channelName = channel.Name;
 | 
			
		||||
 | 
			
		||||
			string title;
 | 
			
		||||
			if (servers.TryGetValue(channel.Server, out var server)) {
 | 
			
		||||
				var titleBuilder = new StringBuilder();
 | 
			
		||||
				var serverType = server.Type;
 | 
			
		||||
 | 
			
		||||
				titleBuilder.Append('[')
 | 
			
		||||
				            .Append(ServerTypes.ToString(serverType))
 | 
			
		||||
				            .Append("] ");
 | 
			
		||||
 | 
			
		||||
				if (serverType == ServerType.DirectMessage) {
 | 
			
		||||
					titleBuilder.Append(channelName);
 | 
			
		||||
				}
 | 
			
		||||
				else {
 | 
			
		||||
					titleBuilder.Append(server.Name)
 | 
			
		||||
					            .Append(" - ")
 | 
			
		||||
					            .Append(channelName);
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				title = titleBuilder.ToString();
 | 
			
		||||
			}
 | 
			
		||||
			else {
 | 
			
		||||
				title = channelName;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			items.Add(new CheckBoxItem<ulong>(channelId) {
 | 
			
		||||
				Title = title,
 | 
			
		||||
				Checked = included.Contains(channelId)
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var result = await OpenIdFilterDialog(window, "Included Channels", items);
 | 
			
		||||
		if (result != null) {
 | 
			
		||||
			IncludedChannels = result;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void OpenUserFilterDialog() {
 | 
			
		||||
		var items = new List<CheckBoxItem<ulong>>();
 | 
			
		||||
		var included = IncludedUsers;
 | 
			
		||||
 | 
			
		||||
		foreach (var user in db.GetAllUsers()) {
 | 
			
		||||
			var name = user.Name;
 | 
			
		||||
			var discriminator = user.Discriminator;
 | 
			
		||||
 | 
			
		||||
			items.Add(new CheckBoxItem<ulong>(user.Id) {
 | 
			
		||||
				Title = discriminator == null ? name : name + " #" + discriminator,
 | 
			
		||||
				Checked = included.Contains(user.Id)
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var result = await OpenIdFilterDialog(window, "Included Users", items);
 | 
			
		||||
		if (result != null) {
 | 
			
		||||
			IncludedUsers = result;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateChannelFilterLabel() {
 | 
			
		||||
		long total = db.Statistics.TotalChannels;
 | 
			
		||||
		long included = FilterByChannel ? IncludedChannels.Count : total;
 | 
			
		||||
		ChannelFilterLabel = "Selected " + included.Format() + " / " + total.Pluralize("channel") + ".";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateUserFilterLabel() {
 | 
			
		||||
		long total = db.Statistics.TotalUsers;
 | 
			
		||||
		long included = FilterByUser ? IncludedUsers.Count : total;
 | 
			
		||||
		UserFilterLabel = "Selected " + included.Format() + " / " + total.Pluralize("user") + ".";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public MessageFilter CreateFilter() {
 | 
			
		||||
		MessageFilter filter = new();
 | 
			
		||||
 | 
			
		||||
		if (FilterByDate) {
 | 
			
		||||
			filter.StartDate = StartDate;
 | 
			
		||||
			filter.EndDate = EndDate?.AddDays(1).AddMilliseconds(-1);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (FilterByChannel) {
 | 
			
		||||
			filter.ChannelIds = new HashSet<ulong>(IncludedChannels);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (FilterByUser) {
 | 
			
		||||
			filter.UserIds = new HashSet<ulong>(IncludedUsers);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return filter;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static async Task<HashSet<ulong>?> OpenIdFilterDialog(Window window, string title, List<CheckBoxItem<ulong>> items) {
 | 
			
		||||
		items.Sort(static (item1, item2) => item1.Title.CompareTo(item2.Title));
 | 
			
		||||
 | 
			
		||||
		var model = new CheckBoxDialogModel<ulong>(items) {
 | 
			
		||||
			Title = title
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		var dialog = new CheckBoxDialog { DataContext = model };
 | 
			
		||||
		var result = await dialog.ShowDialog<DialogResult.OkCancel>(window);
 | 
			
		||||
 | 
			
		||||
		return result == DialogResult.OkCancel.Ok ? model.SelectedItems.Select(static item => item.Item).ToHashSet() : null;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Controls.ServerConfigurationPanel">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Controls.ServerConfigurationPanel">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <controls:ServerConfigurationPanelModel />
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Controls;
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class ServerConfigurationPanel : UserControl {
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Server;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Service;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Controls;
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
sealed class ServerConfigurationPanelModel : BaseModel, IDisposable {
 | 
			
		||||
	private string inputPort;
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Controls.StatusBar">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Controls.StatusBar">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <controls:StatusBarModel />
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Controls;
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class StatusBar : UserControl {
 | 
			
		||||
@@ -1,8 +1,12 @@
 | 
			
		||||
using System;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Controls;
 | 
			
		||||
namespace DHT.Desktop.Main.Controls;
 | 
			
		||||
 | 
			
		||||
sealed class StatusBarModel : BaseModel {
 | 
			
		||||
	public DatabaseStatistics DatabaseStatistics { get; }
 | 
			
		||||
 | 
			
		||||
	private Status status = Status.Stopped;
 | 
			
		||||
 | 
			
		||||
	public Status CurrentStatus {
 | 
			
		||||
@@ -25,6 +29,13 @@ sealed class StatusBarModel : BaseModel {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	[Obsolete("Designer")]
 | 
			
		||||
	public StatusBarModel() : this(new DatabaseStatistics()) {}
 | 
			
		||||
 | 
			
		||||
	public StatusBarModel(DatabaseStatistics databaseStatistics) {
 | 
			
		||||
		this.DatabaseStatistics = databaseStatistics;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public enum Status {
 | 
			
		||||
		Starting,
 | 
			
		||||
		Ready,
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
        xmlns:windows="clr-namespace:DHT.Desktop.App.Windows"
 | 
			
		||||
        xmlns:main="clr-namespace:DHT.Desktop.Main"
 | 
			
		||||
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
        x:Class="DHT.Desktop.App.Windows.MainWindow"
 | 
			
		||||
        x:Class="DHT.Desktop.Main.MainWindow"
 | 
			
		||||
        Title="{Binding Title}"
 | 
			
		||||
        Icon="avares://DiscordHistoryTracker/Resources/icon.ico"
 | 
			
		||||
        Width="800" Height="500"
 | 
			
		||||
@@ -13,7 +13,7 @@
 | 
			
		||||
        Closed="OnClosed">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <windows:MainWindowModel />
 | 
			
		||||
        <main:MainWindowModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <Panel>
 | 
			
		||||
@@ -1,9 +1,11 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.Main.Pages;
 | 
			
		||||
using JetBrains.Annotations;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Windows;
 | 
			
		||||
namespace DHT.Desktop.Main;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class MainWindow : Window {
 | 
			
		||||
@@ -22,5 +24,13 @@ public sealed partial class MainWindow : Window {
 | 
			
		||||
		if (DataContext is IDisposable disposable) {
 | 
			
		||||
			disposable.Dispose();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		foreach (var temporaryFile in ViewerPageModel.TemporaryFiles) {
 | 
			
		||||
			try {
 | 
			
		||||
				File.Delete(temporaryFile);
 | 
			
		||||
			} catch (Exception) {
 | 
			
		||||
				// ignored
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -4,13 +4,13 @@ using System.IO;
 | 
			
		||||
using System.Runtime.InteropServices;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.App.Screens;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Main.Screens;
 | 
			
		||||
using DHT.Desktop.Server;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Windows;
 | 
			
		||||
namespace DHT.Desktop.Main;
 | 
			
		||||
 | 
			
		||||
sealed class MainWindowModel : BaseModel, IDisposable {
 | 
			
		||||
	private const string DefaultTitle = "Discord History Tracker";
 | 
			
		||||
@@ -2,10 +2,10 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.App.Pages"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Pages.AdvancedPage">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Pages.AdvancedPage">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <pages:AdvancedPageModel />
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Pages;
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class AdvancedPage : UserControl {
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
using System;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Controls;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Main.Controls;
 | 
			
		||||
using DHT.Desktop.Server;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Pages;
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
sealed class AdvancedPageModel : BaseModel, IDisposable {
 | 
			
		||||
	public ServerConfigurationPanelModel ServerConfigurationModel { get; }
 | 
			
		||||
							
								
								
									
										54
									
								
								app/Desktop/Main/Pages/AttachmentsPage.axaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								app/Desktop/Main/Pages/AttachmentsPage.axaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,54 @@
 | 
			
		||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Pages.AttachmentsPage">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <pages:AttachmentsPageModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <UserControl.Styles>
 | 
			
		||||
        <Style Selector="Expander">
 | 
			
		||||
            <Setter Property="Margin" Value="0 5 0 0" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="DataGridColumnHeader">
 | 
			
		||||
            <Setter Property="FontWeight" Value="Medium" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="DataGridColumnHeader:nth-child(2)">
 | 
			
		||||
            <Setter Property="HorizontalContentAlignment" Value="Right" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="DataGridColumnHeader:nth-child(3)">
 | 
			
		||||
            <Setter Property="HorizontalContentAlignment" Value="Right" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="DataGridCell.right">
 | 
			
		||||
            <Setter Property="HorizontalContentAlignment" Value="Right" />
 | 
			
		||||
        </Style>
 | 
			
		||||
    </UserControl.Styles>
 | 
			
		||||
 | 
			
		||||
    <StackPanel Orientation="Vertical" Spacing="20">
 | 
			
		||||
        <DockPanel>
 | 
			
		||||
            <Button Command="{Binding OnClickToggleDownload}" Content="{Binding ToggleDownloadButtonText}" IsEnabled="{Binding IsToggleDownloadButtonEnabled}" DockPanel.Dock="Left" />
 | 
			
		||||
            <TextBlock Text="{Binding DownloadMessage}" Margin="10 0 0 0" VerticalAlignment="Center" DockPanel.Dock="Left" />
 | 
			
		||||
            <ProgressBar Value="{Binding DownloadProgress}" IsVisible="{Binding IsDownloading}" Margin="15 0" VerticalAlignment="Center" DockPanel.Dock="Right" />
 | 
			
		||||
        </DockPanel>
 | 
			
		||||
        <controls:AttachmentFilterPanel DataContext="{Binding FilterModel}" IsEnabled="{Binding !DataContext.IsDownloading, RelativeSource={RelativeSource AncestorType=UserControl}}" />
 | 
			
		||||
        <StackPanel Orientation="Vertical" Spacing="12">
 | 
			
		||||
            <Expander Header="Download Status" IsExpanded="True">
 | 
			
		||||
                <DataGrid ItemsSource="{Binding StatisticsRows}" AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" IsReadOnly="True">
 | 
			
		||||
                    <DataGrid.Columns>
 | 
			
		||||
                        <DataGridTextColumn Header="State" Binding="{Binding State}" Width="*" />
 | 
			
		||||
                        <DataGridTextColumn Header="Attachments" Binding="{Binding Items, Converter={StaticResource NumberValueConverter}}" Width="*" CellStyleClasses="right" />
 | 
			
		||||
                        <DataGridTextColumn Header="Size" Binding="{Binding Size, Converter={StaticResource BytesValueConverter}}" Width="*" CellStyleClasses="right" />
 | 
			
		||||
                    </DataGrid.Columns>
 | 
			
		||||
                </DataGrid>
 | 
			
		||||
            </Expander>
 | 
			
		||||
            <StackPanel Orientation="Horizontal" Spacing="10">
 | 
			
		||||
                <Button Command="{Binding OnClickRetryFailedDownloads}" IsEnabled="{Binding HasFailedDownloads}">Retry Failed Downloads</Button>
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
    </StackPanel>
 | 
			
		||||
</UserControl>
 | 
			
		||||
							
								
								
									
										11
									
								
								app/Desktop/Main/Pages/AttachmentsPage.axaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/Desktop/Main/Pages/AttachmentsPage.axaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class AttachmentsPage : UserControl {
 | 
			
		||||
	public AttachmentsPage() {
 | 
			
		||||
		InitializeComponent();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										205
									
								
								app/Desktop/Main/Pages/AttachmentsPageModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										205
									
								
								app/Desktop/Main/Pages/AttachmentsPageModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,205 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using Avalonia.Threading;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Desktop.Main.Controls;
 | 
			
		||||
using DHT.Server.Data;
 | 
			
		||||
using DHT.Server.Data.Aggregations;
 | 
			
		||||
using DHT.Server.Data.Filters;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Download;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
using DHT.Utils.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
sealed class AttachmentsPageModel : BaseModel, IDisposable {
 | 
			
		||||
	private static readonly DownloadItemFilter EnqueuedItemFilter = new() {
 | 
			
		||||
		IncludeStatuses = new HashSet<DownloadStatus> {
 | 
			
		||||
			DownloadStatus.Enqueued
 | 
			
		||||
		}
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	private bool isThreadDownloadButtonEnabled = true;
 | 
			
		||||
 | 
			
		||||
	public string ToggleDownloadButtonText => downloadThread == null ? "Start Downloading" : "Stop Downloading";
 | 
			
		||||
 | 
			
		||||
	public bool IsToggleDownloadButtonEnabled {
 | 
			
		||||
		get => isThreadDownloadButtonEnabled;
 | 
			
		||||
		set => Change(ref isThreadDownloadButtonEnabled, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public string DownloadMessage { get; set; } = "";
 | 
			
		||||
	public double DownloadProgress => allItemsCount is null or 0 ? 0.0 : 100.0 * doneItemsCount / allItemsCount.Value;
 | 
			
		||||
 | 
			
		||||
	public AttachmentFilterPanelModel FilterModel { get; }
 | 
			
		||||
 | 
			
		||||
	private readonly StatisticsRow statisticsEnqueued = new ("Enqueued");
 | 
			
		||||
	private readonly StatisticsRow statisticsDownloaded = new ("Downloaded");
 | 
			
		||||
	private readonly StatisticsRow statisticsFailed = new ("Failed");
 | 
			
		||||
	private readonly StatisticsRow statisticsSkipped = new ("Skipped");
 | 
			
		||||
 | 
			
		||||
	public List<StatisticsRow> StatisticsRows {
 | 
			
		||||
		get {
 | 
			
		||||
			return new List<StatisticsRow> {
 | 
			
		||||
				statisticsEnqueued,
 | 
			
		||||
				statisticsDownloaded,
 | 
			
		||||
				statisticsFailed,
 | 
			
		||||
				statisticsSkipped
 | 
			
		||||
			};
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public bool IsDownloading => downloadThread != null;
 | 
			
		||||
	public bool HasFailedDownloads => statisticsFailed.Items > 0;
 | 
			
		||||
 | 
			
		||||
	private readonly IDatabaseFile db;
 | 
			
		||||
	private readonly AsyncValueComputer<DownloadStatusStatistics>.Single downloadStatisticsComputer;
 | 
			
		||||
	private BackgroundDownloadThread? downloadThread;
 | 
			
		||||
 | 
			
		||||
	private int doneItemsCount;
 | 
			
		||||
	private int? allItemsCount;
 | 
			
		||||
 | 
			
		||||
	public AttachmentsPageModel() : this(DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
	public AttachmentsPageModel(IDatabaseFile db) {
 | 
			
		||||
		this.db = db;
 | 
			
		||||
		this.FilterModel = new AttachmentFilterPanelModel(db);
 | 
			
		||||
 | 
			
		||||
		this.downloadStatisticsComputer = AsyncValueComputer<DownloadStatusStatistics>.WithResultProcessor(UpdateStatistics).WithOutdatedResults().BuildWithComputer(db.GetDownloadStatusStatistics);
 | 
			
		||||
		this.downloadStatisticsComputer.Recompute();
 | 
			
		||||
 | 
			
		||||
		db.Statistics.PropertyChanged += OnDbStatisticsChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose() {
 | 
			
		||||
		db.Statistics.PropertyChanged -= OnDbStatisticsChanged;
 | 
			
		||||
 | 
			
		||||
		FilterModel.Dispose();
 | 
			
		||||
		DisposeDownloadThread();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnDbStatisticsChanged(object? sender, PropertyChangedEventArgs e) {
 | 
			
		||||
		if (e.PropertyName == nameof(DatabaseStatistics.TotalAttachments)) {
 | 
			
		||||
			if (IsDownloading) {
 | 
			
		||||
				EnqueueDownloadItems();
 | 
			
		||||
			}
 | 
			
		||||
			else {
 | 
			
		||||
				downloadStatisticsComputer.Recompute();
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else if (e.PropertyName == nameof(DatabaseStatistics.TotalDownloads)) {
 | 
			
		||||
			downloadStatisticsComputer.Recompute();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void EnqueueDownloadItems() {
 | 
			
		||||
		var filter = FilterModel.CreateFilter();
 | 
			
		||||
		filter.DownloadItemRule = AttachmentFilter.DownloadItemRules.OnlyNotPresent;
 | 
			
		||||
		db.EnqueueDownloadItems(filter);
 | 
			
		||||
 | 
			
		||||
		downloadStatisticsComputer.Recompute();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateStatistics(DownloadStatusStatistics statusStatistics) {
 | 
			
		||||
		var hadFailedDownloads = HasFailedDownloads;
 | 
			
		||||
 | 
			
		||||
		statisticsEnqueued.Items = statusStatistics.EnqueuedCount;
 | 
			
		||||
		statisticsEnqueued.Size = statusStatistics.EnqueuedSize;
 | 
			
		||||
 | 
			
		||||
		statisticsDownloaded.Items = statusStatistics.SuccessfulCount;
 | 
			
		||||
		statisticsDownloaded.Size = statusStatistics.SuccessfulSize;
 | 
			
		||||
 | 
			
		||||
		statisticsFailed.Items = statusStatistics.FailedCount;
 | 
			
		||||
		statisticsFailed.Size = statusStatistics.FailedSize;
 | 
			
		||||
 | 
			
		||||
		statisticsSkipped.Items = statusStatistics.SkippedCount;
 | 
			
		||||
		statisticsSkipped.Size = statusStatistics.SkippedSize;
 | 
			
		||||
 | 
			
		||||
		OnPropertyChanged(nameof(StatisticsRows));
 | 
			
		||||
 | 
			
		||||
		if (hadFailedDownloads != HasFailedDownloads) {
 | 
			
		||||
			OnPropertyChanged(nameof(HasFailedDownloads));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		allItemsCount = doneItemsCount + statisticsEnqueued.Items;
 | 
			
		||||
		UpdateDownloadMessage();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void UpdateDownloadMessage() {
 | 
			
		||||
		DownloadMessage = IsDownloading ? doneItemsCount.Format() + " / " + (allItemsCount?.Format() ?? "?") : "";
 | 
			
		||||
 | 
			
		||||
		OnPropertyChanged(nameof(DownloadMessage));
 | 
			
		||||
		OnPropertyChanged(nameof(DownloadProgress));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void DownloadThreadOnOnItemFinished(object? sender, DownloadItem e) {
 | 
			
		||||
		Interlocked.Increment(ref doneItemsCount);
 | 
			
		||||
 | 
			
		||||
		Dispatcher.UIThread.Invoke(UpdateDownloadMessage);
 | 
			
		||||
		downloadStatisticsComputer.Recompute();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void DownloadThreadOnOnServerStopped(object? sender, EventArgs e) {
 | 
			
		||||
		downloadStatisticsComputer.Recompute();
 | 
			
		||||
		IsToggleDownloadButtonEnabled = true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void OnClickToggleDownload() {
 | 
			
		||||
		if (downloadThread == null) {
 | 
			
		||||
			EnqueueDownloadItems();
 | 
			
		||||
			downloadThread = new BackgroundDownloadThread(db);
 | 
			
		||||
			downloadThread.OnItemFinished += DownloadThreadOnOnItemFinished;
 | 
			
		||||
			downloadThread.OnServerStopped += DownloadThreadOnOnServerStopped;
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			IsToggleDownloadButtonEnabled = false;
 | 
			
		||||
			DisposeDownloadThread();
 | 
			
		||||
 | 
			
		||||
			db.RemoveDownloadItems(EnqueuedItemFilter, FilterRemovalMode.RemoveMatching);
 | 
			
		||||
 | 
			
		||||
			doneItemsCount = 0;
 | 
			
		||||
			allItemsCount = null;
 | 
			
		||||
			UpdateDownloadMessage();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		OnPropertyChanged(nameof(ToggleDownloadButtonText));
 | 
			
		||||
		OnPropertyChanged(nameof(IsDownloading));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void OnClickRetryFailedDownloads() {
 | 
			
		||||
		var allExceptFailedFilter = new DownloadItemFilter {
 | 
			
		||||
			IncludeStatuses = new HashSet<DownloadStatus> {
 | 
			
		||||
				DownloadStatus.Enqueued,
 | 
			
		||||
				DownloadStatus.Success
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		db.RemoveDownloadItems(allExceptFailedFilter, FilterRemovalMode.KeepMatching);
 | 
			
		||||
 | 
			
		||||
		if (IsDownloading) {
 | 
			
		||||
			EnqueueDownloadItems();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void DisposeDownloadThread() {
 | 
			
		||||
		if (downloadThread != null) {
 | 
			
		||||
			downloadThread.OnItemFinished -= DownloadThreadOnOnItemFinished;
 | 
			
		||||
			downloadThread.StopThread();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		downloadThread = null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public sealed class StatisticsRow {
 | 
			
		||||
		public string State { get; }
 | 
			
		||||
		public int Items { get; set; }
 | 
			
		||||
		public ulong? Size { get; set; }
 | 
			
		||||
 | 
			
		||||
		public StatisticsRow(string state) {
 | 
			
		||||
			State = state;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.App.Pages"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Pages.DatabasePage">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Pages.DatabasePage">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <pages:DatabasePageModel />
 | 
			
		||||
@@ -23,6 +23,8 @@
 | 
			
		||||
        </DockPanel>
 | 
			
		||||
        <WrapPanel>
 | 
			
		||||
            <Button Command="{Binding OpenDatabaseFolder}">Open Database Folder</Button>
 | 
			
		||||
            <Button Command="{Binding MergeWithDatabase}">Merge with Database(s)...</Button>
 | 
			
		||||
            <Button Command="{Binding ImportLegacyArchive}">Import Legacy Archive(s)...</Button>
 | 
			
		||||
        </WrapPanel>
 | 
			
		||||
    </StackPanel>
 | 
			
		||||
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Pages;
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class DatabasePage : UserControl {
 | 
			
		||||
							
								
								
									
										245
									
								
								app/Desktop/Main/Pages/DatabasePageModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										245
									
								
								app/Desktop/Main/Pages/DatabasePageModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,245 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Platform.Storage;
 | 
			
		||||
using Avalonia.Threading;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Desktop.Dialogs.File;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Progress;
 | 
			
		||||
using DHT.Desktop.Dialogs.TextBox;
 | 
			
		||||
using DHT.Server.Data;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Database.Import;
 | 
			
		||||
using DHT.Utils.Logging;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages; 
 | 
			
		||||
 | 
			
		||||
sealed class DatabasePageModel : BaseModel {
 | 
			
		||||
	private static readonly Log Log = Log.ForType<DatabasePageModel>();
 | 
			
		||||
 | 
			
		||||
	public IDatabaseFile Db { get; }
 | 
			
		||||
 | 
			
		||||
	public event EventHandler? DatabaseClosed;
 | 
			
		||||
 | 
			
		||||
	private readonly Window window;
 | 
			
		||||
 | 
			
		||||
	[Obsolete("Designer")]
 | 
			
		||||
	public DatabasePageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
	public DatabasePageModel(Window window, IDatabaseFile db) {
 | 
			
		||||
		this.window = window;
 | 
			
		||||
		this.Db = db;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void OpenDatabaseFolder() {
 | 
			
		||||
		string file = Db.Path;
 | 
			
		||||
		string? folder = Path.GetDirectoryName(file);
 | 
			
		||||
 | 
			
		||||
		if (folder == null) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		switch (Environment.OSVersion.Platform) {
 | 
			
		||||
			case PlatformID.Win32NT:
 | 
			
		||||
				Process.Start("explorer.exe", "/select,\"" + file + "\"");
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case PlatformID.Unix:
 | 
			
		||||
				Process.Start("xdg-open", new string[] { folder });
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			case PlatformID.MacOSX:
 | 
			
		||||
				Process.Start("open", new string[] { folder });
 | 
			
		||||
				break;
 | 
			
		||||
 | 
			
		||||
			default:
 | 
			
		||||
				await Dialog.ShowOk(window, "Feature Not Supported", "This feature is not supported for your operating system.");
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void CloseDatabase() {
 | 
			
		||||
		DatabaseClosed?.Invoke(this, EventArgs.Empty);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void MergeWithDatabase() {
 | 
			
		||||
		var paths = await DatabaseGui.NewOpenDatabaseFilesDialog(window, Path.GetDirectoryName(Db.Path));
 | 
			
		||||
		if (paths.Length == 0) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ProgressDialog progressDialog = new ProgressDialog();
 | 
			
		||||
		progressDialog.DataContext = new ProgressDialogModel(async callback => await MergeWithDatabaseFromPaths(Db, paths, progressDialog, callback)) {
 | 
			
		||||
			Title = "Database Merge"
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		await progressDialog.ShowDialog(window);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static async Task MergeWithDatabaseFromPaths(IDatabaseFile target, string[] paths, ProgressDialog dialog, IProgressCallback callback) {
 | 
			
		||||
		int total = paths.Length;
 | 
			
		||||
 | 
			
		||||
		DialogResult.YesNo? upgradeResult = null;
 | 
			
		||||
 | 
			
		||||
		async Task<bool> CheckCanUpgradeDatabase() {
 | 
			
		||||
			upgradeResult ??= total > 1
 | 
			
		||||
				                  ? await DatabaseGui.ShowCanUpgradeMultipleDatabaseDialog(dialog)
 | 
			
		||||
				                  : await DatabaseGui.ShowCanUpgradeDatabaseDialog(dialog);
 | 
			
		||||
 | 
			
		||||
			return DialogResult.YesNo.Yes == upgradeResult;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		await PerformImport(target, paths, dialog, callback, "Database Merge", "Database Error", "database file", async path => {
 | 
			
		||||
			SynchronizationContext? prevSyncContext = SynchronizationContext.Current;
 | 
			
		||||
			SynchronizationContext.SetSynchronizationContext(new AvaloniaSynchronizationContext());
 | 
			
		||||
			IDatabaseFile? db = await DatabaseGui.TryOpenOrCreateDatabaseFromPath(path, dialog, CheckCanUpgradeDatabase);
 | 
			
		||||
			SynchronizationContext.SetSynchronizationContext(prevSyncContext);
 | 
			
		||||
 | 
			
		||||
			if (db == null) {
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			try {
 | 
			
		||||
				target.AddFrom(db);
 | 
			
		||||
				return true;
 | 
			
		||||
			} finally {
 | 
			
		||||
				db.Dispose();
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void ImportLegacyArchive() {
 | 
			
		||||
		var paths = await window.StorageProvider.OpenFiles(new FilePickerOpenOptions {
 | 
			
		||||
			Title = "Open Legacy DHT Archive",
 | 
			
		||||
			SuggestedStartLocation = await FileDialogs.GetSuggestedStartLocation(window, Path.GetDirectoryName(Db.Path)),
 | 
			
		||||
			AllowMultiple = true
 | 
			
		||||
		});
 | 
			
		||||
			
 | 
			
		||||
		if (paths.Length == 0) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ProgressDialog progressDialog = new ProgressDialog();
 | 
			
		||||
		progressDialog.DataContext = new ProgressDialogModel(async callback => await ImportLegacyArchiveFromPaths(Db, paths, progressDialog, callback)) {
 | 
			
		||||
			Title = "Legacy Archive Import"
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		await progressDialog.ShowDialog(window);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static async Task ImportLegacyArchiveFromPaths(IDatabaseFile target, string[] paths, ProgressDialog dialog, IProgressCallback callback) {
 | 
			
		||||
		var fakeSnowflake = new FakeSnowflake();
 | 
			
		||||
 | 
			
		||||
		await PerformImport(target, paths, dialog, callback, "Legacy Archive Import", "Legacy Archive Error", "archive file", async path => {
 | 
			
		||||
			await using var jsonStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
 | 
			
		||||
				
 | 
			
		||||
			return await LegacyArchiveImport.Read(jsonStream, target, fakeSnowflake, async servers => {
 | 
			
		||||
				SynchronizationContext? prevSyncContext = SynchronizationContext.Current;
 | 
			
		||||
				SynchronizationContext.SetSynchronizationContext(new AvaloniaSynchronizationContext());
 | 
			
		||||
				Dictionary<DHT.Server.Data.Server, ulong>? result = await Dispatcher.UIThread.InvokeAsync(() => AskForServerIds(dialog, servers));
 | 
			
		||||
				SynchronizationContext.SetSynchronizationContext(prevSyncContext);
 | 
			
		||||
				return result;
 | 
			
		||||
			});
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static async Task<Dictionary<DHT.Server.Data.Server, ulong>?> AskForServerIds(Window window, DHT.Server.Data.Server[] servers) {
 | 
			
		||||
		static bool IsValidSnowflake(string value) {
 | 
			
		||||
			return string.IsNullOrEmpty(value) || ulong.TryParse(value, out _);
 | 
			
		||||
		}
 | 
			
		||||
			
 | 
			
		||||
		var items = new List<TextBoxItem<DHT.Server.Data.Server>>();
 | 
			
		||||
 | 
			
		||||
		foreach (var server in servers.OrderBy(static server => server.Type).ThenBy(static server => server.Name)) {
 | 
			
		||||
			items.Add(new TextBoxItem<DHT.Server.Data.Server>(server) {
 | 
			
		||||
				Title = server.Name + " (" + ServerTypes.ToNiceString(server.Type) + ")",
 | 
			
		||||
				ValidityCheck = IsValidSnowflake
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var model = new TextBoxDialogModel<DHT.Server.Data.Server>(items) {
 | 
			
		||||
			Title = "Imported Server IDs",
 | 
			
		||||
			Description = "Please fill in the IDs of servers and direct messages. First enable Developer Mode in Discord, then right-click each server or direct message, click 'Copy ID', and paste it into the input field. If a server no longer exists, leave its input field empty to use a random ID."
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		var dialog = new TextBoxDialog { DataContext = model };
 | 
			
		||||
		var result = await dialog.ShowDialog<DialogResult.OkCancel>(window);
 | 
			
		||||
 | 
			
		||||
		if (result != DialogResult.OkCancel.Ok) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return model.ValidItems
 | 
			
		||||
		            .Where(static item => !string.IsNullOrEmpty(item.Value))
 | 
			
		||||
		            .ToDictionary(static item => item.Item, static item => ulong.Parse(item.Value));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static async Task PerformImport(IDatabaseFile target, string[] paths, ProgressDialog dialog, IProgressCallback callback, string neutralDialogTitle, string errorDialogTitle, string itemName, Func<string, Task<bool>> performImport) {
 | 
			
		||||
		int total = paths.Length;
 | 
			
		||||
		var oldStatistics = target.SnapshotStatistics();
 | 
			
		||||
 | 
			
		||||
		int successful = 0;
 | 
			
		||||
		int finished = 0;
 | 
			
		||||
 | 
			
		||||
		foreach (string path in paths) {
 | 
			
		||||
			await callback.Update(Path.GetFileName(path), finished, total);
 | 
			
		||||
			++finished;
 | 
			
		||||
 | 
			
		||||
			if (!File.Exists(path)) {
 | 
			
		||||
				await Dialog.ShowOk(dialog, errorDialogTitle, "File '" + Path.GetFileName(path) + "' no longer exists.");
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			try {
 | 
			
		||||
				if (await performImport(path)) {
 | 
			
		||||
					++successful;
 | 
			
		||||
				}
 | 
			
		||||
			} catch (Exception ex) {
 | 
			
		||||
				Log.Error(ex);
 | 
			
		||||
				await Dialog.ShowOk(dialog, errorDialogTitle, "File '" + Path.GetFileName(path) + "' could not be imported: " + ex.Message);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		await callback.Update("Done", finished, total);
 | 
			
		||||
 | 
			
		||||
		if (successful == 0) {
 | 
			
		||||
			await Dialog.ShowOk(dialog, neutralDialogTitle, "Nothing was imported.");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		await Dialog.ShowOk(dialog, neutralDialogTitle, GetImportDialogMessage(oldStatistics, target.SnapshotStatistics(), successful, total, itemName));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static string GetImportDialogMessage(DatabaseStatisticsSnapshot oldStatistics, DatabaseStatisticsSnapshot newStatistics, int successfulItems, int totalItems, string itemName) {
 | 
			
		||||
		long newServers = newStatistics.TotalServers - oldStatistics.TotalServers;
 | 
			
		||||
		long newChannels = newStatistics.TotalChannels - oldStatistics.TotalChannels;
 | 
			
		||||
		long newUsers = newStatistics.TotalUsers - oldStatistics.TotalUsers;
 | 
			
		||||
		long newMessages = newStatistics.TotalMessages - oldStatistics.TotalMessages;
 | 
			
		||||
 | 
			
		||||
		StringBuilder message = new StringBuilder();
 | 
			
		||||
		message.Append("Processed ");
 | 
			
		||||
 | 
			
		||||
		if (successfulItems == totalItems) {
 | 
			
		||||
			message.Append(successfulItems.Pluralize(itemName));
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			message.Append(successfulItems.Format()).Append(" out of ").Append(totalItems.Pluralize(itemName));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		message.Append(" and added:\n\n  \u2022 ");
 | 
			
		||||
		message.Append(newServers.Pluralize("server")).Append("\n  \u2022 ");
 | 
			
		||||
		message.Append(newChannels.Pluralize("channel")).Append("\n  \u2022 ");
 | 
			
		||||
		message.Append(newUsers.Pluralize("user")).Append("\n  \u2022 ");
 | 
			
		||||
		message.Append(newMessages.Pluralize("message"));
 | 
			
		||||
 | 
			
		||||
		return message.ToString();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										45
									
								
								app/Desktop/Main/Pages/DebugPage.axaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								app/Desktop/Main/Pages/DebugPage.axaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Pages.DebugPage">
 | 
			
		||||
    
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <pages:DebugPageModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <UserControl.Styles>
 | 
			
		||||
        <Style Selector="TextBox">
 | 
			
		||||
            <Setter Property="FontFamily" Value="Consolas,Courier" />
 | 
			
		||||
            <Setter Property="FontSize" Value="15" />
 | 
			
		||||
        </Style>
 | 
			
		||||
        <Style Selector="WrapPanel > StackPanel">
 | 
			
		||||
            <Setter Property="Orientation" Value="Vertical" />
 | 
			
		||||
            <Setter Property="Margin" Value="0 0 10 10" />
 | 
			
		||||
        </Style>
 | 
			
		||||
    </UserControl.Styles>
 | 
			
		||||
 | 
			
		||||
    <StackPanel Orientation="Vertical" Spacing="10">
 | 
			
		||||
        <Expander Header="Generate Random Data" IsExpanded="True">
 | 
			
		||||
            <WrapPanel>
 | 
			
		||||
                <StackPanel>
 | 
			
		||||
                    <Label Target="Channels">Channels</Label>
 | 
			
		||||
                    <TextBox x:Name="Channels" Width="100" Text="{Binding GenerateChannels}" />
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
                <StackPanel>
 | 
			
		||||
                    <Label Target="Users">Users</Label>
 | 
			
		||||
                    <TextBox x:Name="Users" Width="100" Text="{Binding GenerateUsers}" />
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
                <StackPanel>
 | 
			
		||||
                    <Label Target="Messages">Messages</Label>
 | 
			
		||||
                    <TextBox x:Name="Messages" Width="100" Text="{Binding GenerateMessages}" />
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
                <StackPanel VerticalAlignment="Bottom">
 | 
			
		||||
                    <Button Command="{Binding OnClickAddRandomDataToDatabase}">Add to Database</Button>
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
            </WrapPanel>
 | 
			
		||||
        </Expander>
 | 
			
		||||
    </StackPanel>
 | 
			
		||||
</UserControl>
 | 
			
		||||
							
								
								
									
										11
									
								
								app/Desktop/Main/Pages/DebugPage.axaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/Desktop/Main/Pages/DebugPage.axaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class DebugPage : UserControl {
 | 
			
		||||
	public DebugPage() {
 | 
			
		||||
		InitializeComponent();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										185
									
								
								app/Desktop/Main/Pages/DebugPageModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										185
									
								
								app/Desktop/Main/Pages/DebugPageModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,185 @@
 | 
			
		||||
#if DEBUG
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Progress;
 | 
			
		||||
using DHT.Server.Data;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Service;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages {
 | 
			
		||||
	sealed class DebugPageModel : BaseModel {
 | 
			
		||||
		public string GenerateChannels { get; set; } = "0";
 | 
			
		||||
		public string GenerateUsers { get; set; } = "0";
 | 
			
		||||
		public string GenerateMessages { get; set; } = "0";
 | 
			
		||||
 | 
			
		||||
		private readonly Window window;
 | 
			
		||||
		private readonly IDatabaseFile db;
 | 
			
		||||
 | 
			
		||||
		[Obsolete("Designer")]
 | 
			
		||||
		public DebugPageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
		public DebugPageModel(Window window, IDatabaseFile db) {
 | 
			
		||||
			this.window = window;
 | 
			
		||||
			this.db = db;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public async void OnClickAddRandomDataToDatabase() {
 | 
			
		||||
			if (!int.TryParse(GenerateChannels, out int channels) || channels < 1) {
 | 
			
		||||
				await Dialog.ShowOk(window, "Generate Random Data", "Amount of channels must be at least 1!");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (!int.TryParse(GenerateUsers, out int users) || users < 1) {
 | 
			
		||||
				await Dialog.ShowOk(window, "Generate Random Data", "Amount of users must be at least 1!");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (!int.TryParse(GenerateMessages, out int messages) || messages < 1) {
 | 
			
		||||
				await Dialog.ShowOk(window, "Generate Random Data", "Amount of messages must be at least 1!");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			ProgressDialog progressDialog = new ProgressDialog {
 | 
			
		||||
				DataContext = new ProgressDialogModel(async callback => await GenerateRandomData(channels, users, messages, callback)) {
 | 
			
		||||
					Title = "Generating Random Data"
 | 
			
		||||
				}
 | 
			
		||||
			};
 | 
			
		||||
 | 
			
		||||
			await progressDialog.ShowDialog(window);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private const int BatchSize = 500;
 | 
			
		||||
 | 
			
		||||
		private async Task GenerateRandomData(int channelCount, int userCount, int messageCount, IProgressCallback callback) {
 | 
			
		||||
			int batchCount = (messageCount + BatchSize - 1) / BatchSize;
 | 
			
		||||
			await callback.Update("Adding messages in batches of " + BatchSize, 0, batchCount);
 | 
			
		||||
 | 
			
		||||
			var rand = new Random();
 | 
			
		||||
			var server = new DHT.Server.Data.Server {
 | 
			
		||||
				Id = RandomId(rand),
 | 
			
		||||
				Name = RandomName("s"),
 | 
			
		||||
				Type = ServerType.Server,
 | 
			
		||||
			};
 | 
			
		||||
 | 
			
		||||
			var channels = Enumerable.Range(0, channelCount).Select(i => new Channel {
 | 
			
		||||
				Id = RandomId(rand),
 | 
			
		||||
				Server = server.Id,
 | 
			
		||||
				Name = RandomName("c"),
 | 
			
		||||
				ParentId = null,
 | 
			
		||||
				Position = i,
 | 
			
		||||
				Topic = RandomText(rand, 10),
 | 
			
		||||
				Nsfw = rand.Next(4) == 0,
 | 
			
		||||
			}).ToArray();
 | 
			
		||||
 | 
			
		||||
			var users = Enumerable.Range(0, userCount).Select(_ => new User {
 | 
			
		||||
				Id = RandomId(rand),
 | 
			
		||||
				Name = RandomName("u"),
 | 
			
		||||
				AvatarUrl = null,
 | 
			
		||||
				Discriminator = rand.Next(0, 9999).ToString(),
 | 
			
		||||
			}).ToArray();
 | 
			
		||||
 | 
			
		||||
			db.AddServer(server);
 | 
			
		||||
			db.AddUsers(users);
 | 
			
		||||
 | 
			
		||||
			foreach (var channel in channels) {
 | 
			
		||||
				db.AddChannel(channel);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			var now = DateTimeOffset.Now;
 | 
			
		||||
			int batchIndex = 0;
 | 
			
		||||
 | 
			
		||||
			while (messageCount > 0) {
 | 
			
		||||
				int hourOffset = batchIndex;
 | 
			
		||||
 | 
			
		||||
				var messages = Enumerable.Range(0, Math.Min(messageCount, BatchSize)).Select(i => {
 | 
			
		||||
					DateTimeOffset time = now.AddHours(hourOffset).AddMinutes(i * 60.0 / BatchSize);
 | 
			
		||||
					DateTimeOffset? edit = rand.Next(100) == 0 ? time.AddSeconds(rand.Next(1, 60)) : null;
 | 
			
		||||
 | 
			
		||||
					var timeMillis = time.ToUnixTimeMilliseconds();
 | 
			
		||||
					var editMillis = edit?.ToUnixTimeMilliseconds();
 | 
			
		||||
 | 
			
		||||
					return new Message {
 | 
			
		||||
						Id = (ulong) timeMillis,
 | 
			
		||||
						Sender = RandomBiasedIndex(rand, users).Id,
 | 
			
		||||
						Channel = RandomBiasedIndex(rand, channels).Id,
 | 
			
		||||
						Text = RandomText(rand, 100),
 | 
			
		||||
						Timestamp = timeMillis,
 | 
			
		||||
						EditTimestamp = editMillis,
 | 
			
		||||
						RepliedToId = null,
 | 
			
		||||
						Attachments = ImmutableArray<Attachment>.Empty,
 | 
			
		||||
						Embeds = ImmutableArray<Embed>.Empty,
 | 
			
		||||
						Reactions = ImmutableArray<Reaction>.Empty,
 | 
			
		||||
					};
 | 
			
		||||
				}).ToArray();
 | 
			
		||||
 | 
			
		||||
				db.AddMessages(messages);
 | 
			
		||||
 | 
			
		||||
				messageCount -= BatchSize;
 | 
			
		||||
				await callback.Update("Adding messages in batches of " + BatchSize, ++batchIndex, batchCount);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static ulong RandomId(Random rand) {
 | 
			
		||||
			ulong h = unchecked((ulong) rand.Next());
 | 
			
		||||
			ulong l = unchecked((ulong) rand.Next());
 | 
			
		||||
			return (h << 32) | l;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static string RandomName(string prefix) {
 | 
			
		||||
			return prefix + "-" + ServerUtils.GenerateRandomToken(5);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static T RandomBiasedIndex<T>(Random rand, T[] options) {
 | 
			
		||||
			return options[(int) Math.Floor(options.Length * rand.NextDouble() * rand.NextDouble())];
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static readonly string[] RandomWords = {
 | 
			
		||||
			"apple", "apricot", "artichoke", "arugula", "asparagus", "avocado",
 | 
			
		||||
			"banana", "bean", "beechnut", "beet", "blackberry", "blackcurrant", "blueberry", "boysenberry", "bramble", "broccoli",
 | 
			
		||||
			"cabbage", "cacao", "cantaloupe", "caper", "carambola", "carrot", "cauliflower", "celery", "chard", "cherry", "chokeberry", "citron", "clementine", "coconut", "corn", "crabapple", "cranberry", "cucumber", "currant",
 | 
			
		||||
			"daikon", "date", "dewberry", "durian",
 | 
			
		||||
			"edamame", "eggplant", "elderberry", "endive",
 | 
			
		||||
			"fig",
 | 
			
		||||
			"garlic", "ginger", "gooseberry", "grape", "grapefruit", "guava",
 | 
			
		||||
			"honeysuckle", "horseradish", "huckleberry",
 | 
			
		||||
			"jackfruit", "jicama",
 | 
			
		||||
			"kale", "kiwi", "kohlrabi", "kumquat",
 | 
			
		||||
			"leek", "lemon", "lentil", "lettuce", "lime",
 | 
			
		||||
			"mandarin", "mango", "mushroom", "myrtle",
 | 
			
		||||
			"nectarine", "nut",
 | 
			
		||||
			"olive", "okra", "onion", "orange",
 | 
			
		||||
			"papaya", "parsnip", "pawpaw", "peach", "pear", "pea", "pepper", "persimmon", "pineapple", "plum", "plantain", "pomegranate", "pomelo", "potato", "prune", "pumpkin",
 | 
			
		||||
			"quandong", "quinoa",
 | 
			
		||||
			"radicchio", "radish", "raisin", "raspberry", "redcurrant", "rhubarb", "rutabaga",
 | 
			
		||||
			"spinach", "strawberry", "squash",
 | 
			
		||||
			"tamarind", "tangerine", "tomatillo", "tomato", "turnip",
 | 
			
		||||
			"vanilla",
 | 
			
		||||
			"watercress", "watermelon",
 | 
			
		||||
			"yam",
 | 
			
		||||
			"zucchini",
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		private static string RandomText(Random rand, int maxWords) {
 | 
			
		||||
			int wordCount = 1 + (int) Math.Floor(maxWords * Math.Pow(rand.NextDouble(), 3));
 | 
			
		||||
			return string.Join(' ', Enumerable.Range(0, wordCount).Select(_ => RandomWords[rand.Next(RandomWords.Length)]));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages {
 | 
			
		||||
	sealed class DebugPageModel : BaseModel {
 | 
			
		||||
		public string GenerateChannels { get; set; } = "0";
 | 
			
		||||
		public string GenerateUsers { get; set; } = "0";
 | 
			
		||||
		public string GenerateMessages { get; set; } = "0";
 | 
			
		||||
 | 
			
		||||
		public void OnClickAddRandomDataToDatabase() {}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.App.Pages"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Pages.TrackingPage">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Pages.TrackingPage">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <pages:TrackingPageModel />
 | 
			
		||||
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Interactivity;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Pages;
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class TrackingPage : UserControl {
 | 
			
		||||
@@ -2,12 +2,13 @@ using System;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Web;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Discord;
 | 
			
		||||
using DHT.Desktop.Server;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
using static DHT.Desktop.Program;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Pages;
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
sealed class TrackingPageModel : BaseModel {
 | 
			
		||||
	private bool areDevToolsEnabled;
 | 
			
		||||
@@ -51,14 +52,10 @@ sealed class TrackingPageModel : BaseModel {
 | 
			
		||||
			OnPropertyChanged(nameof(IsToggleAppDevToolsButtonEnabled));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	public async Task<bool> OnClickCopyTrackingScript() {
 | 
			
		||||
		string bootstrap = await Resources.ReadTextAsync("Tracker/bootstrap.js");
 | 
			
		||||
		string script = bootstrap.Replace("= 0; /*[PORT]*/", "= " + ServerManager.Port + ";")
 | 
			
		||||
		                         .Replace("/*[TOKEN]*/", HttpUtility.JavaScriptStringEncode(ServerManager.Token))
 | 
			
		||||
		                         .Replace("/*[IMPORTS]*/", await Resources.ReadJoinedAsync("Tracker/scripts/", '\n'))
 | 
			
		||||
		                         .Replace("/*[CSS-CONTROLLER]*/", await Resources.ReadTextAsync("Tracker/styles/controller.css"))
 | 
			
		||||
		                         .Replace("/*[CSS-SETTINGS]*/", await Resources.ReadTextAsync("Tracker/styles/settings.css"));
 | 
			
		||||
		string url = $"http://127.0.0.1:{ServerManager.Port}/get-tracking-script?token={HttpUtility.UrlEncode(ServerManager.Token)}";
 | 
			
		||||
		string script = (await Resources.ReadTextAsync("tracker-loader.js")).Trim().Replace("{url}", url);
 | 
			
		||||
 | 
			
		||||
		var clipboard = window.Clipboard;
 | 
			
		||||
		if (clipboard == null) {
 | 
			
		||||
							
								
								
									
										37
									
								
								app/Desktop/Main/Pages/ViewerPage.axaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								app/Desktop/Main/Pages/ViewerPage.axaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
<UserControl xmlns="https://github.com/avaloniaui"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:pages="clr-namespace:DHT.Desktop.Main.Pages"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Pages.ViewerPage">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <pages:ViewerPageModel />
 | 
			
		||||
    </Design.DataContext>
 | 
			
		||||
 | 
			
		||||
    <UserControl.Styles>
 | 
			
		||||
        <Style Selector="Expander">
 | 
			
		||||
            <Setter Property="Margin" Value="0 5 0 0" />
 | 
			
		||||
        </Style>
 | 
			
		||||
    </UserControl.Styles>
 | 
			
		||||
 | 
			
		||||
    <StackPanel Orientation="Vertical" Spacing="20">
 | 
			
		||||
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
 | 
			
		||||
            <Button Command="{Binding OnClickOpenViewer}" Margin="0 0 5 0">Open Viewer</Button>
 | 
			
		||||
            <Button Command="{Binding OnClickSaveViewer}" Margin="5 0 0 0">Save Viewer</Button>
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
        <controls:MessageFilterPanel DataContext="{Binding FilterModel}" />
 | 
			
		||||
        <Expander Header="Database Tools">
 | 
			
		||||
            <StackPanel Orientation="Vertical" Spacing="10">
 | 
			
		||||
                <StackPanel Orientation="Vertical" Spacing="4">
 | 
			
		||||
                    <RadioButton GroupName="DatabaseToolFilterMode" IsEnabled="{Binding HasFilters}" IsChecked="{Binding DatabaseToolFilterModeKeep}">Keep Only Messages Matching Filters</RadioButton>
 | 
			
		||||
                    <RadioButton GroupName="DatabaseToolFilterMode" IsEnabled="{Binding HasFilters}" IsChecked="{Binding DatabaseToolFilterModeRemove}">Remove Messages Matching Filters</RadioButton>
 | 
			
		||||
                </StackPanel>
 | 
			
		||||
                <Button IsEnabled="{Binding HasFilters}" Command="{Binding OnClickApplyFiltersToDatabase}">Apply Filters to Database</Button>
 | 
			
		||||
            </StackPanel>
 | 
			
		||||
        </Expander>
 | 
			
		||||
    </StackPanel>
 | 
			
		||||
 | 
			
		||||
</UserControl>
 | 
			
		||||
							
								
								
									
										11
									
								
								app/Desktop/Main/Pages/ViewerPage.axaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/Desktop/Main/Pages/ViewerPage.axaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class ViewerPage : UserControl {
 | 
			
		||||
	public ViewerPage() {
 | 
			
		||||
		InitializeComponent();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										149
									
								
								app/Desktop/Main/Pages/ViewerPageModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										149
									
								
								app/Desktop/Main/Pages/ViewerPageModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,149 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Concurrent;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using System.Web;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using Avalonia.Platform.Storage;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Desktop.Dialogs.File;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Main.Controls;
 | 
			
		||||
using DHT.Desktop.Server;
 | 
			
		||||
using DHT.Server.Data.Filters;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Database.Export;
 | 
			
		||||
using DHT.Server.Database.Export.Strategy;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
using static DHT.Desktop.Program;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.Main.Pages;
 | 
			
		||||
 | 
			
		||||
sealed class ViewerPageModel : BaseModel, IDisposable {
 | 
			
		||||
	public static readonly ConcurrentBag<string> TemporaryFiles = new ();
 | 
			
		||||
 | 
			
		||||
	public bool DatabaseToolFilterModeKeep { get; set; } = true;
 | 
			
		||||
	public bool DatabaseToolFilterModeRemove { get; set; } = false;
 | 
			
		||||
 | 
			
		||||
	private bool hasFilters = false;
 | 
			
		||||
 | 
			
		||||
	public bool HasFilters {
 | 
			
		||||
		get => hasFilters;
 | 
			
		||||
		set => Change(ref hasFilters, value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private MessageFilterPanelModel FilterModel { get; }
 | 
			
		||||
 | 
			
		||||
	private readonly Window window;
 | 
			
		||||
	private readonly IDatabaseFile db;
 | 
			
		||||
 | 
			
		||||
	[Obsolete("Designer")]
 | 
			
		||||
	public ViewerPageModel() : this(null!, DummyDatabaseFile.Instance) {}
 | 
			
		||||
 | 
			
		||||
	public ViewerPageModel(Window window, IDatabaseFile db) {
 | 
			
		||||
		this.window = window;
 | 
			
		||||
		this.db = db;
 | 
			
		||||
 | 
			
		||||
		FilterModel = new MessageFilterPanelModel(window, db, "Will export");
 | 
			
		||||
		FilterModel.FilterPropertyChanged += OnFilterPropertyChanged;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void Dispose() {
 | 
			
		||||
		FilterModel.Dispose();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void OnFilterPropertyChanged(object? sender, PropertyChangedEventArgs e) {
 | 
			
		||||
		HasFilters = FilterModel.HasAnyFilters;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private async Task WriteViewerFile(string path, IViewerExportStrategy strategy) {
 | 
			
		||||
		const string ArchiveTag = "/*[ARCHIVE]*/";
 | 
			
		||||
 | 
			
		||||
		string indexFile = await Resources.ReadTextAsync("Viewer/index.html");
 | 
			
		||||
		string viewerTemplate = indexFile.Replace("/*[JS]*/", await Resources.ReadJoinedAsync("Viewer/scripts/", '\n'))
 | 
			
		||||
		                                 .Replace("/*[CSS]*/", await Resources.ReadJoinedAsync("Viewer/styles/", '\n'));
 | 
			
		||||
 | 
			
		||||
		int viewerArchiveTagStart = viewerTemplate.IndexOf(ArchiveTag);
 | 
			
		||||
		int viewerArchiveTagEnd = viewerArchiveTagStart + ArchiveTag.Length;
 | 
			
		||||
 | 
			
		||||
		string jsonTempFile = path + ".tmp";
 | 
			
		||||
 | 
			
		||||
		await using (var jsonStream = new FileStream(jsonTempFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) {
 | 
			
		||||
			await ViewerJsonExport.Generate(jsonStream, strategy, db, FilterModel.CreateFilter());
 | 
			
		||||
 | 
			
		||||
			char[] jsonBuffer = new char[Math.Min(32768, jsonStream.Position)];
 | 
			
		||||
			jsonStream.Position = 0;
 | 
			
		||||
 | 
			
		||||
			await using (var outputStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
 | 
			
		||||
			await using (var outputWriter = new StreamWriter(outputStream, Encoding.UTF8)) {
 | 
			
		||||
				await outputWriter.WriteAsync(viewerTemplate[..viewerArchiveTagStart]);
 | 
			
		||||
 | 
			
		||||
				using (var jsonReader = new StreamReader(jsonStream, Encoding.UTF8)) {
 | 
			
		||||
					int readBytes;
 | 
			
		||||
					while ((readBytes = await jsonReader.ReadAsync(jsonBuffer, 0, jsonBuffer.Length)) > 0) {
 | 
			
		||||
						string jsonChunk = new string(jsonBuffer, 0, readBytes);
 | 
			
		||||
						await outputWriter.WriteAsync(HttpUtility.JavaScriptStringEncode(jsonChunk));
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				await outputWriter.WriteAsync(viewerTemplate[viewerArchiveTagEnd..]);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		File.Delete(jsonTempFile);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void OnClickOpenViewer() {
 | 
			
		||||
		string rootPath = Path.Combine(Path.GetTempPath(), "DiscordHistoryTracker");
 | 
			
		||||
		string filenameBase = Path.GetFileNameWithoutExtension(db.Path) + "-" + DateTime.Now.ToString("yyyy-MM-dd");
 | 
			
		||||
		string fullPath = Path.Combine(rootPath, filenameBase + ".html");
 | 
			
		||||
		int counter = 0;
 | 
			
		||||
 | 
			
		||||
		while (File.Exists(fullPath)) {
 | 
			
		||||
			++counter;
 | 
			
		||||
			fullPath = Path.Combine(rootPath, filenameBase + "-" + counter + ".html");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		TemporaryFiles.Add(fullPath);
 | 
			
		||||
 | 
			
		||||
		Directory.CreateDirectory(rootPath);
 | 
			
		||||
		await WriteViewerFile(fullPath, new LiveViewerExportStrategy(ServerManager.Port, ServerManager.Token));
 | 
			
		||||
 | 
			
		||||
		Process.Start(new ProcessStartInfo(fullPath) { UseShellExecute = true });
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static readonly FilePickerFileType[] ViewerFileTypes = {
 | 
			
		||||
		FileDialogs.CreateFilter("Discord History Viewer", new string[] { "html" }),
 | 
			
		||||
	};
 | 
			
		||||
	
 | 
			
		||||
	public async void OnClickSaveViewer() {
 | 
			
		||||
		string? path = await window.StorageProvider.SaveFile(new FilePickerSaveOptions {
 | 
			
		||||
			Title = "Save Viewer",
 | 
			
		||||
			FileTypeChoices = ViewerFileTypes,
 | 
			
		||||
			SuggestedFileName = Path.GetFileNameWithoutExtension(db.Path) + ".html",
 | 
			
		||||
			SuggestedStartLocation = await FileDialogs.GetSuggestedStartLocation(window, Path.GetDirectoryName(db.Path)),
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if (path != null) {
 | 
			
		||||
			await WriteViewerFile(path, StandaloneViewerExportStrategy.Instance);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async void OnClickApplyFiltersToDatabase() {
 | 
			
		||||
		var filter = FilterModel.CreateFilter();
 | 
			
		||||
 | 
			
		||||
		if (DatabaseToolFilterModeKeep) {
 | 
			
		||||
			if (DialogResult.YesNo.Yes == await Dialog.ShowYesNo(window, "Keep Matching Messages in This Database", db.CountMessages(filter).Pluralize("message") + " will be kept, and the rest will be removed from this database. This action cannot be undone. Proceed?")) {
 | 
			
		||||
				db.RemoveMessages(filter, FilterRemovalMode.KeepMatching);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else if (DatabaseToolFilterModeRemove) {
 | 
			
		||||
			if (DialogResult.YesNo.Yes == await Dialog.ShowYesNo(window, "Remove Matching Messages in This Database", db.CountMessages(filter).Pluralize("message") + " will be removed from this database. This action cannot be undone. Proceed?")) {
 | 
			
		||||
				db.RemoveMessages(filter, FilterRemovalMode.RemoveMatching);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -2,10 +2,10 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:screens="clr-namespace:DHT.Desktop.App.Screens"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.App.Controls"
 | 
			
		||||
             xmlns:controls="clr-namespace:DHT.Desktop.Main.Controls"
 | 
			
		||||
             xmlns:screens="clr-namespace:DHT.Desktop.Main.Screens"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Screens.MainContentScreen">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Screens.MainContentScreen">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <screens:MainContentScreenModel />
 | 
			
		||||
@@ -80,7 +80,7 @@
 | 
			
		||||
        <TabControl x:Name="TabControl" TabStripPlacement="Left" DockPanel.Dock="Top">
 | 
			
		||||
            <TabControl.ItemsPanel>
 | 
			
		||||
                <ItemsPanelTemplate>
 | 
			
		||||
                    <Grid ColumnDefinitions="Auto" RowDefinitions="Auto,Auto,*,Auto" />
 | 
			
		||||
                    <Grid ColumnDefinitions="Auto" RowDefinitions="Auto,Auto,Auto,Auto,*,Auto,Auto" />
 | 
			
		||||
                </ItemsPanelTemplate>
 | 
			
		||||
            </TabControl.ItemsPanel>
 | 
			
		||||
            <TabItem x:Name="TabDatabase" Header="Database" Classes="first" Grid.Row="0">
 | 
			
		||||
@@ -93,11 +93,26 @@
 | 
			
		||||
                    <ContentPresenter Content="{Binding TrackingPage}" Classes="page" />
 | 
			
		||||
                </ScrollViewer>
 | 
			
		||||
            </TabItem>
 | 
			
		||||
            <TabItem x:Name="TabAdvanced" Header="Advanced" Grid.Row="3">
 | 
			
		||||
            <TabItem x:Name="TabAttachments" Header="Attachments" Grid.Row="2">
 | 
			
		||||
                <ScrollViewer>
 | 
			
		||||
                    <ContentPresenter Content="{Binding AttachmentsPage}" Classes="page" />
 | 
			
		||||
                </ScrollViewer>
 | 
			
		||||
            </TabItem>
 | 
			
		||||
            <TabItem x:Name="TabViewer" Header="Viewer" Grid.Row="3">
 | 
			
		||||
                <ScrollViewer>
 | 
			
		||||
                    <ContentPresenter Content="{Binding ViewerPage}" Classes="page" />
 | 
			
		||||
                </ScrollViewer>
 | 
			
		||||
            </TabItem>
 | 
			
		||||
            <TabItem x:Name="TabAdvanced" Header="Advanced" Grid.Row="5">
 | 
			
		||||
                <ScrollViewer>
 | 
			
		||||
                    <ContentPresenter Content="{Binding AdvancedPage}" Classes="page" />
 | 
			
		||||
                </ScrollViewer>
 | 
			
		||||
            </TabItem>
 | 
			
		||||
            <TabItem x:Name="TabDebug" Header="Debug" Grid.Row="6" IsVisible="{Binding HasDebugPage}">
 | 
			
		||||
                <ScrollViewer>
 | 
			
		||||
                    <ContentPresenter Content="{Binding DebugPage}" Classes="page" />
 | 
			
		||||
                </ScrollViewer>
 | 
			
		||||
            </TabItem>
 | 
			
		||||
        </TabControl>
 | 
			
		||||
    </DockPanel>
 | 
			
		||||
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Screens;
 | 
			
		||||
namespace DHT.Desktop.Main.Screens;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class MainContentScreen : UserControl {
 | 
			
		||||
@@ -1,14 +1,15 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Controls;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.App.Pages;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.Main.Controls;
 | 
			
		||||
using DHT.Desktop.Main.Pages;
 | 
			
		||||
using DHT.Desktop.Server;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Server.Service;
 | 
			
		||||
using DHT.Utils.Logging;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Screens;
 | 
			
		||||
namespace DHT.Desktop.Main.Screens;
 | 
			
		||||
 | 
			
		||||
sealed class MainContentScreenModel : IDisposable {
 | 
			
		||||
	private static readonly Log Log = Log.ForType<MainContentScreenModel>();
 | 
			
		||||
@@ -19,9 +20,24 @@ sealed class MainContentScreenModel : IDisposable {
 | 
			
		||||
	public TrackingPage TrackingPage { get; }
 | 
			
		||||
	private TrackingPageModel TrackingPageModel { get; }
 | 
			
		||||
 | 
			
		||||
	public AttachmentsPage AttachmentsPage { get; }
 | 
			
		||||
	private AttachmentsPageModel AttachmentsPageModel { get; }
 | 
			
		||||
 | 
			
		||||
	public ViewerPage ViewerPage { get; }
 | 
			
		||||
	private ViewerPageModel ViewerPageModel { get; }
 | 
			
		||||
 | 
			
		||||
	public AdvancedPage AdvancedPage { get; }
 | 
			
		||||
	private AdvancedPageModel AdvancedPageModel { get; }
 | 
			
		||||
 | 
			
		||||
	public DebugPage? DebugPage { get; }
 | 
			
		||||
 | 
			
		||||
	#if DEBUG
 | 
			
		||||
	public bool HasDebugPage => true;
 | 
			
		||||
	private DebugPageModel DebugPageModel { get; }
 | 
			
		||||
	#else
 | 
			
		||||
		public bool HasDebugPage => false;
 | 
			
		||||
	#endif
 | 
			
		||||
 | 
			
		||||
	public StatusBarModel StatusBarModel { get; }
 | 
			
		||||
 | 
			
		||||
	public event EventHandler? DatabaseClosed {
 | 
			
		||||
@@ -51,10 +67,23 @@ sealed class MainContentScreenModel : IDisposable {
 | 
			
		||||
		TrackingPageModel = new TrackingPageModel(window);
 | 
			
		||||
		TrackingPage = new TrackingPage { DataContext = TrackingPageModel };
 | 
			
		||||
 | 
			
		||||
		AttachmentsPageModel = new AttachmentsPageModel(db);
 | 
			
		||||
		AttachmentsPage = new AttachmentsPage { DataContext = AttachmentsPageModel };
 | 
			
		||||
 | 
			
		||||
		ViewerPageModel = new ViewerPageModel(window, db);
 | 
			
		||||
		ViewerPage = new ViewerPage { DataContext = ViewerPageModel };
 | 
			
		||||
 | 
			
		||||
		AdvancedPageModel = new AdvancedPageModel(window, db, serverManager);
 | 
			
		||||
		AdvancedPage = new AdvancedPage { DataContext = AdvancedPageModel };
 | 
			
		||||
 | 
			
		||||
		StatusBarModel = new StatusBarModel();
 | 
			
		||||
		#if DEBUG
 | 
			
		||||
		DebugPageModel = new DebugPageModel(window, db);
 | 
			
		||||
		DebugPage = new DebugPage { DataContext = DebugPageModel };
 | 
			
		||||
		#else
 | 
			
		||||
			DebugPage = null;
 | 
			
		||||
		#endif
 | 
			
		||||
 | 
			
		||||
		StatusBarModel = new StatusBarModel(db.Statistics);
 | 
			
		||||
 | 
			
		||||
		AdvancedPageModel.ServerConfigurationModel.ServerStatusChanged += OnServerStatusChanged;
 | 
			
		||||
		DatabaseClosed += OnDatabaseClosed;
 | 
			
		||||
@@ -70,6 +99,8 @@ sealed class MainContentScreenModel : IDisposable {
 | 
			
		||||
 | 
			
		||||
	public void Dispose() {
 | 
			
		||||
		ServerLauncher.ServerManagementExceptionCaught -= ServerLauncherOnServerManagementExceptionCaught;
 | 
			
		||||
		AttachmentsPageModel.Dispose();
 | 
			
		||||
		ViewerPageModel.Dispose();
 | 
			
		||||
		serverManager.Dispose();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -2,9 +2,9 @@
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 | 
			
		||||
             xmlns:screens="clr-namespace:DHT.Desktop.App.Screens"
 | 
			
		||||
             xmlns:screens="clr-namespace:DHT.Desktop.Main.Screens"
 | 
			
		||||
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
 | 
			
		||||
             x:Class="DHT.Desktop.App.Screens.WelcomeScreen">
 | 
			
		||||
             x:Class="DHT.Desktop.Main.Screens.WelcomeScreen">
 | 
			
		||||
 | 
			
		||||
    <Design.DataContext>
 | 
			
		||||
        <screens:WelcomeScreenModel />
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Diagnostics.CodeAnalysis;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Screens;
 | 
			
		||||
namespace DHT.Desktop.Main.Screens;
 | 
			
		||||
 | 
			
		||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
 | 
			
		||||
public sealed partial class WelcomeScreen : UserControl {
 | 
			
		||||
@@ -2,13 +2,12 @@ using System;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Avalonia.Controls;
 | 
			
		||||
using DHT.Desktop.App.Common;
 | 
			
		||||
using DHT.Desktop.App.Dialogs.Message;
 | 
			
		||||
using DHT.Desktop.App.Windows;
 | 
			
		||||
using DHT.Desktop.Common;
 | 
			
		||||
using DHT.Desktop.Dialogs.Message;
 | 
			
		||||
using DHT.Server.Database;
 | 
			
		||||
using DHT.Utils.Models;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop.App.Screens;
 | 
			
		||||
namespace DHT.Desktop.Main.Screens;
 | 
			
		||||
 | 
			
		||||
sealed class WelcomeScreenModel : BaseModel, IDisposable {
 | 
			
		||||
	public string Version => Program.Version;
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using Avalonia;
 | 
			
		||||
using DHT.Desktop.Resources;
 | 
			
		||||
using DHT.Utils.Resources;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Desktop;
 | 
			
		||||
 | 
			
		||||
@@ -32,7 +32,7 @@ static class Program {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static AppBuilder BuildAvaloniaApp() {
 | 
			
		||||
		return AppBuilder.Configure<App.App>()
 | 
			
		||||
		return AppBuilder.Configure<App>()
 | 
			
		||||
		                 .UsePlatformDetect()
 | 
			
		||||
		                 .WithInterFont()
 | 
			
		||||
		                 .LogToTrace();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								app/Desktop/Resources/tracker-loader.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								app/Desktop/Resources/tracker-loader.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
fetch("{url}").then(r => r.ok ? (r.headers.get("X-DHT") === "1" ? r.text() : Promise.reject("Invalid response")) : Promise.reject(r.status + " " + r.statusText)).then(s => eval(s)).catch(e => alert("Could not load tracking script:\n" + e));
 | 
			
		||||
							
								
								
									
										37
									
								
								app/Directory.Build.props
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								app/Directory.Build.props
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
<Project>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0</TargetFramework>
 | 
			
		||||
    <LangVersion>11</LangVersion>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <Authors>chylex</Authors>
 | 
			
		||||
    <Company>DiscordHistoryTracker</Company>
 | 
			
		||||
    <Product>DiscordHistoryTracker</Product>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
 | 
			
		||||
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
 | 
			
		||||
    <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <PublishTrimmed>true</PublishTrimmed>
 | 
			
		||||
    <TrimMode>partial</TrimMode>
 | 
			
		||||
    <JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 | 
			
		||||
    <DebugSymbols>false</DebugSymbols>
 | 
			
		||||
    <DebugType>none</DebugType>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <UseArtifactsOutput>true</UseArtifactsOutput>
 | 
			
		||||
    <ArtifactsPath>$(MSBuildThisFileDirectory).artifacts</ArtifactsPath>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
</Project>
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
<Project>
 | 
			
		||||
  
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>net8.0</TargetFramework>
 | 
			
		||||
    <LangVersion>11</LangVersion>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										5
									
								
								app/Resources/Tracker/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								app/Resources/Tracker/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@@ -64,9 +64,11 @@
 | 
			
		||||
			let action = null;
 | 
			
		||||
			
 | 
			
		||||
			if (!DISCORD.hasMoreMessages()) {
 | 
			
		||||
				console.debug("[DHT] Reached first message.");
 | 
			
		||||
				action = SETTINGS.afterFirstMsg;
 | 
			
		||||
			}
 | 
			
		||||
			if (isNoAction(action) && !anyNewMessages) {
 | 
			
		||||
				console.debug("[DHT] No new messages.");
 | 
			
		||||
				action = SETTINGS.afterSavedMsg;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
@@ -121,7 +123,7 @@
 | 
			
		||||
				onTrackingContinued(false);
 | 
			
		||||
			}
 | 
			
		||||
			else {
 | 
			
		||||
				const anyNewMessages = await STATE.addDiscordMessages(info.id, messages);
 | 
			
		||||
				const anyNewMessages = await STATE.addDiscordMessages(messages);
 | 
			
		||||
				onTrackingContinued(anyNewMessages);
 | 
			
		||||
			}
 | 
			
		||||
		} catch (e) {
 | 
			
		||||
@@ -156,3 +158,4 @@
 | 
			
		||||
		GUI.showSettings();
 | 
			
		||||
	}
 | 
			
		||||
})();
 | 
			
		||||
/*[DEBUGGER]*/
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,23 @@
 | 
			
		||||
// noinspection JSUnresolvedVariable
 | 
			
		||||
// noinspection LocalVariableNamingConventionJS
 | 
			
		||||
class DISCORD {
 | 
			
		||||
	
 | 
			
		||||
	// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
 | 
			
		||||
	static CHANNEL_TYPE = {
 | 
			
		||||
		DM: 1,
 | 
			
		||||
		GROUP_DM: 3,
 | 
			
		||||
		ANNOUNCEMENT_THREAD: 10,
 | 
			
		||||
		PUBLIC_THREAD: 11,
 | 
			
		||||
		PRIVATE_THREAD: 12
 | 
			
		||||
	};
 | 
			
		||||
	
 | 
			
		||||
	// https://discord.com/developers/docs/resources/channel#message-object-message-types
 | 
			
		||||
	static MESSAGE_TYPE = {
 | 
			
		||||
		DEFAULT: 0,
 | 
			
		||||
		REPLY: 19,
 | 
			
		||||
		THREAD_STARTER: 21
 | 
			
		||||
	};
 | 
			
		||||
	
 | 
			
		||||
	static getMessageOuterElement() {
 | 
			
		||||
		return DOM.queryReactClass("messagesWrapper");
 | 
			
		||||
	}
 | 
			
		||||
@@ -9,7 +27,7 @@ class DISCORD {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	static getMessageElements() {
 | 
			
		||||
		return this.getMessageOuterElement().querySelectorAll("[class*='message-']");
 | 
			
		||||
		return this.getMessageOuterElement().querySelectorAll("[class*='message_']");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	static hasMoreMessages() {
 | 
			
		||||
@@ -28,46 +46,11 @@ class DISCORD {
 | 
			
		||||
	 * Calls the provided function with a list of messages whenever the currently loaded messages change.
 | 
			
		||||
	 */
 | 
			
		||||
	static setupMessageCallback(callback) {
 | 
			
		||||
		let skipsLeft = 0;
 | 
			
		||||
		let waitForCleanup = false;
 | 
			
		||||
		const previousMessages = new Set();
 | 
			
		||||
		
 | 
			
		||||
		const timer = window.setInterval(() => {
 | 
			
		||||
			if (skipsLeft > 0) {
 | 
			
		||||
				--skipsLeft;
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			const view = this.getMessageOuterElement();
 | 
			
		||||
			
 | 
			
		||||
			if (!view) {
 | 
			
		||||
				skipsLeft = 2;
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			const anyMessage = DOM.queryReactClass("message", this.getMessageOuterElement());
 | 
			
		||||
			const messageCount = anyMessage ? anyMessage.parentElement.children.length : 0;
 | 
			
		||||
			
 | 
			
		||||
			if (messageCount > 300) {
 | 
			
		||||
				if (waitForCleanup) {
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				skipsLeft = 3;
 | 
			
		||||
				waitForCleanup = true;
 | 
			
		||||
				
 | 
			
		||||
				window.setTimeout(() => {
 | 
			
		||||
					const view = this.getMessageScrollerElement();
 | 
			
		||||
					// noinspection JSUnusedGlobalSymbols
 | 
			
		||||
					view.scrollTop = view.scrollHeight / 2;
 | 
			
		||||
				}, 1);
 | 
			
		||||
			}
 | 
			
		||||
			else {
 | 
			
		||||
				waitForCleanup = false;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			const messages = this.getMessages();
 | 
			
		||||
			const hasChanged = messages.some(message => !previousMessages.has(message.id)) || !this.hasMoreMessages();
 | 
			
		||||
		const onMessageElementsChanged = function() {
 | 
			
		||||
			const messages = DISCORD.getMessages();
 | 
			
		||||
			const hasChanged = messages.some(message => !previousMessages.has(message.id)) || !DISCORD.hasMoreMessages();
 | 
			
		||||
			
 | 
			
		||||
			if (!hasChanged) {
 | 
			
		||||
				return;
 | 
			
		||||
@@ -79,24 +62,74 @@ class DISCORD {
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			callback(messages);
 | 
			
		||||
		}, 200);
 | 
			
		||||
		};
 | 
			
		||||
		
 | 
			
		||||
		window.DHT_ON_UNLOAD.push(() => window.clearInterval(timer));
 | 
			
		||||
		let debounceTimer;
 | 
			
		||||
		
 | 
			
		||||
		/**
 | 
			
		||||
		 * Do not trigger the callback too often due to autoscrolling.
 | 
			
		||||
		 */
 | 
			
		||||
		const onMessageElementsChangedLater = function() {
 | 
			
		||||
			window.clearTimeout(debounceTimer);
 | 
			
		||||
			debounceTimer = window.setTimeout(onMessageElementsChanged, 100);
 | 
			
		||||
		};
 | 
			
		||||
		
 | 
			
		||||
		const observer = new MutationObserver(function () {
 | 
			
		||||
			onMessageElementsChangedLater();
 | 
			
		||||
		});
 | 
			
		||||
		
 | 
			
		||||
		let skipsLeft = 0;
 | 
			
		||||
		let observedElement = null;
 | 
			
		||||
		
 | 
			
		||||
		const observerTimer = window.setInterval(() => {
 | 
			
		||||
			if (skipsLeft > 0) {
 | 
			
		||||
				--skipsLeft;
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			const view = this.getMessageOuterElement();
 | 
			
		||||
			
 | 
			
		||||
			if (!view) {
 | 
			
		||||
				skipsLeft = 1;
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			if (observedElement !== null && observedElement.isConnected) {
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			observedElement = view.querySelector("[data-list-id='chat-messages']");
 | 
			
		||||
			
 | 
			
		||||
			if (observedElement) {
 | 
			
		||||
				console.debug("[DHT] Observed message container.");
 | 
			
		||||
				observer.observe(observedElement, { childList: true });
 | 
			
		||||
				onMessageElementsChangedLater();
 | 
			
		||||
			}
 | 
			
		||||
		}, 400);
 | 
			
		||||
		
 | 
			
		||||
		window.DHT_ON_UNLOAD.push(() => {
 | 
			
		||||
			observer.disconnect();
 | 
			
		||||
			observedElement = null;
 | 
			
		||||
			window.clearInterval(observerTimer);
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Returns the property object of a message element.
 | 
			
		||||
	 * @returns { null | { message: DiscordMessage, channel: Object } }
 | 
			
		||||
	 * Returns the message from a message element.
 | 
			
		||||
	 * @returns { null | DiscordMessage } }
 | 
			
		||||
	 */
 | 
			
		||||
	static getMessageElementProps(ele) {
 | 
			
		||||
	static getMessageFromElement(ele) {
 | 
			
		||||
		const props = DOM.getReactProps(ele);
 | 
			
		||||
		
 | 
			
		||||
		if (props.children && props.children.length) {
 | 
			
		||||
			for (let i = 3; i < props.children.length; i++) {
 | 
			
		||||
				const childProps = props.children[i].props;
 | 
			
		||||
		if (props && Array.isArray(props.children)) {
 | 
			
		||||
			for (const child of props.children) {
 | 
			
		||||
				if (!(child instanceof Object)) {
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if (childProps && "message" in childProps && "channel" in childProps) {
 | 
			
		||||
					return childProps;
 | 
			
		||||
				const childProps = child.props;
 | 
			
		||||
				if (childProps instanceof Object && "message" in childProps) {
 | 
			
		||||
					return childProps.message;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -113,10 +146,10 @@ class DISCORD {
 | 
			
		||||
			
 | 
			
		||||
			for (const ele of this.getMessageElements()) {
 | 
			
		||||
				try {
 | 
			
		||||
					const props = this.getMessageElementProps(ele);
 | 
			
		||||
					const message = this.getMessageFromElement(ele);
 | 
			
		||||
					
 | 
			
		||||
					if (props != null) {
 | 
			
		||||
						messages.push(props.message);
 | 
			
		||||
					if (message != null) {
 | 
			
		||||
						messages.push(message);
 | 
			
		||||
					}
 | 
			
		||||
				} catch (e) {
 | 
			
		||||
					console.error("[DHT] Error extracing message data, skipping it.", e, ele, DOM.tryGetReactProps(ele));
 | 
			
		||||
@@ -137,7 +170,7 @@ class DISCORD {
 | 
			
		||||
	 */
 | 
			
		||||
	static getSelectedChannel() {
 | 
			
		||||
		try {
 | 
			
		||||
			let obj;
 | 
			
		||||
			let obj = null;
 | 
			
		||||
			
 | 
			
		||||
			try {
 | 
			
		||||
				for (const child of DOM.getReactProps(DOM.queryReactClass("chatContent")).children) {
 | 
			
		||||
@@ -148,15 +181,6 @@ class DISCORD {
 | 
			
		||||
				}
 | 
			
		||||
			} catch (e) {
 | 
			
		||||
				console.error("[DHT] Error retrieving selected channel from 'chatContent' element.", e);
 | 
			
		||||
				
 | 
			
		||||
				for (const ele of this.getMessageElements()) {
 | 
			
		||||
					const props = this.getMessageElementProps(ele);
 | 
			
		||||
					
 | 
			
		||||
					if (props != null) {
 | 
			
		||||
						obj = props.channel;
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			if (!obj || typeof obj.id !== "string") {
 | 
			
		||||
@@ -168,7 +192,7 @@ class DISCORD {
 | 
			
		||||
			if (dms) {
 | 
			
		||||
				let name;
 | 
			
		||||
				
 | 
			
		||||
				for (const ele of dms.querySelectorAll("[class*='channel-'] [class*='selected-'] [class^='name-'] *, [class*='channel-'][class*='selected-'] [class^='name-'] *")) {
 | 
			
		||||
				for (const ele of dms.querySelectorAll("[class*='channel_'] [class*='selected_'] [class^='name_'] *")) {
 | 
			
		||||
					const node = Array.prototype.find.call(ele.childNodes, node => node.nodeType === Node.TEXT_NODE);
 | 
			
		||||
					
 | 
			
		||||
					if (node) {
 | 
			
		||||
@@ -185,8 +209,8 @@ class DISCORD {
 | 
			
		||||
				
 | 
			
		||||
				// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
 | 
			
		||||
				switch (obj.type) {
 | 
			
		||||
					case 1: type = "DM"; break;
 | 
			
		||||
					case 3: type = "GROUP"; break;
 | 
			
		||||
					case DISCORD.CHANNEL_TYPE.DM: type = "DM"; break;
 | 
			
		||||
					case DISCORD.CHANNEL_TYPE.GROUP_DM: type = "GROUP"; break;
 | 
			
		||||
					default: return null;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
@@ -199,7 +223,7 @@ class DISCORD {
 | 
			
		||||
			else if (obj.guild_id) {
 | 
			
		||||
				let guild;
 | 
			
		||||
				
 | 
			
		||||
				for (const child of DOM.getReactProps(document.querySelector("nav header [class*='headerContent-']")).children) {
 | 
			
		||||
				for (const child of DOM.getReactProps(document.querySelector("nav header [class*='headerContent_']")).children) {
 | 
			
		||||
					if (child && child.props && child.props.guild) {
 | 
			
		||||
						guild = child.props.guild;
 | 
			
		||||
						break;
 | 
			
		||||
@@ -224,7 +248,7 @@ class DISCORD {
 | 
			
		||||
					}
 | 
			
		||||
				};
 | 
			
		||||
				
 | 
			
		||||
				if (obj.parent_id) {
 | 
			
		||||
				if (obj.type === DISCORD.CHANNEL_TYPE.ANNOUNCEMENT_THREAD || obj.type === DISCORD.CHANNEL_TYPE.PUBLIC_THREAD || obj.type === DISCORD.CHANNEL_TYPE.PRIVATE_THREAD) {
 | 
			
		||||
					channel["extra"]["parent"] = obj.parent_id;
 | 
			
		||||
				}
 | 
			
		||||
				else {
 | 
			
		||||
@@ -251,10 +275,10 @@ class DISCORD {
 | 
			
		||||
		
 | 
			
		||||
		if (dms) {
 | 
			
		||||
			const currentChannel = DOM.queryReactClass("selected", dms);
 | 
			
		||||
			const currentChannelContainer = currentChannel && currentChannel.closest("[class*='channel-']");
 | 
			
		||||
			const currentChannelContainer = currentChannel && currentChannel.closest("[class*='channel_']");
 | 
			
		||||
			const nextChannel = currentChannelContainer && currentChannelContainer.nextElementSibling;
 | 
			
		||||
			
 | 
			
		||||
			if (!nextChannel || !nextChannel.getAttribute("class").includes("channel-")) {
 | 
			
		||||
			if (!nextChannel || !nextChannel.getAttribute("class").includes("channel_")) {
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
@@ -281,7 +305,7 @@ class DISCORD {
 | 
			
		||||
			let nextChannel = null;
 | 
			
		||||
			
 | 
			
		||||
			for (let index = 0; index < allTextChannels.length - 1; index++) {
 | 
			
		||||
				if (allTextChannels[index].className.includes("selected-")) {
 | 
			
		||||
				if (allTextChannels[index].className.includes("selected_")) {
 | 
			
		||||
					nextChannel = allTextChannels[index + 1];
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ class DOM {
 | 
			
		||||
	 * Returns the first child element containing the specified obfuscated class. Parent defaults to the entire document.
 | 
			
		||||
	 */
 | 
			
		||||
	static queryReactClass(cls, parent) {
 | 
			
		||||
		return (parent || document).querySelector(`[class*="${cls}-"]`);
 | 
			
		||||
		return (parent || document).querySelector(`[class*="${cls}_"]`);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
@@ -86,12 +86,12 @@ const GUI = (function() {
 | 
			
		||||
<label><input id='dht-cfg-autoscroll' type='checkbox'> Autoscroll</label><br>
 | 
			
		||||
<br>
 | 
			
		||||
<label>After reaching the first message in channel...</label><br>
 | 
			
		||||
${radio("afm", "nothing", "Do Nothing")}
 | 
			
		||||
${radio("afm", "nothing", "Continue Tracking")}
 | 
			
		||||
${radio("afm", "pause", "Pause Tracking")}
 | 
			
		||||
${radio("afm", "switch", "Switch to Next Channel")}
 | 
			
		||||
<br>
 | 
			
		||||
<label>After reaching a previously saved message...</label><br>
 | 
			
		||||
${radio("asm", "nothing", "Do Nothing")}
 | 
			
		||||
${radio("asm", "nothing", "Continue Tracking")}
 | 
			
		||||
${radio("asm", "pause", "Pause Tracking")}
 | 
			
		||||
${radio("asm", "switch", "Switch to Next Channel")}
 | 
			
		||||
<p id='dht-cfg-note'>It is recommended to disable link and image previews to avoid putting unnecessary strain on your browser.</p>`;
 | 
			
		||||
 
 | 
			
		||||
@@ -174,18 +174,142 @@ const STATE = (function() {
 | 
			
		||||
		},
 | 
			
		||||
		
 | 
			
		||||
		/**
 | 
			
		||||
		 * @param {String} channelId
 | 
			
		||||
		 * @param {DiscordMessage[]} discordMessageArray
 | 
			
		||||
		 */
 | 
			
		||||
		async addDiscordMessages(channelId, discordMessageArray) {
 | 
			
		||||
			// https://discord.com/developers/docs/resources/channel#message-object-message-types
 | 
			
		||||
			discordMessageArray = discordMessageArray.filter(msg => msg.state === "SENT");
 | 
			
		||||
		async addDiscordMessages(discordMessageArray) {
 | 
			
		||||
			discordMessageArray = discordMessageArray.filter(msg => (msg.type === DISCORD.MESSAGE_TYPE.DEFAULT || msg.type === DISCORD.MESSAGE_TYPE.REPLY || msg.type === DISCORD.MESSAGE_TYPE.THREAD_STARTER) && msg.state === "SENT");
 | 
			
		||||
			
 | 
			
		||||
			if (discordMessageArray.length === 0) {
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			const response = await post("/track-messages", JSON.stringify(discordMessageArray));
 | 
			
		||||
			const userInfo = {};
 | 
			
		||||
			let hasNewUsers = false;
 | 
			
		||||
			
 | 
			
		||||
			for (const msg of discordMessageArray) {
 | 
			
		||||
				const user = msg.author;
 | 
			
		||||
				
 | 
			
		||||
				if (!addedUsers.has(user.id)) {
 | 
			
		||||
					const obj = {
 | 
			
		||||
						id: user.id,
 | 
			
		||||
						name: user.username
 | 
			
		||||
					};
 | 
			
		||||
					
 | 
			
		||||
					if (user.avatar) {
 | 
			
		||||
						obj.avatar = user.avatar;
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					if (!user.bot) {
 | 
			
		||||
						// noinspection JSUnusedGlobalSymbols
 | 
			
		||||
						obj.discriminator = user.discriminator;
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					userInfo[user.id] = obj;
 | 
			
		||||
					hasNewUsers = true;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			if (hasNewUsers) {
 | 
			
		||||
				await post("/track-users", Object.values(userInfo));
 | 
			
		||||
				
 | 
			
		||||
				for (const id of Object.keys(userInfo)) {
 | 
			
		||||
					addedUsers.add(id);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			const response = await post("/track-messages", discordMessageArray.map(msg => {
 | 
			
		||||
				const obj = {
 | 
			
		||||
					id: msg.id,
 | 
			
		||||
					sender: msg.author.id,
 | 
			
		||||
					channel: msg.channel_id,
 | 
			
		||||
					text: msg.content,
 | 
			
		||||
					timestamp: msg.timestamp.toDate().getTime()
 | 
			
		||||
				};
 | 
			
		||||
				
 | 
			
		||||
				if (msg.editedTimestamp !== null) {
 | 
			
		||||
					// noinspection JSUnusedGlobalSymbols
 | 
			
		||||
					obj.editTimestamp = msg.editedTimestamp.toDate().getTime();
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if (msg.messageReference !== null) {
 | 
			
		||||
					// noinspection JSUnusedGlobalSymbols
 | 
			
		||||
					obj.repliedToId = msg.messageReference.message_id;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if (msg.attachments.length > 0) {
 | 
			
		||||
					obj.attachments = msg.attachments.map(attachment => {
 | 
			
		||||
						const mapped = {
 | 
			
		||||
							id: attachment.id,
 | 
			
		||||
							name: attachment.filename,
 | 
			
		||||
							size: attachment.size,
 | 
			
		||||
							url: attachment.url
 | 
			
		||||
						};
 | 
			
		||||
						
 | 
			
		||||
						if (attachment.content_type) {
 | 
			
		||||
							mapped.type = attachment.content_type;
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						if (attachment.width && attachment.height) {
 | 
			
		||||
							mapped.width = attachment.width;
 | 
			
		||||
							mapped.height = attachment.height;
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						return mapped;
 | 
			
		||||
					});
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if (msg.embeds.length > 0) {
 | 
			
		||||
					obj.embeds = msg.embeds.map(embed => {
 | 
			
		||||
						const mapped = {};
 | 
			
		||||
						
 | 
			
		||||
						for (const key of Object.keys(embed)) {
 | 
			
		||||
							if (key === "id") {
 | 
			
		||||
								continue;
 | 
			
		||||
							}
 | 
			
		||||
							
 | 
			
		||||
							if (key === "rawTitle") {
 | 
			
		||||
								mapped["title"] = embed[key];
 | 
			
		||||
							}
 | 
			
		||||
							else if (key === "rawDescription") {
 | 
			
		||||
								mapped["description"] = embed[key];
 | 
			
		||||
							}
 | 
			
		||||
							else {
 | 
			
		||||
								mapped[key] = embed[key];
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						return JSON.stringify(mapped);
 | 
			
		||||
					});
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if (msg.reactions.length > 0) {
 | 
			
		||||
					obj.reactions = msg.reactions.map(reaction => {
 | 
			
		||||
						const emoji = reaction.emoji;
 | 
			
		||||
						
 | 
			
		||||
						const mapped = {
 | 
			
		||||
							count: reaction.count
 | 
			
		||||
						};
 | 
			
		||||
						
 | 
			
		||||
						if (emoji.id) {
 | 
			
		||||
							mapped.id = emoji.id;
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						if (emoji.name) {
 | 
			
		||||
							mapped.name = emoji.name;
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						if (emoji.animated) {
 | 
			
		||||
							// noinspection JSUnusedGlobalSymbols
 | 
			
		||||
							mapped.isAnimated = emoji.animated;
 | 
			
		||||
						}
 | 
			
		||||
						
 | 
			
		||||
						return mapped;
 | 
			
		||||
					});
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				return obj;
 | 
			
		||||
			}));
 | 
			
		||||
			
 | 
			
		||||
			const anyNewMessages = await response.text();
 | 
			
		||||
			return anyNewMessages === "1";
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,8 @@
 | 
			
		||||
const DISCORD = (function() {
 | 
			
		||||
	const regex = {
 | 
			
		||||
		formatBold: /\*\*([\s\S]+?)\*\*(?!\*)/g,
 | 
			
		||||
		formatItalic: /(.)?([_*])([\s\S]+?)\2(?!\2)/g,
 | 
			
		||||
		formatItalic1: /\*([\s\S]+?)\*(?!\*)/g,
 | 
			
		||||
		formatItalic2: /_([\s\S]+?)_(?!_)\b/g,
 | 
			
		||||
		formatUnderline: /__([\s\S]+?)__(?!_)/g,
 | 
			
		||||
		formatStrike: /~~([\s\S]+?)~~(?!~)/g,
 | 
			
		||||
		formatCodeInline: /(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/g,
 | 
			
		||||
@@ -48,7 +49,8 @@ const DISCORD = (function() {
 | 
			
		||||
				.replace(regex.specialEscapedDouble, full => full.replace(/\\/g, "").replace(/(.)/g, escapeHtmlMatch))
 | 
			
		||||
				.replace(regex.formatBold, "<b>$1</b>")
 | 
			
		||||
				.replace(regex.formatUnderline, "<u>$1</u>")
 | 
			
		||||
				.replace(regex.formatItalic, (full, pre, char, match) => pre === "\\" ? full : (pre || "") + "<i>" + match + "</i>")
 | 
			
		||||
				.replace(regex.formatItalic1, "<i>$1</i>")
 | 
			
		||||
				.replace(regex.formatItalic2, "<i>$1</i>")
 | 
			
		||||
				.replace(regex.formatStrike, "<s>$1</s>");
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -1,27 +0,0 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
import glob
 | 
			
		||||
import os
 | 
			
		||||
import shutil
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
if os.name == "nt":
 | 
			
		||||
    uglifyjs = os.path.abspath("../../lib/uglifyjs.cmd")
 | 
			
		||||
else:
 | 
			
		||||
    uglifyjs = "uglifyjs"
 | 
			
		||||
 | 
			
		||||
if shutil.which(uglifyjs) is None:
 | 
			
		||||
    print("Cannot find executable: {0}".format(uglifyjs))
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
input_dir = os.path.abspath("./Tracker/scripts")
 | 
			
		||||
output_dir = os.path.abspath("../Desktop/bin/.res/scripts")
 | 
			
		||||
 | 
			
		||||
os.makedirs(output_dir, exist_ok=True)
 | 
			
		||||
 | 
			
		||||
for file in glob.glob(input_dir + "/*.js"):
 | 
			
		||||
    name = os.path.basename(file)
 | 
			
		||||
    print("Minifying {0}...".format(name))
 | 
			
		||||
    os.system("{0} {1} -o {2}/{3}".format(uglifyjs, file, output_dir, name))
 | 
			
		||||
 | 
			
		||||
print("Done!")
 | 
			
		||||
							
								
								
									
										15
									
								
								app/Server/Data/Aggregations/DownloadStatusStatistics.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/Server/Data/Aggregations/DownloadStatusStatistics.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
namespace DHT.Server.Data.Aggregations;
 | 
			
		||||
 | 
			
		||||
public sealed class DownloadStatusStatistics {
 | 
			
		||||
	public int EnqueuedCount { get; internal set; }
 | 
			
		||||
	public ulong EnqueuedSize { get; internal set; }
 | 
			
		||||
 | 
			
		||||
	public int SuccessfulCount { get; internal set; }
 | 
			
		||||
	public ulong SuccessfulSize { get; internal set; }
 | 
			
		||||
 | 
			
		||||
	public int FailedCount { get; internal set; }
 | 
			
		||||
	public ulong FailedSize { get; internal set; }
 | 
			
		||||
 | 
			
		||||
	public int SkippedCount { get; internal set; }
 | 
			
		||||
	public ulong SkippedSize { get; internal set; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								app/Server/Data/Attachment.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/Server/Data/Attachment.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Attachment {
 | 
			
		||||
	public ulong Id { get; internal init; }
 | 
			
		||||
	public string Name { get; internal init; }
 | 
			
		||||
	public string? Type { get; internal init; }
 | 
			
		||||
	public string NormalizedUrl { get; internal init; }
 | 
			
		||||
	public string DownloadUrl { get; internal init; }
 | 
			
		||||
	public ulong Size { get; internal init; }
 | 
			
		||||
	public int? Width { get; internal init; }
 | 
			
		||||
	public int? Height { get; internal init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								app/Server/Data/Channel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								app/Server/Data/Channel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Channel {
 | 
			
		||||
	public ulong Id { get; init; }
 | 
			
		||||
	public ulong Server { get; init; }
 | 
			
		||||
	public string Name { get; init; }
 | 
			
		||||
	public ulong? ParentId { get; init; }
 | 
			
		||||
	public int? Position { get; init; }
 | 
			
		||||
	public string? Topic { get; init; }
 | 
			
		||||
	public bool? Nsfw { get; init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								app/Server/Data/Download.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/Server/Data/Download.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Net;
 | 
			
		||||
using DHT.Server.Download;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Download {
 | 
			
		||||
	internal static Download NewSuccess(DownloadItem item, byte[] data) {
 | 
			
		||||
		return new Download(item.NormalizedUrl, item.DownloadUrl, DownloadStatus.Success, (ulong) Math.Max(data.LongLength, 0), data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	internal static Download NewFailure(DownloadItem item, HttpStatusCode? statusCode, ulong size) {
 | 
			
		||||
		return new Download(item.NormalizedUrl, item.DownloadUrl, statusCode.HasValue ? (DownloadStatus) (int) statusCode : DownloadStatus.GenericError, size);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public string NormalizedUrl { get; }
 | 
			
		||||
	public string DownloadUrl { get; }
 | 
			
		||||
	public DownloadStatus Status { get; }
 | 
			
		||||
	public ulong Size { get; }
 | 
			
		||||
	public byte[]? Data { get; }
 | 
			
		||||
 | 
			
		||||
	internal Download(string normalizedUrl, string downloadUrl, DownloadStatus status, ulong size, byte[]? data = null) {
 | 
			
		||||
		NormalizedUrl = normalizedUrl;
 | 
			
		||||
		DownloadUrl = downloadUrl;
 | 
			
		||||
		Status = status;
 | 
			
		||||
		Size = size;
 | 
			
		||||
		Data = data;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	internal Download WithData(byte[] data) {
 | 
			
		||||
		return new Download(NormalizedUrl, DownloadUrl, Status, Size, data);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								app/Server/Data/DownloadStatus.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/Server/Data/DownloadStatus.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
using System.Net;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// Extends <see cref="HttpStatusCode"/> with custom status codes in the range 0-99.
 | 
			
		||||
/// </summary>
 | 
			
		||||
public enum DownloadStatus {
 | 
			
		||||
	Enqueued = 0,
 | 
			
		||||
	GenericError = 1,
 | 
			
		||||
	Success = HttpStatusCode.OK
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								app/Server/Data/DownloadedAttachment.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								app/Server/Data/DownloadedAttachment.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct DownloadedAttachment {
 | 
			
		||||
	public string? Type { get; internal init; }
 | 
			
		||||
	public byte[] Data { get; internal init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								app/Server/Data/Embed.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/Server/Data/Embed.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Embed {
 | 
			
		||||
	public string Json { get; internal init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								app/Server/Data/EmojiFlags.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								app/Server/Data/EmojiFlags.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
[Flags]
 | 
			
		||||
public enum EmojiFlags : ushort {
 | 
			
		||||
	None = 0,
 | 
			
		||||
	Animated = 0b1
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								app/Server/Data/Filters/AttachmentFilter.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/Server/Data/Filters/AttachmentFilter.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
namespace DHT.Server.Data.Filters;
 | 
			
		||||
 | 
			
		||||
public sealed class AttachmentFilter {
 | 
			
		||||
	public ulong? MaxBytes { get; set; } = null;
 | 
			
		||||
 | 
			
		||||
	public DownloadItemRules? DownloadItemRule { get; set; } = null;
 | 
			
		||||
 | 
			
		||||
	public bool IsEmpty => MaxBytes == null &&
 | 
			
		||||
	                       DownloadItemRule == null;
 | 
			
		||||
 | 
			
		||||
	public enum DownloadItemRules {
 | 
			
		||||
		OnlyNotPresent,
 | 
			
		||||
		OnlyPresent
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								app/Server/Data/Filters/DownloadItemFilter.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								app/Server/Data/Filters/DownloadItemFilter.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Server.Data.Filters;
 | 
			
		||||
 | 
			
		||||
public sealed class DownloadItemFilter {
 | 
			
		||||
	public HashSet<DownloadStatus>? IncludeStatuses { get; init; } = null;
 | 
			
		||||
	public HashSet<DownloadStatus>? ExcludeStatuses { get; init; } = null;
 | 
			
		||||
 | 
			
		||||
	public bool IsEmpty => IncludeStatuses == null && ExcludeStatuses == null;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								app/Server/Data/Filters/FilterRemovalMode.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								app/Server/Data/Filters/FilterRemovalMode.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
namespace DHT.Server.Data.Filters;
 | 
			
		||||
 | 
			
		||||
public enum FilterRemovalMode {
 | 
			
		||||
	KeepMatching,
 | 
			
		||||
	RemoveMatching
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								app/Server/Data/Filters/MessageFilter.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								app/Server/Data/Filters/MessageFilter.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Server.Data.Filters;
 | 
			
		||||
 | 
			
		||||
public sealed class MessageFilter {
 | 
			
		||||
	public DateTime? StartDate { get; set; } = null;
 | 
			
		||||
	public DateTime? EndDate { get; set; } = null;
 | 
			
		||||
 | 
			
		||||
	public HashSet<ulong>? ChannelIds { get; set; } = null;
 | 
			
		||||
	public HashSet<ulong>? UserIds { get; set; } = null;
 | 
			
		||||
	public HashSet<ulong>? MessageIds { get; set; } = null;
 | 
			
		||||
 | 
			
		||||
	public bool IsEmpty => StartDate == null &&
 | 
			
		||||
	                       EndDate == null &&
 | 
			
		||||
	                       ChannelIds == null &&
 | 
			
		||||
	                       UserIds == null &&
 | 
			
		||||
	                       MessageIds == null;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								app/Server/Data/Message.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								app/Server/Data/Message.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
using System.Collections.Immutable;
 | 
			
		||||
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Message {
 | 
			
		||||
	public ulong Id { get; init; }
 | 
			
		||||
	public ulong Sender { get; init; }
 | 
			
		||||
	public ulong Channel { get; init; }
 | 
			
		||||
	public string Text { get; init; }
 | 
			
		||||
	public long Timestamp { get; init; }
 | 
			
		||||
	public long? EditTimestamp { get; init; }
 | 
			
		||||
	public ulong? RepliedToId { get; init; }
 | 
			
		||||
	public ImmutableArray<Attachment> Attachments { get; init; }
 | 
			
		||||
	public ImmutableArray<Embed> Embeds { get; init; }
 | 
			
		||||
	public ImmutableArray<Reaction> Reactions { get; init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								app/Server/Data/Reaction.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/Server/Data/Reaction.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Reaction {
 | 
			
		||||
	public ulong? EmojiId { get; internal init; }
 | 
			
		||||
	public string? EmojiName { get; internal init; }
 | 
			
		||||
	public EmojiFlags EmojiFlags { get; internal init; }
 | 
			
		||||
	public int Count { get; internal init; }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								app/Server/Data/Server.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/Server/Data/Server.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
namespace DHT.Server.Data;
 | 
			
		||||
 | 
			
		||||
public readonly struct Server {
 | 
			
		||||
	public ulong Id { get; init; }
 | 
			
		||||
	public string Name { get; init; }
 | 
			
		||||
	public ServerType? Type { get; init; }
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user