public Dictionary <int, BugComment[]> GetComments(int[] bugIds, bool withAttachments) { BugGetComments args = new BugGetComments(); args.ids = bugIds; GetCommentsResult res = Proxy.GetComments(args); Dictionary <int, BugComment[]> dict = new Dictionary <int, BugComment[]> (); List <int> attIds = new List <int>(); Dictionary <int, BugComment> attTargets = new Dictionary <int, BugComment> (); foreach (DictionaryEntry e in res.bugs) { string bugId = (string)e.Key; XmlRpcStruct cms = (XmlRpcStruct)e.Value; object[] cmsArray = (object[])cms ["comments"]; List <BugComment> list = new List <BugComment> (); foreach (XmlRpcStruct cm in cmsArray) { BugComment c = new BugComment(); if (cm.Contains("attachment_id")) { c.attachment_id = (int)cm ["attachment_id"]; } c.author = (string)cm ["author"]; c.is_private = (bool)cm ["is_private"]; c.text = (string)cm ["text"]; c.time = (DateTime)cm ["time"]; list.Add(c); if (c.attachment_id != 0) { attIds.Add(c.attachment_id); attTargets [c.attachment_id] = c; } } dict [int.Parse(bugId)] = list.ToArray(); } if (withAttachments && attIds.Count > 0) { Dictionary <int, BugAttachment> atts = GetAttachments(attIds.ToArray()); foreach (BugAttachment at in atts.Values) { BugComment c = attTargets [at.id]; c.attachment = at; } } return(dict); }
public List <StreamComment> GetComments(StreamItem streamItem, PaginationRecord pg) { CommentApi commentApi = new CommentApi(session.GetApiClient()); try { CommentListV2OptionsRecord options = new CommentListV2OptionsRecord(); options.SortDir = "DESC"; options.HighlightTag = "mark"; options.CreatorFilter = "all"; options.ReadFilter = "all"; options.SortFilter = "updateTime"; AdditionalDataRecord additionalData = new AdditionalDataRecord(); additionalData.SubType = "general"; additionalData.FirstLevelCount = true; GetCommentsResult getCommentsResult = commentApi.GetComments(streamItem.Key, options.ToJson(), pg.ToJson(), streamItem.CommentListKey, additionalData.ToJson()); if (getCommentsResult.Hdr.Rc == 0) { commentsPager = getCommentsResult.Pager; List <StreamComment> comments = new List <StreamComment>(); List <CommentV2Record> commentRecords = getCommentsResult.Comments; foreach (CommentV2Record commentRecord in commentRecords) { StreamComment comment = new StreamComment(commentRecord, streamItem.RecordType); comments.Add(comment); } return(comments); } else { throw new Exception("Error getting comments for contentKey " + streamItem.Key); } } catch (Exception ex) { throw new Exception("Error getting comments for contentKey " + streamItem.Key, ex); } }
private static async Task <GetCommentsResult> GetCommentsResult(UserService _userService, CommentsDbModel comments, string userId) { var result = new GetCommentsResult(); result.Comments = new List <CommentItem>(); if (comments != null) { var list = comments.Comments.Where(c => !c.IsDeleted); foreach (var comment1 in list) { var commentItem = new CommentItem(); commentItem.Comment = comment1.Comment; commentItem.Id = comment1.Id; commentItem.DateCreate = comment1.DateCreate; commentItem.UserInfo = await _userService.GetUserInfoAsync(comment1.UserId); commentItem.CanDelete = comment1.UserId == userId; result.Comments.Add(commentItem); } } return(result); }