Example #1
0
        private async Task ReceiveChats(string receivedJson)
        {
            _log.LogTrace("-> ChatGuest.ReceiveChats(string)");

            if (CurrentSession.Chats == null)
            {
                CurrentSession.Chats = new List <Chat>();
            }

            await ChatProxy.ReceiveChats(
                RaiseUpdateEvent,
                null, // Do not save messages in the guest, they always need a Host to be online.
                receivedJson,
                CurrentSession.Chats,
                PeerInfo.Message.PeerId,
                _log);

            var firstChat = CurrentSession.Chats
                            .FirstOrDefault(c => c.SessionName != null);

            if (firstChat != null)
            {
                CurrentSession.SessionName = firstChat.SessionName;
                RaiseUpdateEvent();
            }

            _log.LogTrace("ChatGuest.ReceiveChats(string) ->");
        }
Example #2
0
        public async Task ToggleLikeChat(Chat chat)
        {
            _log.LogDebug("-> ChatGuest.ToggleLikeChat");

            await ChatProxy.ToggleLikeChat(
                chat,
                PeerInfo.Message,
                CurrentSession.SessionId,
                _log);
        }
Example #3
0
 public async Task <bool> SendCurrentChat()
 {
     _log.LogTrace("-> SendCurrentChat");
     return(await ChatProxy.SendCurrentChat(
                RaiseUpdateEvent,
                PeerInfo.Message,
                CurrentSession.SessionName,
                CurrentSession.SessionId,
                _log));
 }
Example #4
0
 public ChatGuest(
     IConfiguration config,
     ILocalStorageService localStorage,
     ILogger log,
     HttpClient http,
     string sessionId,
     SessionHandler session) : base(config, localStorage, log, http, sessionId, session)
 {
     ChatProxy = new ChatProxy(_http, _hostNameFree);
     _log.LogInformation("-> ChatGuest()");
 }
Example #5
0
        private async Task LikeChat(string receivedJson)
        {
            _log.LogTrace("-> ChatGuest.LikeChat(string)");

            await ChatProxy.ReceiveLikeChat(
                RaiseUpdateEvent,
                null,
                receivedJson,
                CurrentSession.Chats,
                PeerInfo.Message.PeerId,
                _log);
        }
Example #6
0
 public ChatHost(
     IConfiguration config,
     ILocalStorageService localStorage,
     ILogger log,
     HttpClient http,
     NavigationManager nav,
     SessionHandler session,
     string sessionId) : base(config, localStorage, log, http, nav, session)
 {
     _sessionId = sessionId;
     ChatProxy  = new ChatProxy(_http, _hostNameFree);
 }
Example #7
0
        private async Task ReceiveChats(string receivedJson)
        {
            _log.LogTrace("-> ChatHost.ReceiveChats(string)");

            await ChatProxy.ReceiveChats(
                RaiseUpdateEvent,
                SaveSession,
                receivedJson,
                CurrentSession.Chats,
                PeerInfo.Message.PeerId,
                _log);
        }
Example #8
0
        private async Task <bool> SendChats(string _)
        {
            // TODO Think about adding paging here for the chats. For instance,
            // send the ones from the last 30 minutes and add a "load more" link on top.

            _log.LogTrace("-> SendChats(string)");

            if (CurrentSession.Chats == null)
            {
                CurrentSession.Chats = new List <Chat>();
            }

            if (CurrentSession.Chats.Count == 0)
            {
                return(true);
            }

            return(await ChatProxy.SendChats(
                       CurrentSession.Chats,
                       CurrentSession.SessionName,
                       CurrentSession.SessionId,
                       _log));
        }
Example #9
0
        public override async Task Connect()
        {
            _log.LogInformation("-> ChatHost.Connect");

            IsBusy      = true;
            IsInError   = false;
            IsConnected = false;
            RaiseUpdateEvent();

            var ok = await InitializeSession(_sessionId);

            if (!ok)
            {
                // Error cases are handled in InitializeSession
                return;
            }

            ok = await InitializePeerInfo() &&
                 await CreateConnection();

            if (ok)
            {
                ChatProxy.UpdateChats(CurrentSession, PeerInfo.Message.PeerId);

                _connection.On <string>(Constants.ReceiveChatsMessage, ReceiveChats);
                _connection.On <string>(Constants.RequestChatsMessage, SendChats);
                _connection.On <string>(Constants.LikeChatMessage, LikeChat);

                ok = await StartConnection();
            }

            if (!ok)
            {
                _log.LogTrace("StartConnection NOT OK");
                IsConnected = false;
                IsInError   = true;
                IsBusy      = false;
                ErrorStatus = "Error";
                RaiseUpdateEvent();
                return;
            }

            ok = await SendChats();

            if (!ok)
            {
                _log.LogTrace("Error when sending chats");
                IsConnected = false;
                IsInError   = true;
                IsBusy      = false;
                ErrorStatus = "Error sending chats";
                RaiseUpdateEvent();
                return;
            }

            Status      = "Connected";
            IsBusy      = false;
            IsInError   = false;
            IsConnected = true;
            RaiseUpdateEvent();
            _log.LogInformation("ChatsHost.Connect ->");
        }