From df5fe7c86e41235f99a9b0d69519a18581eddd5e Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 8 Aug 2024 02:57:34 +0200 Subject: Further work --- .../UserManagement/UserManagementViewModel.cs | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 ModerationClient/ViewModels/UserManagement/UserManagementViewModel.cs (limited to 'ModerationClient/ViewModels/UserManagement/UserManagementViewModel.cs') diff --git a/ModerationClient/ViewModels/UserManagement/UserManagementViewModel.cs b/ModerationClient/ViewModels/UserManagement/UserManagementViewModel.cs new file mode 100644 index 0000000..7a2ad63 --- /dev/null +++ b/ModerationClient/ViewModels/UserManagement/UserManagementViewModel.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; +using ArcaneLibs.Collections; +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec.State; +using LibMatrix.Helpers; +using LibMatrix.Homeservers; +using LibMatrix.Homeservers.ImplementationDetails.Synapse.Models.Responses; +using LibMatrix.Responses; +using MatrixUtils.Abstractions; +using Microsoft.Extensions.Logging; +using ModerationClient.Services; + +namespace ModerationClient.ViewModels; + +public partial class UserManagementViewModel : ViewModelBase { + public UserManagementViewModel(ILogger logger, MatrixAuthenticationService authService, CommandLineConfiguration cfg) { + _logger = logger; + _authService = authService; + _cfg = cfg; + _ = Task.Run(Run).ContinueWith(x=>x.Exception?.Handle(y=> { + Console.WriteLine(y); + return true; + })); + } + + private readonly ILogger _logger; + private readonly MatrixAuthenticationService _authService; + private readonly CommandLineConfiguration _cfg; + private string _status = "Loading..."; + public ObservableCollection Users { get; set; } = []; + + public string Status { + get => _status + " " + DateTime.Now; + set => SetProperty(ref _status, value); + } + + public async Task Run() { + Users.Clear(); + Status = "Doing initial sync..."; + if (_authService.Homeserver is not AuthenticatedHomeserverSynapse synapse) { + Console.WriteLine("This client only supports Synapse homeservers."); + return; + } + + await foreach (var user in synapse.Admin.SearchUsersAsync(chunkLimit: 100)) { + Console.WriteLine("USERMANAGER GOT USER: " + user.ToJson(indent:false, ignoreNull: true)); + Users.Add(JsonSerializer.Deserialize(user.ToJson())!); + } + Console.WriteLine("Done."); + } +} + +public class User : AdminUserListResult.AdminUserListResultUser { + +} \ No newline at end of file -- cgit 1.5.1