/// <summary> /// Add the provided vote to the output in compact format. /// </summary> /// <param name="vote">The vote to add.</param> private void AddCompactVote(KeyValuePair <string, HashSet <string> > vote) { List <string> voteLines = vote.Key.GetStringLines(); if (voteLines.Count == 0) { return; } int userCount = VoteInfo.CountVote(vote); string userCountMarker = userCount.ToString(); // Single-line votes are always shown. if (voteLines.Count == 1) { sb.AppendLine(VoteString.ModifyVoteLine(voteLines.First(), marker: userCountMarker)); return; } // Two-line votes can be shown if the second line is a sub-vote. if (voteLines.Count == 2 && !string.IsNullOrEmpty(VoteString.GetVotePrefix(voteLines.Last()))) { sb.AppendLine(VoteString.ModifyVoteLine(voteLines.First(), marker: userCountMarker)); sb.AppendLine(VoteString.ModifyVoteLine(voteLines.Last(), marker: userCountMarker)); return; } // Longer votes get condensed down to a link to the original post (and named after the first voter) string firstVoter = VoteInfo.GetFirstVoter(vote.Value); string task = VoteString.GetVoteTask(vote.Key); sb.Append($"[{userCountMarker}]"); if (!string.IsNullOrEmpty(task)) { sb.Append($"[{task}]"); } string link; if (firstVoter.StartsWith(StringUtility.PlanNameMarker, StringComparison.Ordinal)) { link = VoteInfo.GetVoterUrl(firstVoter, VoteType.Plan); } else { link = VoteInfo.GetVoterUrl(firstVoter, VoteType.Vote); } sb.Append($" Plan: {firstVoter} — {link}\r\n"); }
/// <summary> /// Function to get a line for one of the compact mode displays, /// based on whether this is a parent or child node. /// </summary> /// <param name="displayMode">The display mode currently being used.</param> /// <returns>Returns a string representation of the current vote node.</returns> public string GetLine(DisplayMode displayMode) { var lines = Text.GetStringLines(); if (lines.Count == 0) { return(string.Empty); } string results = string.Empty; if (HasChildren || (!HasParent && lines.Count == 1)) { // Parent node, or solitary node with 1 line. results = VoteString.ModifyVoteLine(lines[0], marker: VoterCount.ToString()); } else if (HasParent && lines.Count == 1) { // Child node with 1 line if (displayMode == DisplayMode.Compact) { results = VoteString.ModifyVoteLine(lines[0], prefix: "", marker: VoterCount.ToString()); } else { results = VoteString.ModifyVoteLine(lines[0], prefix: "-", marker: VoterCount.ToString()); } } else if (!HasChildren) { // Other nodes without children (typically child nodes). StringBuilder sb = new StringBuilder(); if (HasParent && displayMode == DisplayMode.CompactNoVoters) { sb.Append("-"); } sb.Append("["); sb.Append(VoterCount); sb.Append("]"); // Only explicitly add tasks to parent nodes if (!HasParent) { string task = VoteString.GetVoteTask(lines[0]); if (!string.IsNullOrEmpty(task)) { sb.Append($"[{task}]"); } } sb.Append(" Plan: "); string firstVoter = VoteInfo.GetFirstVoter(Voters); sb.Append(firstVoter); // Only add the link if we're not showing the voters if (displayMode == DisplayMode.CompactNoVoters) { string link; VoteType voteType = firstVoter.IsPlanName() ? VoteType.Plan : VoteType.Vote; link = VoteInfo.GetVoterUrl(firstVoter, voteType); sb.Append(" — "); sb.Append(link); } results = sb.ToString(); } // Child nodes in compact mode will be put in spoilers. Remove BBCode. if (HasParent && displayMode == DisplayMode.Compact) { results = VoteString.RemoveBBCode(results); } return(results); }