< Summary

Class:DCL.Social.Chat.WebInterfaceChatBridge
Assembly:ChatController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/WebInterfaceChatBridge.cs
Covered lines:0
Uncovered lines:40
Coverable lines:40
Total lines:139
Line coverage:0% (0 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
InitializeChat(...)0%6200%
AddMessageToChatWindow(...)0%6200%
AddChatMessages(...)0%12300%
UpdateTotalUnseenMessages(...)0%6200%
UpdateUserUnseenMessages(...)0%6200%
UpdateTotalUnseenMessagesByUser(...)0%12300%
UpdateTotalUnseenMessagesByChannel(...)0%12300%
UpdateChannelMembers(...)0%6200%
JoinChannelConfirmation(...)0%6200%
JoinChannelError(...)0%6200%
LeaveChannelError(...)0%6200%
UpdateChannelInfo(...)0%6200%
MuteChannelError(...)0%6200%
UpdateChannelSearchResults(...)0%6200%
LeaveChannel(...)0%2100%
GetChannelMessages(...)0%2100%
JoinOrCreateChannel(...)0%2100%
GetJoinedChannels(...)0%2100%
GetChannels(...)0%2100%
MuteChannel(...)0%2100%
GetPrivateMessages(...)0%2100%
MarkChannelMessagesAsSeen(...)0%2100%
GetUnseenMessagesByUser()0%2100%
GetUnseenMessagesByChannel()0%2100%
CreateChannel(...)0%2100%
GetChannelInfo(...)0%2100%
GetChannelMembers(...)0%2100%
SendChatMessage(...)0%2100%
MarkMessagesAsSeen(...)0%2100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Linq;
 3using DCL.Chat.Channels;
 4using DCL.Chat.WebApi;
 5using DCL.Interface;
 6using JetBrains.Annotations;
 7using UnityEngine;
 8
 9namespace DCL.Social.Chat
 10{
 11    public class WebInterfaceChatBridge : MonoBehaviour, IChatApiBridge
 12    {
 13        public event Action<InitializeChatPayload> OnInitialized;
 14        public event Action<ChatMessage[]> OnAddMessage;
 15        public event Action<UpdateTotalUnseenMessagesPayload> OnTotalUnseenMessagesChanged;
 16        public event Action<(string userId, int count)[]> OnUserUnseenMessagesChanged;
 17        public event Action<(string channelId, int count)[]> OnChannelUnseenMessagesChanged;
 18        public event Action<UpdateChannelMembersPayload> OnChannelMembersUpdated;
 19        public event Action<ChannelInfoPayloads> OnChannelJoined;
 20        public event Action<JoinChannelErrorPayload> OnChannelJoinFailed;
 21        public event Action<JoinChannelErrorPayload> OnChannelLeaveFailed;
 22        public event Action<ChannelInfoPayloads> OnChannelsUpdated;
 23        public event Action<MuteChannelErrorPayload> OnMuteChannelFailed;
 24        public event Action<ChannelSearchResultsPayload> OnChannelSearchResults;
 25
 26        [PublicAPI]
 27        public void InitializeChat(string json) =>
 028            OnInitialized?.Invoke(JsonUtility.FromJson<InitializeChatPayload>(json));
 29
 30        [PublicAPI]
 31        public void AddMessageToChatWindow(string jsonMessage) =>
 032            OnAddMessage?.Invoke(new[] {JsonUtility.FromJson<ChatMessage>(jsonMessage)});
 33
 34        [PublicAPI]
 35        public void AddChatMessages(string jsonMessage)
 36        {
 037            var msg = JsonUtility.FromJson<ChatMessageListPayload>(jsonMessage);
 038            if (msg == null) return;
 039            OnAddMessage?.Invoke(msg.messages);
 040        }
 41
 42        [PublicAPI]
 43        public void UpdateTotalUnseenMessages(string json) =>
 044            OnTotalUnseenMessagesChanged?.Invoke(JsonUtility.FromJson<UpdateTotalUnseenMessagesPayload>(json));
 45
 46        [PublicAPI]
 47        public void UpdateUserUnseenMessages(string json)
 48        {
 049            var msg = JsonUtility.FromJson<UpdateUserUnseenMessagesPayload>(json);
 050            OnUserUnseenMessagesChanged?.Invoke(new[] {(msg.userId, msg.total)});
 051        }
 52
 53        [PublicAPI]
 54        public void UpdateTotalUnseenMessagesByUser(string json)
 55        {
 056            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesByUserPayload>(json);
 057            OnUserUnseenMessagesChanged?.Invoke(msg.unseenPrivateMessages
 058                .Select(unseenMessages => (unseenMessages.userId, unseenMessages.count))
 59                .ToArray());
 060        }
 61
 62        [PublicAPI]
 63        public void UpdateTotalUnseenMessagesByChannel(string json)
 64        {
 065            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesByChannelPayload>(json);
 066            OnChannelUnseenMessagesChanged?.Invoke(msg.unseenChannelMessages
 067                .Select(message => (message.channelId, message.count))
 68                .ToArray());
 069        }
 70
 71        [PublicAPI]
 72        public void UpdateChannelMembers(string json) =>
 073            OnChannelMembersUpdated?.Invoke(JsonUtility.FromJson<UpdateChannelMembersPayload>(json));
 74
 75        [PublicAPI]
 76        public void JoinChannelConfirmation(string payload) =>
 077            OnChannelJoined?.Invoke(JsonUtility.FromJson<ChannelInfoPayloads>(payload));
 78
 79        [PublicAPI]
 80        public void JoinChannelError(string payload) =>
 081            OnChannelJoinFailed?.Invoke(JsonUtility.FromJson<JoinChannelErrorPayload>(payload));
 82
 83        [PublicAPI]
 84        public void LeaveChannelError(string payload) =>
 085            OnChannelLeaveFailed?.Invoke(JsonUtility.FromJson<JoinChannelErrorPayload>(payload));
 86
 87        [PublicAPI]
 88        public void UpdateChannelInfo(string payload) =>
 089            OnChannelsUpdated?.Invoke(JsonUtility.FromJson<ChannelInfoPayloads>(payload));
 90
 91        [PublicAPI]
 92        public void MuteChannelError(string payload) =>
 093            OnMuteChannelFailed?.Invoke(JsonUtility.FromJson<MuteChannelErrorPayload>(payload));
 94
 95        [PublicAPI]
 96        public void UpdateChannelSearchResults(string payload) =>
 097            OnChannelSearchResults?.Invoke(JsonUtility.FromJson<ChannelSearchResultsPayload>(payload));
 98
 099        public void LeaveChannel(string channelId) => WebInterface.LeaveChannel(channelId);
 100
 101        public void GetChannelMessages(string channelId, int limit, string fromMessageId) =>
 0102            WebInterface.GetChannelMessages(channelId, limit, fromMessageId);
 103
 0104        public void JoinOrCreateChannel(string channelId) => WebInterface.JoinOrCreateChannel(channelId);
 105
 0106        public void GetJoinedChannels(int limit, int skip) => WebInterface.GetJoinedChannels(limit, skip);
 107
 108        public void GetChannels(int limit, string paginationToken, string name) =>
 0109            WebInterface.GetChannels(limit, paginationToken, name);
 110
 111        public void MuteChannel(string channelId, bool muted) =>
 0112            WebInterface.MuteChannel(channelId, muted);
 113
 114        public void GetPrivateMessages(string userId, int limit, string fromMessageId) =>
 0115            WebInterface.GetPrivateMessages(userId, limit, fromMessageId);
 116
 117        public void MarkChannelMessagesAsSeen(string channelId) =>
 0118            WebInterface.MarkChannelMessagesAsSeen(channelId);
 119
 120        public void GetUnseenMessagesByUser() =>
 0121            WebInterface.GetUnseenMessagesByUser();
 122
 123        public void GetUnseenMessagesByChannel() =>
 0124            WebInterface.GetUnseenMessagesByChannel();
 125
 126        public void CreateChannel(string channelId) =>
 0127            WebInterface.CreateChannel(channelId);
 128
 129        public void GetChannelInfo(string[] channelIds) =>
 0130            WebInterface.GetChannelInfo(channelIds);
 131
 132        public void GetChannelMembers(string channelId, int limit, int skip, string name) =>
 0133            WebInterface.GetChannelMembers(channelId, limit, skip, name);
 134
 0135        public void SendChatMessage(ChatMessage message) => WebInterface.SendChatMessage(message);
 136
 0137        public void MarkMessagesAsSeen(string userId) => WebInterface.MarkMessagesAsSeen(userId);
 138    }
 139}