public async Task RemoveMessageGroup(MessageGroupItem messageGroupItem) { try { var result = await _messageManager.DeleteMessageThread(messageGroupItem.MessageGroup.MessageGroupId, Locator.ViewModels.MainPageVm.CurrentUser.Username, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (!resultCheck) { return; } if (SelectedMessageGroup != null && SelectedMessageGroup.MessageGroupId == messageGroupItem.MessageGroup.MessageGroupId) { GroupMemberSeperatedList = string.Empty; SelectedMessageGroup = null; MessageCollection.Clear(); IsSelected = false; } MessageGroupCollection.Remove(messageGroupItem); } catch (Exception ex) { // TODO: Proper Error handling if deleting fails :\ } }
private async Task <string> GetAvatarUrl(string username) { var userResult = await _userManager.GetUserAvatar(username, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, userResult); var result = await ResultChecker.CheckSuccess(userResult); if (!result) { return(string.Empty); } if (string.IsNullOrEmpty(userResult.ResultJson)) { return(string.Empty); } var user = JsonConvert.DeserializeObject <User>(userResult.ResultJson); if (user?.AvatarUrls != null) { return(user.AvatarUrls.First().AvatarUrlLink); } return(string.Empty); }
public async void SetMessages(string userName) { MessageGroupCollection = new ObservableCollection <MessageGroupItem>(); var messageManager = new MessageManager(); var messageResult = await messageManager.GetGroupConversation( string.Format("~{0},{1}", userName, Locator.ViewModels.MainPageVm.CurrentUser.Username), Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region, Locator.ViewModels.MainPageVm.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, messageResult); _messageEntity = JsonConvert.DeserializeObject <MessageResponse>(messageResult.ResultJson); if (_messageEntity?.Messages == null) { return; } foreach ( MessageGroupItem newMessage in _messageEntity.Messages.Select(message => new MessageGroupItem { Message = message })) { MessageGroupCollection.Add(newMessage); } }
public async Task CheckAndNavigateToMainShell(object sender, ItemClickEventArgs e) { if (IsLoading) { return; } var user = e.ClickedItem as AccountUser; if (user == null) { return; } var loginResult = false; loginResult = await LoginTest(user); if (loginResult) { if (Shell.Instance.ViewModel.CurrentUser != null) { await AccountAuthHelpers.UpdateUserIsDefault(Shell.Instance.ViewModel.CurrentUser); } Shell.Instance.ViewModel.CurrentUser = user; Shell.Instance.ViewModel.IsLoggedIn = true; await AccountAuthHelpers.UpdateUserIsDefault(user, true); NavigationService.Navigate(typeof(MainPage)); //new NavigateToWhatsNewPage().Execute(null); } }
public async Task SetTrophyDetailList(string npCommunicationId) { NpcommunicationId = npCommunicationId; IsLoading = true; TrophyDetailList = new ObservableCollection <Trophy>(); var trophyResult = await _trophyManager.GetTrophyDetailList(npCommunicationId, TrophyScrollingCollection.CompareUsername, true, Locator.ViewModels.MainPageVm.CurrentTokens, TrophyScrollingCollection.Username, Locator.ViewModels.MainPageVm.CurrentUser.Region, Locator.ViewModels.MainPageVm.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, trophyResult); var trophies = JsonConvert.DeserializeObject <TrophyResponse>(trophyResult.ResultJson); if (trophies == null) { IsLoading = false; return; } if (trophies.Trophies == null) { IsLoading = false; return; } foreach (var trophy in trophies.Trophies) { TrophyDetailList.Add(trophy); } if (!trophies.Trophies.Any()) { IsTrophyDetailListEmpty = true; } IsLoading = false; }
private async Task <bool> LoginTest(AccountUser user) { IsLoading = true; Result result = new Result(); try { result = await _authManager.RefreshAccessToken(user.RefreshToken); var tokenResult = JsonConvert.DeserializeObject <Tokens>(result.Tokens); result = await _userManager.GetUser(user.Username, new UserAuthenticationEntity(tokenResult.AccessToken, tokenResult.RefreshToken, tokenResult.ExpiresIn), user.Region, user.Language); var userResult = JsonConvert.DeserializeObject <User>(result.ResultJson); var didUpdate = await AccountAuthHelpers.UpdateUserAccount(user, tokenResult, null, userResult); result.IsSuccess = didUpdate; } catch (Exception ex) { result.IsSuccess = false; result.Error = ex.Message; } await ResultChecker.CheckSuccess(result); IsLoading = false; return(result.IsSuccess); }
private async Task SetTwitchElements(bool interactive = false, string query = "") { var twitchResult = await _liveStreamManager.GetTwitchFeed(0, 80, "PS4", interactive, query, Locator.ViewModels.MainPageVm.CurrentTokens); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, twitchResult); var result = await ResultChecker.CheckSuccess(twitchResult); if (!result) { return; } var twitchList = JsonConvert.DeserializeObject <TwitchEntity>(twitchResult.ResultJson); if (twitchList?.streams == null) { return; } foreach (TwitchEntity.Stream twitch in twitchList.streams) { var entity = new LiveBroadcastEntity(); entity.ParseFromTwitch(twitch); LiveBroadcastCollection.Add(entity); } }
private async Task SetNicoDougaElements(bool interactive = false, string query = "") { var nicoNicoResultEntity = await _liveStreamManager.GetNicoFeed("onair", "PS4", interactive, 0, 80, "view", query, Locator.ViewModels.MainPageVm.CurrentTokens); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, nicoNicoResultEntity); var result = await ResultChecker.CheckSuccess(nicoNicoResultEntity); if (!result) { return; } var nicoNicoEntity = JsonConvert.DeserializeObject <NicoNicoEntity>(nicoNicoResultEntity.ResultJson); if (nicoNicoEntity?.programs == null) { return; } foreach (NicoNicoEntity.Program program in nicoNicoEntity.programs) { var entity = new LiveBroadcastEntity(); entity.ParseFromNicoNico(program); LiveBroadcastCollection.Add(entity); } }
private async Task <bool> LoadFeed(ObservableCollection <Feed> testFeed) { await Shell.Instance.ViewModel.UpdateTokens(); var feedResultEntity = await _recentActivityManager.GetActivityFeed(Shell.Instance.ViewModel.CurrentUser.Username, _page, true, true, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, feedResultEntity); var result = await ResultChecker.CheckSuccess(feedResultEntity); if (!result) { return(false); } if (string.IsNullOrEmpty(feedResultEntity.ResultJson)) { // No Items, return false. return(false); } var feedEntity = JsonConvert.DeserializeObject <RecentActivityResponse>(feedResultEntity.ResultJson); foreach (var feed in feedEntity.Feed) { testFeed.Add(feed); } _page++; return(true); }
private async Task SetUstreamElements(bool interactive = false, string query = "") { var filterList = new Dictionary <string, string> { { "platform", "PS4" }, { "type", "live" }, { "interactive", interactive ? "true" : "false" } }; var ustreamResultList = await _liveStreamManager.GetUstreamFeed(0, 80, "compact", filterList, "views", query, Locator.ViewModels.MainPageVm.CurrentTokens); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, ustreamResultList); var result = await ResultChecker.CheckSuccess(ustreamResultList); if (!result) { return; } var ustreamList = JsonConvert.DeserializeObject <UstreamEntity>(ustreamResultList.ResultJson); if (ustreamList?.items == null) { return; } foreach (UstreamEntity.Item ustream in ustreamList.items) { var entity = new LiveBroadcastEntity(); entity.ParseFromUstream(ustream); LiveBroadcastCollection.Add(entity); } }
public async Task GetMessageGroups(string userName) { Username = userName; IsLoading = true; MessageGroupCollection = new ObservableCollection <MessageGroupItem>(); try { await Shell.Instance.ViewModel.UpdateTokens(); var messageResult = await _messageManager.GetMessageGroup(userName, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, messageResult); var result = await ResultChecker.CheckSuccess(messageResult); if (!result) { return; } _messageGroupEntity = JsonConvert.DeserializeObject <MessageGroupResponse>(messageResult.ResultJson); var avatarOnlineId = new Dictionary <string, string>(); var avatarOnlinelist = _messageGroupEntity.MessageGroups.Select(node => node.LatestMessage); foreach (var member in avatarOnlinelist) { var avatar = await GetAvatarUrl(member.SenderOnlineId); if (avatarOnlineId.All(node => node.Key != member.SenderOnlineId)) { avatarOnlineId.Add(member.SenderOnlineId, avatar); } } foreach ( var newMessage in _messageGroupEntity.MessageGroups.Select( message => new MessageGroupItem { MessageGroup = message })) { newMessage.AvatarUrl = avatarOnlineId.FirstOrDefault( node => node.Key == newMessage.MessageGroup.LatestMessage.SenderOnlineId).Value; MessageGroupCollection.Add(newMessage); } } catch (Exception ex) { //Insights.Report(ex); } if (MessageGroupCollection.Count <= 0) { MessageGroupEmpty = true; } IsLoading = false; }
public async Task <bool> LoadTrophies(string username) { Offset = Offset + MaxCount; IsLoading = true; await Shell.Instance.ViewModel.UpdateTokens(); var trophyManager = new TrophyManager(); var trophyResultList = await trophyManager.GetTrophyList(username, CompareUsername, Offset, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, trophyResultList); var result = await ResultChecker.CheckSuccess(trophyResultList, false); if (!result) { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } IsLoading = false; return(false); } var trophyList = JsonConvert.DeserializeObject <TrophyDetailResponse>(trophyResultList.ResultJson); if (trophyList == null) { //HasMoreItems = false; IsEmpty = true; IsLoading = false; return(false); } foreach (var trophy in trophyList.TrophyTitles) { Add(trophy); } if (trophyList.TrophyTitles.Any()) { HasMoreItems = true; MaxCount += 64; } else { if (Count <= 0) { IsEmpty = true; } HasMoreItems = false; } IsLoading = false; return(true); }
public async Task SendSticker(StickerSelection stickerSelection) { string error; try { var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateStickerPostWithNewGroupMessage(GroupMembers.ToArray(), stickerSelection.ManifestUrl, stickerSelection.Number.ToString(), stickerSelection.ImageUrl, stickerSelection.PackageId, stickerSelection.Type, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } else { result = await _messageManager.CreateStickerPost(SelectedMessageGroup.MessageGroupId, stickerSelection.ManifestUrl, stickerSelection.Number.ToString(), stickerSelection.ImageUrl, stickerSelection.PackageId, stickerSelection.Type, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); //await GetMessageGroups(Shell.Instance.ViewModel.CurrentUser.Username); IsNewMessage = false; } return; } catch (Exception ex) { error = ex.Message; } await ResultChecker.SendMessageDialogAsync(error, false); }
public async Task <string> CreateFriendLink() { var result = await _friendManager.GetFriendLink(Locator.ViewModels.MainPageVm.CurrentTokens); await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (!resultCheck) { return(string.Empty); } var tokenEntity = JsonConvert.DeserializeObject <TokenResponse>(result.ResultJson); return(tokenEntity.Token); }
private async Task SendMessageWithMedia() { var realImage = await ConvertToJpeg(AttachedImage); var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateNewGroupMessageWithMedia(GroupMembers.ToArray(), Message, ImagePath, realImage, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } else { if (SelectedMessageGroup == null) { await ResultChecker.SendMessageDialogAsync("Selected Message Group Null!", false); } else { result = await _messageManager.CreatePostWithMedia(SelectedMessageGroup.MessageGroupId, Message, ImagePath, realImage, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } } await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { IsImageAttached = false; AttachedImage = null; SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); //await GetMessageGroups(Shell.Instance.ViewModel.CurrentUser.Username); IsNewMessage = false; } }
public async Task <bool> DeleteUserAccount(AccountUser user) { var result = new Result(); try { result.IsSuccess = await AccountAuthHelpers.DeleteUserAccount(user); } catch (Exception ex) { result.IsSuccess = false; result.Error = "Failed to delete user"; } var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { AccountUsers.Remove(user); if (Shell.Instance.ViewModel.CurrentUser != null && Shell.Instance.ViewModel.CurrentUser.Username == user.Username) { Shell.Instance.ViewModel.CurrentUser = null; Shell.Instance.ViewModel.IsLoggedIn = false; try { var pages = App.Frame.BackStack; foreach (var page in pages) { App.Frame.BackStack.Remove(page); } } catch (Exception) { // Failed to delete backstack :\ } } if (!AccountUsers.Any()) { NavigationService.Navigate(typeof(LoginPage)); } } return(resultCheck); }
public async Task <bool> LoginDefaultUser() { string errorMessage; try { var defaultUsers = await _udb.GetDefaultUserAccounts(); if (!defaultUsers.Any()) { return(false); } var defaultUser = defaultUsers.First(); var loginResult = await LoginTest(defaultUser); if (loginResult) { if (Shell.Instance.ViewModel.CurrentUser != null) { await AccountAuthHelpers.UpdateUserIsDefault(Shell.Instance.ViewModel.CurrentUser); } CurrentUser = defaultUser; IsLoggedIn = true; return(true); //new NavigateToWhatsNewPage().Execute(null); } else { return(false); } } catch (Exception ex) { errorMessage = ex.Message; } // Failed to log in with default user, tell them. await ResultChecker.SendMessageDialogAsync(errorMessage, false); return(false); }
public async Task SetUser(string userName) { var isCurrentUser = Shell.Instance.ViewModel.CurrentUser.Username.Equals(userName); var userManager = new UserManager(); await Shell.Instance.ViewModel.UpdateTokens(); var userResult = await userManager.GetUser(userName, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, userResult); var result = await ResultChecker.CheckSuccess(userResult); if (!result) { return; } if (string.IsNullOrEmpty(userResult.ResultJson)) { return; } var user = JsonConvert.DeserializeObject <User>(userResult.ResultJson); if (user == null) { return; } var list = user.TrophySummary.EarnedTrophies; user.TrophySummary.TotalTrophies = list.Bronze + list.Gold + list.Platinum + list.Silver; List <string> languageList = user.LanguagesUsed.Select(ParseLanguageVariable).ToList(); string language = string.Join("," + Environment.NewLine, languageList); UserModel = new UserViewModel { Language = language, User = user, IsNotCurrentUser = !isCurrentUser, CurrentUserOnlineId = Shell.Instance.ViewModel.CurrentUser.Username }; }
public async Task <bool> DeleteUserAccount(AccountUser user) { Locator.ViewModels.MainPageVm.MenuItems = new List <MenuItem>(); try { var pages = App.RootFrame.BackStack; foreach (var page in pages) { App.RootFrame.BackStack.Remove(page); } } catch (Exception) { // Failed to delete backstack :\ } var result = new Result(); try { result.IsSuccess = await AccountAuthHelpers.DeleteUserAccount(user); } catch (Exception ex) { result.IsSuccess = false; result.Error = "Failed to delete user"; } var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { AccountUsers.Remove(user); if (AccountUsers.Any()) { OnPropertyChanged("AccountUsers"); return(true); } App.RootFrame.Navigate(typeof(LoginPage)); } return(resultCheck); }
public async Task SendSticker(StickerSelection stickerSelection) { var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateStickerPostWithNewGroupMessage(GroupMembers.ToArray(), stickerSelection.ManifestUrl, stickerSelection.Number.ToString(), stickerSelection.ImageUrl, stickerSelection.PackageId, stickerSelection.Type, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); } else { result = await _messageManager.CreateStickerPost(SelectedMessageGroup.MessageGroupId, stickerSelection.ManifestUrl, stickerSelection.Number.ToString(), stickerSelection.ImageUrl, stickerSelection.PackageId, stickerSelection.Type, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); } await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); await GetMessageGroups(Locator.ViewModels.MainPageVm.CurrentUser.Username); IsNewMessage = false; } }
public async Task SetTrophyDetailList() { IsLoading = true; await Shell.Instance.ViewModel.UpdateTokens(); TrophyDetailList = new ObservableCollection <Trophy>(); var trophyResult = await _trophyManager.GetTrophyDetailList(NpcommunicationId, Username, true, Shell.Instance.ViewModel.CurrentTokens, Username, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, trophyResult); var trophies = JsonConvert.DeserializeObject <TrophyResponse>(trophyResult.ResultJson); if (trophies == null) { IsLoading = false; return; } if (trophies.Trophies == null) { IsLoading = false; return; } foreach (var trophy in trophies.Trophies) { TrophyDetailList.Add(trophy); } if (!trophies.Trophies.Any()) { IsTrophyDetailListEmpty = true; } IsLoading = false; }
private async Task SendMessageWithoutMedia() { var result = new Result(); if (GroupMembers.Any() && IsNewMessage) { result = await _messageManager.CreateNewGroupMessage(GroupMembers.ToArray(), Message, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); } else { if (SelectedMessageGroup == null) { await ResultChecker.SendMessageDialogAsync("Selected Message Group Null!", false); } else { result = await _messageManager.CreatePost(SelectedMessageGroup.MessageGroupId, Message, Locator.ViewModels.MainPageVm.CurrentTokens, Locator.ViewModels.MainPageVm.CurrentUser.Region); } } await AccountAuthHelpers.UpdateTokens(Locator.ViewModels.MainPageVm.CurrentUser, result); var resultCheck = await ResultChecker.CheckSuccess(result); if (resultCheck) { SelectedMessageGroup = JsonConvert.DeserializeObject <MessageGroup>(result.ResultJson); await GetMessages(SelectedMessageGroup); await GetMessageGroups(Locator.ViewModels.MainPageVm.CurrentUser.Username); IsNewMessage = false; } }
public async Task Login() { Result loginResult = new Result(); IsLoading = true; try { loginResult = await _authManager.SendLoginData(UserName, Password); } catch (Exception ex) { loginResult.IsSuccess = false; loginResult.ResultJson = ex.Message; } var loader = new Windows.ApplicationModel.Resources.ResourceLoader(); if (!loginResult.IsSuccess) { loginResult.ResultJson = loader.GetString("LoginError/Text"); } else if (loginResult.IsSuccess) { try { var authTokens = JsonConvert.DeserializeObject <Tokens>(loginResult.Tokens); var expiresInDate = AuthHelpers.GetUnixTime(DateTime.Now) + authTokens.ExpiresIn; if (!string.IsNullOrEmpty(authTokens.AccessToken) && !string.IsNullOrEmpty(authTokens.RefreshToken)) { var loginUserResult = await _authManager.GetUserEntity(new UserAuthenticationEntity(authTokens.AccessToken, authTokens.RefreshToken, expiresInDate), "ja"); var loginUser = JsonConvert.DeserializeObject <LogInUser>(loginUserResult.ResultJson); var userResult = await _userManager.GetUser(loginUser.OnlineId, new UserAuthenticationEntity(authTokens.AccessToken, authTokens.RefreshToken, expiresInDate), loginUser.Region, loginUser.Language); var user = JsonConvert.DeserializeObject <User>(userResult.ResultJson); var newAccountResult = await AccountAuthHelpers.CreateUserAccount(authTokens, loginUser, user); if (!newAccountResult) { loginResult.IsSuccess = false; loginResult.Error = "Failed to create new user in database."; } } } catch (Exception ex) { loginResult.IsSuccess = false; loginResult.ResultJson = ex.Message; } } // Check if the result was good. If not, show error. await ResultChecker.CheckSuccess(loginResult); IsLoading = false; if (loginResult.IsSuccess) { NavigationService.Navigate(typeof(AccountPage)); } }
public async void LoadFeedList(string username) { IsLoading = true; await Shell.Instance.ViewModel.UpdateTokens(); var feedResultEntity = await _recentActivityManager.GetActivityFeed(username, PageCount, StorePromo, IsNews, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, feedResultEntity); var result = await ResultChecker.CheckSuccess(feedResultEntity, false); if (!result) { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } IsLoading = false; return; } var feedEntity = JsonConvert.DeserializeObject <RecentActivityResponse>(feedResultEntity.ResultJson); if (feedEntity == null) { if (Count <= 0) { IsEmpty = true; } HasMoreItems = false; IsLoading = false; return; } if (feedEntity.Feed == null) { if (Count <= 0) { IsEmpty = true; } HasMoreItems = false; IsLoading = false; return; } foreach (var feed in feedEntity.Feed) { Add(feed); } if (feedEntity.Feed.Any()) { HasMoreItems = true; PageCount++; } else { if (Count <= 0) { IsEmpty = true; } HasMoreItems = false; } IsLoading = false; }
private async Task <LoadMoreItemsResult> LoadFriends(uint count) { IsLoading = true; try { var friendManager = new FriendManager(); await Shell.Instance.ViewModel.UpdateTokens(); var friendResultEntity = await friendManager.GetFriendsList(Username, Offset, BlockedPlayer, RecentlyPlayed, PersonalDetailSharing, FriendStatus, Requesting, Requested, OnlineFilter, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); var result = await ResultChecker.CheckSuccess(friendResultEntity, false); if (!result) { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } IsLoading = false; return(new LoadMoreItemsResult { Count = 0 }); } await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.CurrentUser, friendResultEntity); var friendEntity = JsonConvert.DeserializeObject <FriendListResponse>(friendResultEntity.ResultJson); if (friendEntity == null) { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } IsLoading = false; return(new LoadMoreItemsResult { Count = count }); } if (friendEntity.Friend == null) { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } IsLoading = false; return(new LoadMoreItemsResult { Count = count }); } foreach (var friend in friendEntity.Friend) { Add(friend); } if (friendEntity.Friend.Any()) { HasMoreItems = true; Offset = Offset += 32; } else { HasMoreItems = false; if (Count <= 0) { IsEmpty = true; } } } catch (Exception ex) { HasMoreItems = false; } IsLoading = false; return(new LoadMoreItemsResult { Count = count }); }
public async Task GetMessages(MessageGroup messageGroup) { IsSelected = false; //MessageCollection.Clear(); IsLoading = true; try { SelectedMessageGroup = messageGroup; await Shell.Instance.ViewModel.UpdateTokens(); var messageResult = await _messageManager.GetGroupConversation(messageGroup.MessageGroupId, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region, Shell.Instance.ViewModel.CurrentUser.Language); await AccountAuthHelpers.UpdateTokens(Shell.Instance.ViewModel.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 != Shell.Instance.ViewModel.CurrentUser.Username) .Select(node => node.Key); GroupMemberSeperatedList = string.Join(", ", newList); foreach ( var newMessage in _messageResponse.Messages.Where(node => !MessageCollection.Select(test => test.Message.MessageUid).Contains(node.MessageUid)).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, // Shell.Instance.ViewModel.CurrentTokens, // Shell.Instance.ViewModel.CurrentUser.Region, // Shell.Instance.ViewModel.CurrentUser.Language); //newMessage.Image = await DecodeImage(imageBytes); } } catch (Exception ex) { //Insights.Report(ex); } MessageCollection.Add(newMessage); } ScrollToBottom(); } catch (Exception ex) { //Insights.Report(ex); } var newMessages = _messageResponse?.Messages.Where(node => !node.SeenFlag); if (newMessages != null) { await Shell.Instance.ViewModel.UpdateTokens(); var messageUids = newMessages.Select(node => node.MessageUid).ToList(); await _messageManager.ClearMessages(_messageResponse.MessageGroup.MessageGroupId, messageUids, Shell.Instance.ViewModel.CurrentTokens, Shell.Instance.ViewModel.CurrentUser.Region); } IsLoading = false; IsSelected = true; }