public static List <FacebookGroupPost> getGroupFeed(string groupId, FacebookAuth givenAuth = null)
        {
            string requestString = groupId + "/feed?fields=permalink_url,description,message,from,comments{message,from}";

            requestString += "&access_token=" + givenAuth.accessToken;
            FacebookGroup group = new FacebookGroup();

            using (var db = new ClassroomContext())
            {
                group = db.FacebookGroups.Where(x => x.id == groupId).SingleOrDefault();
            }
            string resultRaw  = fireGetRequest(requestString);
            JToken resultJson = JObject.Parse(resultRaw)["data"];
            List <FacebookGroupPost> result = JsonConvert.DeserializeObject <List <FacebookGroupPost> >(resultJson.ToString());

            result.ForEach(x =>
            {
                x.comments    = new List <FacebookComment>();
                x.parentGroup = group;
            });
            foreach (JToken post in JObject.Parse(resultRaw)["data"])
            {
                if (post["comments"] != null)
                {
                    foreach (JToken comment in post["comments"]["data"])
                    {
                        FacebookComment newComment = JsonConvert.DeserializeObject <FacebookComment>(comment.ToString());
                        result.Where(x => x.id == post["id"].ToString()).ToList().ForEach(x => x.comments.Add(newComment));
                    }
                }
            }

            return(result);
        }
        public void CreateComment_ShouldReturnXml_WhenCommentProvided()
        {
            // Arrange
            var comment = new FacebookComment
            {
                Id          = "id",
                CreatedTime = DateTime.Parse("2017-03-21 00:03:00"),
                Message     = "message",
                From        = new FacebookCommentUser
                {
                    Id   = "userid",
                    Name = "username"
                }
            };

            var formatter = new DisqusCommentsFormatter();

            // Act
            var result = formatter.CreateComment(comment);

            // Assert
            result.Descendants(_wp + "comment_id").FirstOrDefault().Value.Should().Be("id");
            result.Descendants(_wp + "comment_author").FirstOrDefault().Value.Should().Be("username");
            result.Descendants(_wp + "comment_date_gmt").FirstOrDefault().Value.Should().Be("2017-03-21 00:03:00");
            result.Descendants(_wp + "comment_approved").FirstOrDefault().Value.Should().Be("1");
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes ActivityComment object from underlying facebook data object
 /// </summary>
 /// <param name="comment">comment object</param>
 internal ActivityComment(FacebookComment comment)
 {
     this.CommentId  = comment.CommentId;
     this.FromUserId = comment.FromId;
     this.Time       = comment.Time;
     this.Text       = comment.Text;
 }
        private void buttonLike_Click(object sender, RoutedEventArgs e)
        {
            FacebookComment comment = this.DataContext as FacebookComment;

            if (comment != null)
            {
                comment.LikeThisComment();
            }
        }
Esempio n. 5
0
        public FacebookCommentCardViewModel(FacebookComment facebookComment) : base()
        {
            _facebookComment = facebookComment;
            _facebookService = IocContainer.GetContainer().Resolve <IFacebookService> ();

            ShowTimeline         = true;
            ShowCommentButton    = false;
            ShowShareButton      = false;
            ShowDateTime         = false;
            ShowSocialMediaImage = false;
        }
        /// <summary>
        /// Creates Facebook comment by parsing JSON data from content of HTTP message.
        /// </summary>
        /// <param name="msgJson">JSON data from content of HTTP message.</param>
        /// <param name="exportObject">For referencing FacebookSnooperExport from Facebook object.</param>
        /// <param name="index">Index to array inside JSON data where we can relevant data.</param>
        /// <returns>Parsed comment from HTTP content.</returns>
        private static FacebookComment GetFacebookComment(JObject msgJson, SnooperExportBase exportObject, int index)
        {
            var parsedComment = new FacebookComment(exportObject)
            {
                Text        = (string)msgJson["ms"][index]["comments"][0]["body"]["text"],
                SenderId    = (ulong)msgJson["ms"][index]["comments"][0]["author"],
                FbTimeStamp = (ulong)msgJson["ms"][index]["comments"][0]["timestamp"]["time"]
            };

            return(parsedComment);
        }
        public void CreateComment_ShouldAddZeroParentId_WhenParentIdNotProvided()
        {
            // Arrange
            var comment = new FacebookComment
            {
                Message = string.Empty,
                From    = new FacebookCommentUser()
            };

            var formatter = new DisqusCommentsFormatter();

            // Act
            var result = formatter.CreateComment(comment);

            // Assert
            result.Descendants(_wp + "comment_parent").FirstOrDefault().Value.Should().Be("0");
        }
Esempio n. 8
0
        /// <summary>
        /// Gets all the Comments written by the Facebook users on a post.
        /// </summary>
        /// <param name="postId">Facebook post ID</param>
        /// <returns>Returns the list of comments for the post</returns>
        public IEnumerable <FacebookComment> GetAllCommentsForPost(string postId)
        {
            #region Initialize objects and Url
            string Url  = string.Format("{0}/{2}/comments?access_token={1}", _baseUrl, AccessToken, postId);
            var    json = new JavaScriptSerializer();
            List <FacebookComment> commentsList = new List <FacebookComment>();
            #endregion

            using (var webClient = new WebClient())
            {
                string data = webClient.DownloadString(Url);

                #region parse returned data

                var      comments      = (Dictionary <string, object>)json.DeserializeObject(data);
                object[] commentsArray = (object[])comments.FirstOrDefault(p => p.Key == "data").Value;
                if (commentsArray.Count() > 0)
                {
                    foreach (object comment in commentsArray)
                    {
                        FacebookComment             facebookComment = null;
                        Dictionary <string, object> comment2        = (Dictionary <string, object>)comment;
                        if (comment2.Keys.Contains("message") && null != comment2["message"])
                        {
                            facebookComment                    = new FacebookComment();
                            facebookComment.CommentText        = comment2["message"].ToString();
                            facebookComment.Id                 = comment2["id"].ToString();
                            facebookComment.CreatedDateAndTime = null != comment2["created_time"] ? Convert.ToDateTime(comment2["created_time"].ToString()) : DateTime.MinValue;
                            Dictionary <string, object> commentedUser = (Dictionary <string, object>)comment2["from"];
                            if (commentedUser.Keys.Contains("name") && null != commentedUser["name"])
                            {
                                facebookComment.User = GetUserProfile(commentedUser["id"].ToString());
                            }
                            facebookComment.IsSupportive = (null != comment2["user_likes"] ? Convert.ToBoolean(comment2["user_likes"].ToString()) : false);
                            commentsList.Add(facebookComment);
                        }
                    }
                }

                #endregion
            }
            return(commentsList);
        }
Esempio n. 9
0
        public XElement CreateComment(FacebookComment comment, string parentId = "0")
        {
            if (comment == null)
            {
                throw new ArgumentNullException(nameof(comment));
            }

            var commentElement = new XElement(_wpNs + "comment",
                                              new XElement(_wpNs + "comment_id", comment.Id),
                                              new XElement(_wpNs + "comment_author", comment.From.Name),
                                              new XElement(_wpNs + "comment_author_email", string.Empty),
                                              new XElement(_wpNs + "comment_author_url", string.Empty),
                                              new XElement(_wpNs + "comment_author_IP", string.Empty),
                                              new XElement(_wpNs + "comment_date_gmt", comment.CreatedTime.ToString("yyyy-MM-dd HH:MM:ss")),
                                              new XElement(_wpNs + "comment_content", new XCData(comment.Message)),
                                              new XElement(_wpNs + "comment_approved", "1"),
                                              new XElement(_wpNs + "comment_parent", parentId)
                                              );

            return(commentElement);
        }
Esempio n. 10
0
        public override async Task Reply(string message)
        {
            // TODO: Grab the comment from the response and save the id
            var account = _facebookHelper.GetAccount();
//			var response = await _facebookService.Comment (_facebookPost.Id, message);
            var comment = new FacebookComment()
            {
                Id            = Guid.NewGuid().ToString(),
                CreatedAt     = DateTime.Now,
                Message       = message,
                LikedCount    = 0,
                IsLikedByUser = false,
                User          = new FacebookUser()
                {
                    Id   = account.Properties["id"],
                    Name = account.Username,
                }
            };

            IsCommentedByUser = true;
            _facebookPost.Comments.Add(comment);
        }