<commit_before>using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Wukong.Models;

namespace Wukong.Services
{
    public interface IChannelManager
    {
        void JoinAndLeavePreviousChannel(string channelId, string userId);
        void Leave(string userId);
    }
    public class ChannelManager : IChannelManager
    {
        private readonly ILogger Logger;
        private readonly IStorage Storage;
        private readonly ISocketManager SocketManager;
        private readonly IProvider Provider;
        private readonly IUserManager UserManager;

        public ChannelManager(ILoggerFactory loggerFactory, IStorage storage, ISocketManager socketManager, IProvider provider, IUserManager userManager)
        {
            Logger = loggerFactory.CreateLogger<ChannelManager>();
            Storage = storage;
            Provider = provider;
            SocketManager = socketManager;
            UserManager = userManager;
            UserManager.UserConnected += UserConnected;
            UserManager.UserTimeout += UserTimeout;
        }

        public void JoinAndLeavePreviousChannel(string channelId, string userId)
        {
            if (channelId == Storage.GetChannelByUser(userId)?.Id) return;
            Leave(userId);
            var channel = Storage.GetOrCreateChannel(channelId, SocketManager, Provider, UserManager);
            channel.Join(userId);
        }

        public void Leave(string userId)
        {
            var channel = Storage.GetChannelByUser(userId);
            channel?.Leave(userId);
            if (channel == null || !channel.Empty) return;
            Logger.LogInformation($"Channel {channel.Id} removed.");<commit_msg>fix: state machine join not called<commit_after>using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Wukong.Models;

namespace Wukong.Services
{
    public interface IChannelManager
    {
        void JoinAndLeavePreviousChannel(string channelId, string userId);
        void Leave(string userId);
    }
    public class ChannelManager : IChannelManager
    {
        private readonly ILogger Logger;
        private readonly IStorage Storage;
        private readonly ISocketManager SocketManager;
        private readonly IProvider Provider;
        private readonly IUserManager UserManager;

        public ChannelManager(ILoggerFactory loggerFactory, IStorage storage, ISocketManager socketManager, IProvider provider, IUserManager userManager)
        {
            Logger = loggerFactory.CreateLogger<ChannelManager>();
            Storage = storage;
            Provider = provider;
            SocketManager = socketManager;
            UserManager = userManager;
            UserManager.UserConnected += UserConnected;
            UserManager.UserTimeout += UserTimeout;
        }

        public void JoinAndLeavePreviousChannel(string channelId, User user)
        {
            if (channelId == Storage.GetChannelByUser(user.Id)?.Id) return;
            Leave(user.Id);
            var channel = Storage.GetOrCreateChannel(channelId, SocketManager, Provider, UserManager);
            channel.Join(user.Id);
            user.Join();
        }

        public void Leave(string userId)
        {
            var channel = Storage.GetChannelByUser(userId);
            channel?.Leave(userId);
            if (channel == null || !channel.Empty) return;
            Logger.LogInformation($"Channel {channel.Id} removed.");
{'fraction_non_alphanumeric': 0.07304153889043768, 'fraction_numerical': 0.0, 'mean_word_length': 2.7104446742502586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5879023', 'n_tokens_mistral': 837, 'n_tokens_neox': 838, 'n_words': 217}