private async void NewMessage(object sender, RoutedEventArgs e)
        {
            string error;
            if (!MessageFriendList.SelectedItems.Any()) return;
            try
            {
                ViewModel.MessageCollection?.Clear();
                var usernameObjectList = MessageFriendList.SelectedItems.ToList();
                var friendList = usernameObjectList.Cast<Friend>().ToList();
                var usernameList = friendList.Select(node => node.OnlineId).ToList();
                ViewModel.IsNewMessage = true;
                ViewModel.GroupMembers = usernameList;
                var selectedGroupMessage = new MessageGroup()
                {
                    MessageGroupDetail = new MessageGroupDetail() { MessageGroupName = string.Join(",", usernameList) }
                };
                ViewModel.SelectedMessageGroup = selectedGroupMessage;
                ViewModel.Selected = new MessageGroupItem()
                {
                    MessageGroup = selectedGroupMessage
                };
                FriendMessageFlyout.Hide();
                return;
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            await ResultChecker.SendMessageDialogAsync(error, false);
        }
        public async Task GetMessages(MessageGroup messageGroup)
        {
            IsSelected = false;
            MessageCollection.Clear();
            IsLoading = true;
            try
            {
                SelectedMessageGroup = messageGroup;
                var messageResult =
                    await
                        _messageManager.GetGroupConversation(messageGroup.MessageGroupId,
                            Locator.ViewModels.MainPageVm.CurrentTokens,
                            Locator.ViewModels.MainPageVm.CurrentUser.Region,
                            Locator.ViewModels.MainPageVm.CurrentUser.Language);
                await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, messageResult);
                var result = await ResultChecker.CheckSuccess(messageResult);
                if (!result)
                {
                    return;
                }
                _messageResponse = JsonConvert.DeserializeObject<MessageResponse>(messageResult.ResultJson);
                var avatarOnlineId = new Dictionary<string, string>();
                foreach (var member in _messageResponse.MessageGroup.MessageGroupDetail.Members)
                {
                    var avatar = await GetAvatarUrl(member.OnlineId);
                    if (avatarOnlineId.All(node => node.Key != member.OnlineId))
                    {
                        avatarOnlineId.Add(member.OnlineId, avatar);
                    }
                }
                var newList =
                    avatarOnlineId.Where(node => node.Key != Locator.ViewModels.MainPageVm.CurrentUser.Username)
                        .Select(node => node.Key);
                GroupMemberSeperatedList = string.Join(", ", newList);
                foreach (
                    var newMessage in
                        _messageResponse.Messages.Reverse().Select(message => new MessageGroupItem {Message = message}))
                {
                    newMessage.AvatarUrl =
                        avatarOnlineId.First(node => node.Key == newMessage.Message.SenderOnlineId).Value;
                    if (newMessage.Message.StickerDetail != null)
                    {
                        newMessage.Message.Body = string.Empty;
                    }
                    newMessage.ImageAvailable = newMessage.Message.ContentKeys.Contains("image-data-0");
                    try
                    {
                        if (newMessage.ImageAvailable)
                        {
                            //var imageBytes =
                            //    await
                            //        _messageManager.GetMessageContent(SelectedMessageGroup.MessageGroupId,
                            //            newMessage.Message.SentMessageId,
                            //            Locator.ViewModels.MainPageVm.CurrentTokens,
                            //            Locator.ViewModels.MainPageVm.CurrentUser.Region,
                            //            Locator.ViewModels.MainPageVm.CurrentUser.Language);
                            //newMessage.Image = await DecodeImage(imageBytes);
                        }
                    }
                    catch (Exception ex)
                    {
                        //Insights.Report(ex);
                    }
                    MessageCollection.Add(newMessage);
                }
            }
            catch (Exception ex)
            {
                //Insights.Report(ex);
            }
            var newMessages = _messageResponse?.Messages.Where(node => !node.SeenFlag);
            if (newMessages != null)
            {
                var messageUids = newMessages.Select(node => node.MessageUid).ToList();
                await
                    _messageManager.ClearMessages(_messageResponse.MessageGroup.MessageGroupId, messageUids,
                        Locator.ViewModels.MainPageVm.CurrentTokens,
                        Locator.ViewModels.MainPageVm.CurrentUser.Region);
            }

            IsLoading = false;
            IsSelected = true;
        }
     public async Task GetMessages(MessageGroup messageGroup)
     {
         SelectedMessageGroup = messageGroup;
         IsSelected = false;
         MessageCollection = new ObservableCollection<MessageGroupItem>();
         IsLoading = true;
         try
         {
             _selectedMessageGroup = messageGroup;
             var messageResult =
            await _messageManager.GetGroupConversation(messageGroup.MessageGroupId, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region, Locator.ViewModels.MainPageVm.CurrentUser.Language);
             await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, messageResult);
             var result = await ResultChecker.CheckSuccess(messageResult);
             if (!result)
             {
                 return;
             }
             _messageResponse = JsonConvert.DeserializeObject<MessageResponse>(messageResult.ResultJson);
             foreach (
 var newMessage in
     _messageResponse.Messages.Reverse().Select(message => new MessageGroupItem { Message = message }))
             {
                 newMessage.AvatarUrl = await GetAvatarUrl(newMessage.Message.SenderOnlineId);
                 newMessage.ImageAvailable = newMessage.Message.ContentKeys.Contains("image-data-0");
                 try
                 {
                     if (newMessage.ImageAvailable)
                     {
                         var imageBytes =
                             await
                                 _messageManager.GetMessageContent(_selectedMessageGroup.MessageGroupId, newMessage.Message.SentMessageId,
                                     Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region, Locator.ViewModels.MainPageVm.CurrentUser.Language);
                         newMessage.Image = await DecodeImage(imageBytes);
                     }
                 }
                 catch (Exception ex)
                 {
                     //Insights.Report(ex);
                 }
                 MessageCollection.Add(newMessage);
             }
         }
         catch (Exception ex)
         {
             //Insights.Report(ex);
         }
         IsLoading = false;
         IsSelected = true;
     }