private void BisnerClientOnNewFeedPost(ApiWhitelabelFeedPostModel model) { if (model.Id == PostId) { // This is the current post InvokeOnMainThread(async() => { var postModel = await _feedService.GetPostAsync(ApiPriority.Background, model.Id); var posts = BuildItems(postModel); var post = posts.FirstOrDefault(); var currentPost = Items[0] as IFeedPost; currentPost?.Update(post); var comments = postModel.Posts.FirstOrDefault()?.Comments.Select(c => c.ToModel()); // add new comments var newComments = comments.Where(c => Items.All(i => i.Id != c.Id)).OrderBy(c => c.DateTime).ToList(); foreach (var newComment in newComments.OrderBy(c => c.DateTime)) { Items.Add(newComment); } if (newComments.Any()) { Mvx.Resolve <IMvxMessenger>().Publish(new NewCommentMessage(this)); } }); } }
private void AddPost(ApiWhitelabelFeedPostModel model) { BlobCache.LocalMachine.Invalidate("homefeed"); var oldPost = Items.FirstOrDefault(p => p.Id == model.Id && p is IFeedPost); InvokeOnMainThread(() => { var feedPost = BuildItem(model); if (oldPost != null) { // Update existing ((IFeedPost)oldPost).Update(feedPost); } else { // Insert new one Items.Insert(FeedId == Guid.Empty ? 0 : 1, feedPost); } }); }
private void OnUpdateFeedPost(ApiWhitelabelFeedPostModel feedPostModel) { Execute(NewFeedPost, action => action(feedPostModel)); }