예제 #1
0
파일: Thread.cs 프로젝트: Izuzusama/4charm
 /// <summary>
 /// Construct a thread from an initial post and a board.
 /// </summary>
 /// <param name="board">The parent board out of the board cache.</param>
 /// <param name="op">The first post in the thread.</param>
 public Thread(Board board, APIPost op)
 {
     Board = board;
     Number = op.Number;
     Posts = new SortedDictionary<ulong, Post>();
     Merge(op);
 }
예제 #2
0
파일: Post.cs 프로젝트: Izuzusama/4charm
 /// <summary>
 /// Create a post, given a parent thread and a data set returned by the API.
 /// </summary>
 /// <param name="thread">The parent thread.</param>
 /// <param name="post">Post returned by API.</param>
 public Post(Thread thread, APIPost post)
 {
     Thread = thread;
     Quotes = new HashSet<ulong>();
     Merge(post);
 }
예제 #3
0
파일: Thread.cs 프로젝트: Izuzusama/4charm
 /// <summary>
 /// Merge a post into the thread. If the post is already in the thread, it will be updated
 /// in-place with the new information, otherwise the post is inserted in the correct position.
 /// </summary>
 /// <param name="p">The post to merge into the thread.</param>
 public void Merge(APIPost p)
 {
     if (Posts.ContainsKey(p.Number))
     {
         Posts[p.Number].Merge(p);
     }
     else
     {
         Posts[p.Number] = new Post(this, p);
     }
 }
예제 #4
0
파일: Post.cs 프로젝트: Izuzusama/4charm
        /// <summary>
        /// Merge a new set of information retrieved from the API into this post.
        /// </summary>
        /// <param name="post">The post to update this with.</param>
        public void Merge(APIPost post)
        {
            Number = post.Number;
            IsSticky = post.IsSticky;
            IsClosed = post.IsClosed;
            FileDeleted = post.FileDeleted;
            Time = UnixEpoch.AddSeconds(post.TimeStamp);
            Subject = post.Subject;
            Tripcode = post.Tripcode;
            CapCode = post.CapCode;
            RenamedFileName = post.RenamedFileName;
            FileName = post.FileName;
            FileType = post.FileType;
            Comment = post.Comment;
            PostCount = post.Replies;
            ImageCount = post.Images;
            ImageWidth = post.ImageWidth;
            ImageHeight = post.ImageHeight;

            // When fetching from the API, we need to translate some stray entities for correct display.
            if (Subject != null)
            {
                Subject = WebUtility.HtmlDecode(Subject).Replace("&#039;", "'").Replace("&#44;", ",");
            }

            // There is an API bug when mods do things wrong and sometimes the post name has an HTML span
            // in it.
            string modName = post.Name;
            if (modName != null && modName.StartsWith("<span"))
            {
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(modName);
                if (CapCode == APIPost.CapCodes.none) CapCode = APIPost.CapCodes.quiet_mod;
                Name = doc.DocumentNode.InnerText;
            }
            else
            {
                Name = post.Name;
            }
            if (Name != null)
            {
                // Names also need to have some stray entities decoded.
                Name = WebUtility.HtmlDecode(Name).Replace("&#039;", "'").Replace("&#44;", ",");
            }

            FindQuotes();
        }