< Summary

Class:DCL.Chat.Channels.ChannelsFeatureFlagService
Assembly:ChatController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChannelsFeatureFlagService.cs
Covered lines:21
Uncovered lines:7
Coverable lines:28
Total lines:78
Line coverage:75% (21 of 28)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ChannelsFeatureFlagService(...)0%110100%
Dispose()0%110100%
Initialize()0%110100%
IsChannelsFeatureEnabled()0%110100%
OnUserProfileUpdate(...)0%3.143075%
IsAllowedToCreateChannels()0%12.638058.33%
IsPromoteChannelsToastEnabled()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChannelsFeatureFlagService.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using UnityEngine;
 4
 5namespace DCL.Chat.Channels
 6{
 7    public class ChannelsFeatureFlagService : IChannelsFeatureFlagService
 8    {
 9        private const string FEATURE_FLAG_FOR_CHANNELS_FEATURE = "matrix_channels_enabled";
 10        private const string FEATURE_FLAG_FOR_USERS_ALLOWED_TO_CREATE_CHANNELS = "users_allowed_to_create_channels";
 11        private const string VARIANT_FOR_USERS_ALLOWED_TO_CREATE_CHANNELS = "allowedUsers";
 12        private const string FEATURE_FLAG_FOR_PROMOTE_CHANNELS_TOAST = "promote_channels_toast";
 13
 514        private BaseVariable<FeatureFlag> featureFlags => dataStore.featureFlags.flags;
 15
 16        private readonly DataStore dataStore;
 17        private readonly IUserProfileBridge userProfileBridge;
 18
 19        public event Action<bool> OnAllowedToCreateChannelsChanged;
 20
 66921        public ChannelsFeatureFlagService(DataStore dataStore, IUserProfileBridge userProfileBridge)
 22        {
 66923            this.dataStore = dataStore;
 66924            this.userProfileBridge = userProfileBridge;
 66925        }
 26
 27        public void Dispose()
 28        {
 66929            userProfileBridge.GetOwn().OnUpdate -= OnUserProfileUpdate;
 66930        }
 31
 32        public void Initialize()
 33        {
 66834            userProfileBridge.GetOwn().OnUpdate += OnUserProfileUpdate;
 66835        }
 36
 237        public bool IsChannelsFeatureEnabled() => featureFlags.Get().IsFeatureEnabled(FEATURE_FLAG_FOR_CHANNELS_FEATURE)
 38
 39        private void OnUserProfileUpdate(UserProfile profile)
 40        {
 741            if (string.IsNullOrEmpty(profile.userId))
 142                return;
 43
 644            OnAllowedToCreateChannelsChanged?.Invoke(IsAllowedToCreateChannels());
 045        }
 46
 47        public bool IsAllowedToCreateChannels()
 48        {
 149            if (!featureFlags.Get().IsFeatureEnabled(FEATURE_FLAG_FOR_USERS_ALLOWED_TO_CREATE_CHANNELS))
 050                return false;
 51
 152            FeatureFlagVariantPayload usersAllowedToCreateChannelsPayload = featureFlags
 53                .Get()
 54                .GetFeatureFlagVariantPayload($"{FEATURE_FLAG_FOR_USERS_ALLOWED_TO_CREATE_CHANNELS}:{VARIANT_FOR_USERS_A
 55
 156            if (usersAllowedToCreateChannelsPayload == null)
 057                return false;
 58
 159            UsersAllowedToCreateChannelsVariantPayload allowedUsersData = JsonUtility.FromJson<UsersAllowedToCreateChann
 160            UserProfile ownUserProfile = userProfileBridge.GetOwn();
 61
 162            switch (allowedUsersData.mode)
 63            {
 64                case AllowChannelsCreationMode.ALLOWLIST:
 165                    return allowedUsersData.allowList != null
 066                           && allowedUsersData.allowList.Any(userId => userId?.ToLower() == ownUserProfile.userId.ToLowe
 67                case AllowChannelsCreationMode.NAMES:
 068                    return ownUserProfile.hasClaimedName;
 69                case AllowChannelsCreationMode.WALLET:
 070                    return !ownUserProfile.isGuest;
 71            }
 72
 073            return true;
 74        }
 75
 176        public bool IsPromoteChannelsToastEnabled() => featureFlags.Get().IsFeatureEnabled(FEATURE_FLAG_FOR_PROMOTE_CHAN
 77    }
 78}