aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-02-23 09:53:16 -0600
committerJP Dillingham <jpdillingham@gmail.com>2022-02-23 09:53:16 -0600
commit1955417f467bf9eda4ec9c897dcefb50b43c99ff (patch)
tree7b2ba1b9fedbba9400596d975b9d4fd8db0d86ff /src
parent2b850c11f8f7e18ed35afa6344743decc82f7faf (diff)
downloadslskd-1955417f467bf9eda4ec9c897dcefb50b43c99ff.tar.gz
drop tracked users on disconnect, force reconfig on login
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Users/UserService.cs20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/slskd/Users/UserService.cs b/src/slskd/Users/UserService.cs
index 58b14cec..3c3b6508 100644
--- a/src/slskd/Users/UserService.cs
+++ b/src/slskd/Users/UserService.cs
@@ -56,7 +56,7 @@ namespace slskd.Users
ContextFactory = contextFactory;
OptionsMonitor = optionsMonitor;
- OptionsMonitor.OnChange(Configure);
+ OptionsMonitor.OnChange(options => Configure(options));
BindClientEvents();
Configure(OptionsMonitor.CurrentValue);
@@ -252,29 +252,23 @@ namespace slskd.Users
_ = GetStatisticsAsync(userStatus.Username);
};
- Client.LoggedIn += (_, _) => WatchAllUsers();
+ Client.LoggedIn += (_, _) => Configure(OptionsMonitor.CurrentValue, force: true);
Client.Disconnected += (_, _) =>
{
// when the client is disconnected, the watched user list resets server-side,
- // so clear the watched dictionary to reflect this
+ // so clear the state to reflect this
WatchedUsernamesDictionary.Clear();
+ UserDictionary.Clear();
- // over the course of operation the application will watch users which are not explicitly
- // configured as they enqueue uploads. these are considered transiently-tracked users,
- // and we want to discard them upon disconnect to avoid re-watching them when the client
- // is reconnected. to do this, purge the user dictionary of any entry lacking an explicit group.
- foreach (var user in UserDictionary.Values.Where(user => user.Group == null))
- {
- UserDictionary.TryRemove(user.Username, out _);
- }
+ StateMutator.SetValue(state => state with { Users = Users.ToArray() });
};
}
- private void Configure(Options options)
+ private void Configure(Options options, bool force = false)
{
var optionsHash = Compute.Sha1Hash(options.Groups.UserDefined.ToJson());
- if (optionsHash == LastOptionsHash)
+ if (optionsHash == LastOptionsHash && !force)
{
return;
}