about summary refs log tree commit diff
path: root/ModerationClient/ViewModels/UserManagement/UserManagementViewModel.cs
blob: 7a2ad63cd552c9e85dbaf0eaf741c8c36e8db995 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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<UserManagementViewModel> 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<UserManagementViewModel> _logger;
    private readonly MatrixAuthenticationService _authService;
    private readonly CommandLineConfiguration _cfg;
    private string _status = "Loading...";
    public ObservableCollection<User> 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>(user.ToJson())!);
        }
        Console.WriteLine("Done.");
    }
}

public class User : AdminUserListResult.AdminUserListResultUser {
    
}