コード例 #1
0
        public bool DeleteReply(string commentId)
        {
            string targetUser = string.Empty;

            if (commentId.Equals(_instInteraction.InstComment.Id))
            {
                targetUser = _instInteraction.InstComment.UserName;
            }
            else
            {
                foreach (InstObject instObject in _instInteraction.InstComment.Replies)
                {
                    if (commentId.Equals(instObject.Id))
                    {
                        targetUser = instObject.UserName;
                    }
                }
            }
            string url    = "http://emp.istnetworks.com:8080/InstGenesys/rest/InstClientRest/deleteReply?id=" + _instInteraction.UserId + "&commentId=" + commentId;
            string result = SendHTTPRequest(url, null, null, "GET", "Application/Json");

            if (result == null)
            {
                MessageBox.Show("Error deleting reply", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            dynamic outcome = JObject.Parse(result);

            if (outcome.error == true)
            {
                string errorMsg = outcome.errorMessage;
                MessageBox.Show("Error deleting comment", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                _instInteraction = new InstInteraction()
                {
                    CanComment  = true,
                    InstComment = new InstObject()
                };
                return(false);
            }
            InstObject selectedComment = null;

            foreach (InstObject deleteReply in _instInteraction.InstComment.Replies)
            {
                if (deleteReply.Id.Equals(commentId))
                {
                    selectedComment = deleteReply;
                }
            }

            if (selectedComment != null)
            {
                _instInteraction.InstComment.Replies.Remove(selectedComment);
            }
            return(true);
        }
コード例 #2
0
        public bool PushReply(string commentId, string text)
        {
            string targetUser = string.Empty;

            if (commentId.Equals(_instInteraction.InstComment.Id))
            {
                targetUser = _instInteraction.InstComment.UserName;
            }
            else
            {
                foreach (InstObject instObject in _instInteraction.InstComment.Replies)
                {
                    if (commentId.Equals(instObject.Id))
                    {
                        targetUser = instObject.UserName;
                    }
                }
            }
            text = "@" + targetUser + " " + text;
            string url    = "http://emp.istnetworks.com:8080/InstGenesys/rest/InstClientRest/addReply?id=" + _instInteraction.UserId + "&commentId=" + commentId + "&text=" + text;
            string result = SendHTTPRequest(url, null, null, "GET", "Application/Json");

            if (result == null)
            {
                MessageBox.Show("Error posting reply", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            dynamic outcome = JObject.Parse(result);

            if (outcome.error == true)
            {
                string errorMsg = outcome.errorMessage;
                MessageBox.Show(errorMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                _instInteraction = new InstInteraction()
                {
                    CanComment  = true,
                    InstComment = new InstObject()
                };
                return(false);
            }
            InstObject lastReply = new InstObject()
            {
                Id         = outcome.generatedid,
                UserName   = _instInteraction.UserName,
                ProfilePic = _instInteraction.ProfilePic,
                Text       = text,
                TimeStamp  = "Now",
                ItemColor  = new SolidColorBrush(Color.FromRgb(255, 255, 255))
            };

            _instInteraction.InstComment.Replies.Add(lastReply);
            return(true);
        }
コード例 #3
0
        public void LoadInteraction(string commentId, string userId)
        {
            string url    = "http://emp.istnetworks.com:8080/InstGenesys/rest/InstClientRest/getInteraction?id=" + userId + "&commentId=" + commentId;
            string result = SendHTTPRequest(url, null, null, "GET", "Application/Json");

            if (result == null)
            {
                _instInteraction = new InstInteraction()
                {
                    CanComment  = true,
                    InstComment = new InstObject()
                };
                return;
            }

            dynamic outcome = JObject.Parse(result);

            if (outcome.error == true)
            {
                string errorMsg = outcome.errorMessage;
                MessageBox.Show(errorMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                _instInteraction = new InstInteraction()
                {
                    CanComment  = true,
                    InstComment = new InstObject()
                };
                return;
            }
            _instInteraction = new InstInteraction
            {
                CanComment     = true,
                MediaURL       = (outcome.instMedia != null) ?outcome.instMedia.media_url:null,
                MediaLikeCount = (outcome.instMedia != null) ? outcome.instMedia.like_count:null,
                UserId         = outcome.id,
                UserName       = (outcome.instMedia != null && outcome.instMedia.owner != null) ? outcome.instMedia.owner.username : null,
                ProfilePic     = (outcome.instMedia != null && outcome.instMedia.owner != null) ? outcome.instMedia.owner.profile_picture_url : null,

                InstComment = new InstObject()
            };
            _instInteraction.InstComment.ProfilePic = (outcome.instComment != null && outcome.instComment.user != null) ? outcome.instComment.user.profile_picture_url:null;
            _instInteraction.InstComment.UserName   = (outcome.instComment != null && outcome.instComment.user != null) ? outcome.instComment.user.username:null;
            _instInteraction.InstComment.Id         = (outcome.instComment != null) ? outcome.instComment.id:null;
            _instInteraction.InstComment.LikeCount  = (outcome.instComment != null) ? outcome.instComment.like_count:null;
            _instInteraction.InstComment.Text       = (outcome.instComment != null) ? outcome.instComment.text:null;
            _instInteraction.InstComment.TimeStamp  = (outcome.instComment != null) ? outcome.instComment.timestamp:null;

            if (_instInteraction.InstComment.UserName.Equals(_instInteraction.UserName)) // If comment from owner
            {
                _instInteraction.InstComment.ProfilePic = _instInteraction.ProfilePic;
                _instInteraction.InstComment.ItemColor  = new SolidColorBrush(Color.FromRgb(255, 255, 255));
            }

            if (outcome.instComment != null && outcome.instComment.replies != null)
            {
                foreach (dynamic replyJson in outcome.instComment.replies.data)
                {
                    InstObject instReply = new InstObject
                    {
                        ProfilePic = replyJson.user.profile_picture_url,
                        UserName   = replyJson.user.username,
                        Text       = replyJson.text,
                        LikeCount  = replyJson.like_count,
                        TimeStamp  = replyJson.timestamp,
                        Id         = replyJson.id
                    };
                    if (instReply.UserName.Equals(_instInteraction.UserName))
                    { // If reply from owner
                        instReply.ProfilePic = _instInteraction.ProfilePic;
                        instReply.ItemColor  = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    }

                    _instInteraction.InstComment.Replies.Insert(0, instReply);
                }
            }
        }