protected async Task CloseContact() { StateTchatContainer.SetModalChatContactOpen(!StateTchatContainer.ModalChatContactOpen); //StateTchatContainer.SetHasMessage(StateTchatContainer.MyContacts.Any(x => x.HasNewMsg)); await NotifyClient.CloseModalContactTchat(); }
protected async Task OpenChat(ViewContact item) { var response = await httpClient.GetAsync($"/api/Tchat/{item.UserId}"); response.EnsureSuccessStatusCode(); StateTchatContainer.ListMessage.Clear(); var json = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(json)) { StateTchatContainer.ListMessage.AddRange(JsonConvert.DeserializeObject <List <Message> >(json)); } StateTchatContainer.ContactSelected = item; var tmp = StateTchatContainer.MyContacts.FirstOrDefault(x => x.UserId == item.UserId); tmp.HasNewMsg = false; StateTchatContainer.SetModalTchat(true); await ScrollToElementId("msg_card_body"); }
protected override async Task OnInitializedAsync() { StateTchatContainer.OnChange += StateHasChanged; var authState = await authenticationStateTask; _user = authState.User; var accessTokenResult = await tokenProvider.RequestAccessToken(); if (!accessTokenResult.TryGetToken(out var accessToken) && _user.Identity.IsAuthenticated) { navigationManager.NavigateTo("/Identity/Account/Login", true); } if (_user.Identity.IsAuthenticated) { StateTchatContainer.MyContacts.Clear(); Console.WriteLine($"start get notification for user {_user.Identity.Name}"); var getMyContacts = await httpClient.GetAsync("api/Contacts"); getMyContacts.EnsureSuccessStatusCode(); var jsonContact = await getMyContacts.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(jsonContact)) { StateTchatContainer.SetMyContacts(JsonConvert.DeserializeObject <List <ViewContact> >(jsonContact)); } var getResponse = await httpClient.GetAsync("api/Tchat/GetMessageUnread"); getResponse.EnsureSuccessStatusCode(); var jsonResp = await getResponse.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(jsonResp)) { var listContactUnread = JsonConvert.DeserializeObject <List <string> >(jsonResp); foreach (var item in StateTchatContainer.MyContacts) { if (listContactUnread.Contains(item.UserId.ToString())) { item.HasNewMsg = true; } } } var getNotifications = await httpClient.GetAsync("api/Notification"); getNotifications.EnsureSuccessStatusCode(); NotificationClient = new NotificationClient(navigationManager.ToAbsoluteUri("/notification").AbsoluteUri, accessToken.Value); await NotificationClient.StartAsync(); NotificationClient.NotificationEvent += ShowNotification; NotificationClient.MessageReceivedEvent += MessageReceived; var json = await getNotifications.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(json)) { var temp = JsonConvert.DeserializeObject <List <Notification> >(json); await NotificationClient.SendNotifications(temp); } } }
protected async Task CloseModalTchat() { StateTchatContainer.SetModalTchat(false); MsgText = string.Empty; await InvokeAsync(StateHasChanged); }