public void SaveCommentToLocal(Entity.PostFeed newComment)
 {
     _postFeedManager.SaveNewPostToLocal(newComment);
     CurrentPostFeed.Comments.Add(newComment);
     CurrentPostFeed.NoOfComments = CurrentPostFeed.Comments.Count;
     RaisePropertyChanged(nameof(CurrentPostFeed));
 }
        private void SupportPost(Entity.PostFeed SelectedPost)
        {
            var updatedSelectedPost = _postFeedManager.GetPostFeed(SelectedPost.PostFeedID);

            if (ProcessInternetConnection(true))
            {
                PostFeedMessage postFeedMessage = new PostFeedMessage
                {
                    CurrentPost = AppUnityContainer.Instance.Resolve <IServiceMapper>().Instance.Map <Contract.PostFeedK>(updatedSelectedPost),
                    CurrentUser = AppUnityContainer.Instance.Resolve <IServiceMapper>().Instance.Map <Contract.ContactK>(CurrentContact)
                };

                MessagingCenter.Send(postFeedMessage, "LikeOrUnlikePostFeedToHub");
                SelectedPost.IsSelfSupported = !SelectedPost.IsSelfSupported;
                var updatePostFeed = _postFeedManager.UpdatePostFeedAndPostFeedLikeToLocal(updatedSelectedPost, CurrentContact);

                if (CurrentPostFeed.Equals(updatedSelectedPost))
                {
                    CurrentPostFeed = updatePostFeed;
                }
                else
                {
                    SelectedComment = updatePostFeed;
                }
            }
        }
        private bool ReadIfExistingPost(Entity.PostFeed currentPost)
        {
            if (viewModel.ReadPostFeedFromLocal(currentPost) == null)
            {
                return(false);
            }

            return(true);
        }
        public void DeletePostFeedFromLocal(Entity.PostFeed newPost, bool getLocalFirst = false)
        {
            if (getLocalFirst)
            {
                var foundLocalComment = _postFeedManager.GetPostFeed(newPost.PostFeedID);
                _postFeedManager.DeletePostInLocal(foundLocalComment);
                return;
            }

            _postFeedManager.DeletePostInLocal(newPost);
        }
        public void DeletePostFeedAndItsComments(Entity.PostFeed postFeed)
        {
            var comments = GetCommentsFromLocal(postFeed.PostFeedID);

            foreach (var comment in comments)
            {
                base.Delete(comment);
            }

            base.Delete(postFeed);
        }
        public void WhenITapTheCommentIconOfThePostOfWithContentAndPostFeedIdFromMyOwnPostPage(string authorName, string content, int postFeedId)
        {
            var stringArray = authorName.Split(' ');
            var postFeed    = new Entity.PostFeed
            {
                PostFeedID      = postFeedId,
                PosterFirstName = stringArray[0],
                PosterLastName  = stringArray[1],
                ContentText     = content
            };

            Main.App.Container.GetContainer().Resolve <PostFeedMyselfPageViewModel>().CommentCommand.Execute(postFeed);
        }
        private void SendAddEditToBackground(Entity.PostFeed postFeed, Entity.Contact contact)
        {
            PostFeedMessage postFeedMessage = new PostFeedMessage
            {
                CurrentPost = AppUnityContainer.Instance.Resolve <IServiceMapper>().Instance.Map <Contract.PostFeedK>(postFeed),
                CurrentUser = AppUnityContainer.Instance.Resolve <IServiceMapper>().Instance.Map <Contract.ContactK>(contact)
            };

            MessagingCenter.Send(postFeedMessage, "AddUpdatePostFeedToHub");

            //chito. added this for FAKE only because navigating to PostFeedPage after editing a post is called only after subscribing to messaging center coming from Native.
            AddUpdatePostFeedToHubFake();
        }
        private void SendAddEditToBackground(Entity.PostFeed postFeed, Entity.Contact contact)
        {
            PostFeedMessage postFeedMessage = new PostFeedMessage
            {
                CurrentPost = AppUnityContainer.Instance.Resolve <IServiceMapper>().Instance.Map <Contract.PostFeedK>(postFeed),
                CurrentUser = AppUnityContainer.Instance.Resolve <IServiceMapper>().Instance.Map <Contract.ContactK>(contact)
            };

            //_eventAggregator.GetEvent<AddUpdatePostFeedToHubEventModel>().Publish(postFeedMessage);

            // 01-12-2018 12:06pm REYNZ:
            // added this for FAKE only because navigating to PostFeedPage after editing
            // a post is called only after subscribing to messaging center coming from
            // Native.
            AddUpdatePostFeedToHubFake();
        }
        public void WriteComment()
        {
            if (!ProcessValidationErrors(_validator.Validate(this), false))
            {
                return;
            }

            if (ProcessInternetConnection(true))
            {
                if (DoUpdate)
                {
                    Comment.ContentText  = CommentText;
                    Comment.DateModified = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToString(Constants.DateTimeFormat);
                    RaisePropertyChanged(nameof(Comment));
                }
                else
                {
                    Comment = new Entity.PostFeed
                    {
                        Title                = $"A new post from @{CurrentContact.FirstName} {CurrentContact.LastName}",
                        ContentText          = CommentText ?? "",
                        ContentURL           = PostImageUrl ?? "",
                        Poster               = CurrentContact,
                        PosterEmail          = CurrentContact.EmailAdd,
                        PosterId             = CurrentContact.RemoteId,
                        PosterFirstName      = CurrentContact.FirstName,
                        PosterLastName       = CurrentContact.LastName,
                        PosterProfilePhotoFB = CurrentContact.FBLink,
                        PosterProfilePhoto   = CurrentContact.PhotoURL,
                        DatePosted           = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToString(Constants.DateTimeFormat),
                        DateModified         = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToString(Constants.DateTimeFormat),
                        SupportersIdsList    = new System.Collections.Generic.List <int>(),
                        NoOfSupports         = 0,
                        PostFeedLevel        = 1,
                        PostFeedParentId     = CurrentPostFeed.PostFeedID,
                        AliasName            = CurrentContact.AliasName,
                        IsSelfPosted         = true
                    };
                }

                IsWritePostEnabled = false;
                SendAddEditToBackground(Comment, CurrentContact);   // Updating the UI before sending updated comment to background
                _keyboardHelper.HideKeyboard();
                CommentText = string.Empty;
            }
        }
        private void AddCommentToView(Entity.PostFeed currentComment)
        {
            try
            {
                var commentItemsControl = ScrollViewElement.FindByName <StackLayout>("CommentItems");
                commentItemsControl.Children.Add(new CommentItemTemplate {
                    BindingContext = currentComment
                });

                var moreOptionsGesture = commentItemsControl.Children[commentItemsControl.Children.Count - 1].FindByName <TapGestureRecognizer>("moreOptionsSupportGesture");
                moreOptionsGesture.Command          = viewModel.ShowPostOptionsCommand;
                moreOptionsGesture.CommandParameter = currentComment;

                var supportgesture = commentItemsControl.Children[commentItemsControl.Children.Count - 1].FindByName <TapGestureRecognizer>("commentItemSupportGesture");
                supportgesture.Command          = viewModel.SupportCommand;
                supportgesture.CommandParameter = currentComment;
                supportgesture.Tapped          += SupportGesture_Tapped;

                if (commentsIndexValueList == null)
                {
                    commentsIndexValueList = new List <CommentsIndexValue>();
                }
                commentsIndexValueList.Add(new CommentsIndexValue {
                    Comment = currentComment, Index = commentsIndexValueList.Count, IsLocallySaved = false
                });

                var ellipsisContainer = commentItemsControl.Children.Last().FindByName <ContentView>("EllipsisContainer");
                var ellipsisiCon      = ellipsisContainer.FindByName <Label>("Ellipsis");
                ellipsisiCon.IsVisible = false;

                if (currentComment.IsSelfPosted)
                {
                    var grid = (CommentItemTemplate)ellipsisContainer.Parent;
                    grid.IsEnabled = false;
                    grid.Opacity   = 0.25;
                }
            }
            catch (Exception ex)
            {
                viewModel.SendErrorToHockeyApp(ex);
            }
        }
        public void AddDeductOneLikeToThisPostFromLocal(Entity.PostFeed postFeed, Entity.Contact userWhoLiked)
        {
            var postToLike = _postFeedManager.GetPostFeed(postFeed.PostFeedID);

            if (userWhoLiked.RemoteId == CurrentContact.RemoteId)
            {
                postToLike.IsSelfSupported = !postToLike.IsSelfSupported;
            }

            var updatePostFeed = _postFeedManager.UpdatePostFeedAndPostFeedLikeToLocal(postToLike, userWhoLiked);

            if (postFeed.PostFeedLevel == 1)
            {
                SelectedComment = updatePostFeed;
                SelectedComment.NoOfSupports = updatePostFeed.NoOfSupports;
            }
            else
            {
                CurrentPostFeed = updatePostFeed;
            }
        }
Пример #12
0
        public PostFeed UpdatePostFeedAndPostFeedLikeToLocal(Entity.PostFeed existingPostFeed, Entity.Contact userWhoLiked)
        {
            try
            {
                if (existingPostFeed.PosterId == int.Parse(_keyValueCachedUtility.GetUserDefaultsKeyValue("CurrentContactId")))
                {
                    existingPostFeed.IsSelfPosted = true;
                }

                var postFeedLikeInLocal = _postFeedRepository.GetPostFeedLikeByContactId(userWhoLiked.RemoteId, existingPostFeed.PostFeedID);
                existingPostFeed.NoOfSupports = (postFeedLikeInLocal == null) ? existingPostFeed.NoOfSupports + 1 : existingPostFeed.NoOfSupports - 1;

                if (postFeedLikeInLocal == null)
                {
                    _postFeedRepository.UpdateItem(new PostFeedLike {
                        ContactID = userWhoLiked.RemoteId, PostFeedID = existingPostFeed.PostFeedID
                    });
                }
                else
                {
                    _postFeedRepository.DeleteTable(postFeedLikeInLocal);
                }

                _postFeedRepository.UpdateItem(existingPostFeed);
                _updatedPostFeedFromLocal = _postFeedRepository.GetPostFeedById(existingPostFeed.PostFeedID);
                // 01-11-2018 12:31pm REYNZ
                // since comments are not saved locally because sqlite cannot saved List, i explicitly added it before returning the updated post to the caller
                //existingPostFeed.Comments = postComments;
                _updatedPostFeedFromLocal.Comments     = existingPostFeed.Comments;
                _updatedPostFeedFromLocal.NoOfSupports = existingPostFeed.NoOfSupports;
                return(_updatedPostFeedFromLocal);
            }
            catch (SQLite.SQLiteException)
            {
                return(_updatedPostFeedFromLocal);
            }
        }
 private void ShowPostOptions(Entity.PostFeed currentPostFeed)
 {
     IsShowPostOptions = true;
     Comment           = currentPostFeed;
 }
 private void UpdateAddComment(Entity.PostFeed currentPost) => viewModel.SaveCommentToLocal(currentPost);
 public Entity.PostFeed ReadPostFeedFromLocal(Entity.PostFeed newPost) => _postFeedManager.GetPostFeed(newPost.PostFeedID);
 private void DeletePost(Entity.Contact posterContact, Entity.PostFeed currentPost)
 {
     currentPost.Poster = posterContact;
     viewModel.DeletePostFeedFromLocal(currentPost);
 }
 private void UpdateAddPost(Entity.Contact posterContact, Entity.PostFeed currentPost)
 {
     currentPost.Poster = posterContact;
     currentPost.PosterProfilePhotoFB = currentPost.Poster.FBLink;
     viewModel.SavePostFeedToLocal(currentPost);
 }
Пример #18
0
        public async Task <int> SavePostToServer(Entity.PostFeed newPost)
        {
            await Task.Delay(1);

            return(0);
        }