Commit 5ceeb82a authored by HankG's avatar HankG

Bugfix post inserting into timeline works for all but one element

parent c9681e41
......@@ -12,7 +12,7 @@ namespace MySocialPortalDesktop.ViewModels
{
public class PostTimelineViewModel : ViewModelBase
{
private const int MaxPostsQuery = 5;
private const int MaxPostsQuery = 20;
private const int MaxPostHistory = 50;
public ObservableCollection<PostViewModel> PostViewModels { get; }
......@@ -57,7 +57,7 @@ namespace MySocialPortalDesktop.ViewModels
try
{
var posts = CurrentPerson == null ?
TwitterConnector.GetNewerHomeTimeline(MaxPostsQuery).ToList() :
TwitterConnector.GetNewerHomeTimeline(10).ToList() :
TwitterConnector.GetNewerUserTimeline(CurrentPerson, MaxPostsQuery).ToList();
ProcessNewPosts(posts, true);
......@@ -73,7 +73,7 @@ namespace MySocialPortalDesktop.ViewModels
try
{
var posts = CurrentPerson == null ?
TwitterConnector.GetOlderHomeTimeline(MaxPostsQuery).ToList() :
TwitterConnector.GetOlderHomeTimeline(10).ToList() :
TwitterConnector.GetOlderUserTimeline(CurrentPerson, MaxPostsQuery).ToList();
ProcessNewPosts(posts, false);
}
......@@ -110,33 +110,48 @@ namespace MySocialPortalDesktop.ViewModels
RepositoryFactory.Instance.AllPostsRepository.AddPosts(filteredPosts);
if (insertTop)
{
posts.Sort(new PostComparisonAscending());
posts.Sort(new PostComparison(true));
posts.ForEach(p => PostViewModels.Insert(0, new PostViewModel(p)));
}
else
{
posts.Sort(new PostComparisonDescending());
var currentGuessIndex = 0;
posts.Sort(new PostComparison(false));
foreach (var post in posts)
{
var postDate = post.PostDateTime.LocalDateTime;
var guessDate = PostViewModels[currentGuessIndex].Date;
if (postDate >= guessDate)
var found = false;
var currentGuessIndex = 0;
while (!found)
{
PostViewModels.Insert(currentGuessIndex, new PostViewModel(post));
continue;
}
if (PostViewModels.Count == 0)
{
PostViewModels.Add(new PostViewModel(post));
found = true;
continue;
}
var postDate = post.PostDateTime.LocalDateTime;
var guessDate = PostViewModels[currentGuessIndex].Date;
if (currentGuessIndex == PostViewModels.Count - 1)
{
PostViewModels.Insert(currentGuessIndex, new PostViewModel(post));
continue;
}
if (postDate >= guessDate)
{
PostViewModels.Insert(currentGuessIndex, new PostViewModel(post));
found = true;
continue;
}
if (currentGuessIndex == PostViewModels.Count - 1)
{
PostViewModels.Insert(currentGuessIndex, new PostViewModel(post));
found = true;
continue;
}
currentGuessIndex++;
currentGuessIndex++;
}
}
PostViewModels.AddRange(posts.Select(p => new PostViewModel(p)));
//PostViewModels.AddRange(posts.Select(p => new PostViewModel(p)));
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment