Skip to content

Commit 3f24259

Browse files
Add a "we've moved" banner
Show error if new topic can't be created Send notifications for people involved in thread that it's continuing elsewhere
1 parent 9fed834 commit 3f24259

File tree

6 files changed

+155
-13
lines changed

6 files changed

+155
-13
lines changed

OurUmbraco.Site/Views/Forum.cshtml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
}
55

66
<!-- FORUM OVERVIEW START -->
7+
@if (System.Configuration.ConfigurationManager.AppSettings["DiscourseEnabled"] == "true")
8+
{
9+
<div style="width: 100%;" class="alertbar__red">
10+
<h2 style="color: black; font-size: 50px; text-align: center; line-height: 50px; text-decoration: underline;">We have moved!</h2>
11+
<p style="font-size:20px; text-align: center; line-height: 50px; color: black; margin: 0 auto;max-width: 1000px;">
12+
The forum has a new home. Go to <a href="https://forum.umbraco.com">forum.umbraco.com</a> for the new forum.<br />
13+
You can continue any existing topic by scrolling to the last reply and tapping the "Continue discussion button.
14+
</p>
15+
</div>
16+
}
17+
718
<section class="forum-overview">
819
<div class="forum-archive">
920
@Html.Partial("~/Views/Partials/Forum/Forum.cshtml")

OurUmbraco.Site/Views/Partials/Forum/ForumActions.cshtml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage
44

55
<div class="utility-actions">
6-
@if (MemberData != null)
6+
@if (MemberData != null && System.Configuration.ConfigurationManager.AppSettings["DiscourseEnabled"] == "false")
77
{
88
if (Model.Content.AncestorOrSelfIsArchived() == false && Model.Content.NewTopicsAllowed())
99
{
@@ -28,9 +28,12 @@
2828
}
2929
else
3030
{
31-
<a href="/member/login?redirectUrl=@(Server.UrlEncode(Request.Url.AbsoluteUri))" class="button login">
32-
<i class="icon-Add"></i><span>Sign in to ask a question</span>
33-
</a>
31+
if (System.Configuration.ConfigurationManager.AppSettings["DiscourseEnabled"] == "false")
32+
{
33+
<a href="/member/login?redirectUrl=@(Server.UrlEncode(Request.Url.AbsoluteUri))" class="button login">
34+
<i class="icon-Add"></i><span>Sign in to ask a question</span>
35+
</a>
36+
}
3437
}
3538

3639
</div>

OurUmbraco.Site/Views/Partials/Forum/Thread.cshtml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@
115115

116116
@if (System.Configuration.ConfigurationManager.AppSettings["DiscourseEnabled"] == "true")
117117
{
118+
var discourseBlogPostUrl = System.Configuration.ConfigurationManager.AppSettings["DiscourseBlogPostUrl"];
119+
118120
<li class="comment" data-parent="0">
119121
<div class="comment-inner">
120122
<div class="body">
121123
<div>
122-
<p style="font-size: 1.2em; font-weight: bold;">This forum is in read-only mode [LINK TO EXPLANATION].</p>
124+
<p style="font-size: 1.2em; font-weight: bold;"><a href="@discourseBlogPostUrl" target="_blank">This forum is in read-only mode</a> while we transition to the new forum.</p>
123125
</div>
124126
@if (Model.DiscourseTopic != null)
125127
{
@@ -144,11 +146,11 @@
144146
{
145147
<p style="font-size: 1.2em; font-weight: bold;">You can continue this topic on the <a href="https://forum.umbraco.com">new forum</a> by tapping the "Continue discussion" link below.</p>
146148
<p>
147-
<a href="#" id="create-topic">Continue Discussion</a>
149+
<a href="#" id="create-topic" class="continue">Continue discussion</a>
148150
</p>
149151

150152
<style type="text/css">
151-
.ready {
153+
.ready, .continue {
152154
background-color: #4CAF50;
153155
color: white;
154156
padding: 10px 24px;
@@ -160,6 +162,9 @@
160162
cursor: pointer;
161163
border-radius: 8px;
162164
}
165+
.continue {
166+
background-color: #3544b1;
167+
}
163168
</style>
164169
<script type="text/javascript">
165170
$('#create-topic').click(function() {
@@ -173,12 +178,18 @@
173178
body: JSON.stringify({ "TopicId": @Model.Id })
174179
});
175180
const content = await rawResponse.json();
176-
const linkElement = $('#create-topic');
177-
linkElement.attr('href', content);
178-
linkElement.attr('id', '');
179-
linkElement.html('Continue to the new topic');
180-
linkElement.addClass('ready')
181-
linkElement.unbind('click');
181+
if (content == null) {
182+
alert('An error occurred while creating the topic. Please try again later.');
183+
return;
184+
} else {
185+
const linkElement = $('#create-topic');
186+
linkElement.attr('href', content);
187+
linkElement.attr('id', '');
188+
linkElement.html('Continue to the new topic');
189+
linkElement.addClass('ready')
190+
linkElement.removeClass('continue')
191+
linkElement.unbind('click');
192+
}
182193
})();
183194
});
184195
</script>

OurUmbraco.Site/web.vsts.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@
169169
<add key="DiscourseApiBaseUrl" value="https://forum.umbraco.com/" />
170170
<add key="DiscourseApiUsername" value="system" />
171171
<add key="DiscourseApiKey" value="#{DiscourseApiKey}#" />
172+
<add key="DiscourseWebhookSecret" value="#{DiscourseWebhookSecret}" />
173+
<add key="DiscourseBlogPostUrl" value="https://community.umbraco.com/blog/something" />
172174
<add key="OurUmbracoUrl" value="https://our.umbraco.com/" />
173175
</appSettings>
174176
<connectionStrings>

OurUmbraco/Forum/Controllers/DiscourseController.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Umbraco.Web.WebApi;
99
using System.Collections.Generic;
1010
using System.Linq;
11+
using System.Web;
1112

1213
namespace OurUmbraco.Forum.Controllers
1314
{
@@ -36,6 +37,26 @@ public IHttpActionResult Post(TopicModel topicModel)
3637
return Ok(redirectUrl);
3738
}
3839

40+
[HttpPost]
41+
public IHttpActionResult TopicCreated(DiscourseTopicModel topicModel)
42+
{
43+
var secret = HttpContext.Current.Request.QueryString["secret"];
44+
if (secret == System.Configuration.ConfigurationManager.AppSettings["DiscourseWebhookSecret"])
45+
{
46+
// this is called as a webhook from Discourse to Our - it contains any newly created topic.
47+
// If it has an external id that matches a forum post on Our, we notify the people involved in the thread.
48+
var newUrl = "https://forum.umbraco.com/t/" + topicModel.Topic.Slug + "/" + topicModel.Topic.Id;
49+
50+
if (int.TryParse(topicModel.Topic.ExternalId, out int externalId))
51+
{
52+
var newForumCommentNotification = new NotificationsCore.Notifications.NewForumComment();
53+
newForumCommentNotification.SendNewForumTopicCreatedNotification(externalId, newUrl);
54+
}
55+
}
56+
57+
return Ok();
58+
}
59+
3960
private string CreateTopicOnDiscourse(DiscourseCreateTopic createTopic)
4061
{
4162
var forumBaseUrl = System.Configuration.ConfigurationManager.AppSettings["DiscourseApiBaseUrl"];
@@ -132,5 +153,28 @@ internal class DiscoursePost
132153
[JsonProperty("post_url")]
133154
public string PostUrl { get; set; }
134155
}
156+
157+
// the model that the webhook sends us
158+
public class DiscourseTopicModel
159+
{
160+
[JsonProperty("topic")]
161+
public Topic Topic { get; set; }
162+
}
163+
164+
public class Topic
165+
{
166+
[JsonProperty("id")]
167+
public int Id { get; set; }
168+
169+
[JsonProperty("title")]
170+
public string Title { get; set; }
171+
172+
[JsonProperty("slug")]
173+
public string Slug { get; set; }
174+
175+
[JsonProperty("external_id")]
176+
public string ExternalId { get; set; }
177+
}
178+
135179
}
136180
}

OurUmbraco/NotificationsCore/Notifications/NewForumComment.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,76 @@ public void SendNotification(Comment comment, string memberName, string url)
9292
}
9393
}
9494
}
95+
96+
public void SendNewForumTopicCreatedNotification(int topicId, string newUrl)
97+
{
98+
var topicService = new TopicService(ApplicationContext.Current.DatabaseContext);
99+
var topic = topicService.GetById(topicId);
100+
101+
var db = ApplicationContext.Current.DatabaseContext.Database;
102+
var sql = new Sql().Select("memberId")
103+
.From("forumTopicSubscribers")
104+
.Where("topicId = @topicId", new { topicId = topic.Id });
105+
106+
var results = db.Query<int>(sql).ToList();
107+
108+
using (ContextHelper.EnsureHttpContext())
109+
{
110+
var memberShipHelper = new MembershipHelper(UmbracoContext.Current);
111+
112+
foreach (var memberId in results)
113+
{
114+
try
115+
{
116+
var member = memberShipHelper.GetById(memberId);
117+
if (member.GetPropertyValue<bool>("bugMeNot"))
118+
continue;
119+
120+
var from = new MailAddress(_details.SelectSingleNode("//from/email").InnerText,
121+
_details.SelectSingleNode("//from/name").InnerText);
122+
123+
//var subject = string.Format(_details.SelectSingleNode("//subject").InnerText, topic.Title);
124+
var subject = $"The forum topic '{topic.Title}' is continued on the new forum";
125+
126+
var domain = _details.SelectSingleNode("//domain").InnerText;
127+
var discourseBlogPostUrl = System.Configuration.ConfigurationManager.AppSettings["DiscourseBlogPostUrl"];
128+
var body = $@"Someone is continuing a topic you were involved in.
129+
130+
--------------------------------------------------
131+
132+
The topic with title '{topic.Title}' has been moved from it's old URL (https://{domain}{topic.GetUrl()}) to the new forum.
133+
134+
You can view the new topic here:
135+
{newUrl}
136+
137+
The forum is moving to a new platform, and we invite you to join us there. You can read all about the new forum in the following blog post: {discourseBlogPostUrl}
138+
139+
Thank You from the Umbraco Community!
140+
--------------------------------------------------
141+
You get this notification because you are subscribed to the topic's forum notifications.
142+
You can unsubscribe from your profile on our.umbraco.com";
143+
144+
var mailMessage = new MailMessage
145+
{
146+
Subject = subject,
147+
Body = body
148+
};
149+
150+
mailMessage.To.Add(member.GetPropertyValue<string>("Email"));
151+
mailMessage.From = @from;
152+
153+
using (var smtpClient = new SmtpClient())
154+
{
155+
smtpClient.Send(mailMessage);
156+
}
157+
}
158+
catch (Exception exception)
159+
{
160+
LogHelper.Error<NewForumComment>(
161+
string.Format("Error sending mail to member id {0}", memberId), exception);
162+
}
163+
}
164+
}
165+
}
95166
}
96167
}

0 commit comments

Comments
 (0)