public static int CreateCommentDiscussion(ArticleModel article) { Logger.Information("Creating comment discussion for article \"{0}\" (ID={1}).", article.Title, article.Id); var api = DiscourseHelper.CreateApi(); // create topic and embed <!--ARTICLEID:...--> in the body so the hacky JavaScript // for the "Feature" button can append the article ID to each of its query strings var topic = api.CreateTopic( new Category(Config.Discourse.CommentCategory), article.Title, string.Format( "Discussion for the article: {0}\r\n\r\n<!--ARTICLEID:{1}-->", article.Url, article.Id ) ); api.SetVisibility(topic.Id, false); StoredProcs .Articles_CreateOrUpdateArticle(article.Id, Discourse_Topic_Id: topic.Id) .Execute(); return(topic.Id); }
public static void OpenCommentDiscussion(int articleId, int topicId) { try { var api = DiscourseHelper.CreateApi(); api.SetVisibility(topicId, true); // delete the worthless auto-generated "this topic is now invisible/visible" rubbish var topic = api.GetTopic(topicId); foreach (var post in topic.Posts.Where(p => p.Type == Post.PostType.ModeratorAction)) { api.DeletePost(post.Id); } StoredProcs .Articles_CreateOrUpdateArticle(articleId, Discourse_Topic_Opened: YNIndicator.Yes) .Execute(); } catch (Exception ex) { throw new InvalidOperationException( string.Format("An unknown error occurred when attempting to open the Discourse discussion. " + "Verify that the article #{0} is assigned to a valid correct topic ID (currently #{1})", articleId, topicId), ex); } }
public static IList <Topic> GetSideBarWtfs() { try { return(DiscourseCache.GetOrAdd( "SideBarWtfs", () => { Logger.Debug("Getting Side Bar WTFs."); var api = DiscourseHelper.CreateApi(); return api.GetTopicsByCategory(new Category(Config.Discourse.SideBarWtfCategory)) .Where(topic => !topic.Pinned && topic.Visible) .Take(5) .ToList() .AsReadOnly(); } )); } catch (Exception ex) { Logger.Error("Error getting Side Bar WTFs, error: {0}", ex); return(new Topic[0]); } }
public static IList <Post> GetFeaturedCommentsForArticle(int articleId) { try { return(DiscourseCache.GetOrAdd( "FeaturedCommentsForArticle_" + articleId, () => { Logger.Debug("Getting and caching featured comments for article (ID={0}).", articleId); var api = DiscourseHelper.CreateApi(); return StoredProcs.Articles_GetFeaturedComments(articleId) .Execute() .Select(c => api.GetReplyPost(c.Discourse_Post_Id)) .Where(p => !p.Hidden) .ToList() .AsReadOnly(); } )); } catch (Exception ex) { Logger.Error("Error getting featured comments for article (ID={0}), error: {1}", articleId, ex); return(new Post[0]); } }
public static Topic GetDiscussionTopic(int topicId) { try { return(DiscourseCache.GetOrAdd( "Topic_" + topicId, () => { var api = DiscourseHelper.CreateApi(); return api.GetTopic(topicId); } )); } catch (Exception ex) { throw new InvalidOperationException( string.Format("An unknown error occurred when attempting to get the Discourse topic #{0}. " + "Verify that this Discourse topic ID actually exists (e.g. /t/{0} relative to forum)", topicId), ex); } }
public static IList <Topic> GetSideBarWtfs() { try { return(DiscourseCache.GetOrAdd( "SideBarWtfs", () => { var api = DiscourseHelper.CreateApi(); return api.GetTopicsByCategory(new Category(Config.Discourse.SideBarWtfCategory)) .Where(topic => !topic.Pinned && topic.Visible) .Take(5) .ToList() .AsReadOnly(); } )); } catch { return(new Topic[0]); } }
public static IList <Post> GetFeaturedCommentsForArticle(int articleId) { try { return(DiscourseCache.GetOrAdd( "FeaturedCommentsForArticle_" + articleId, () => { var api = DiscourseHelper.CreateApi(); return StoredProcs.Articles_GetFeaturedComments(articleId) .Execute() .Select(c => api.GetReplyPost(c.Discourse_Post_Id)) .Where(p => !p.Hidden) .ToList() .AsReadOnly(); } )); } catch { return(new Post[0]); } }