Skip to content

Commit

Permalink
fixed broken redirect after posting questions when using a custom con…
Browse files Browse the repository at this point in the history
…text path, fixes #176
  • Loading branch information
albogdano committed Jun 11, 2020
1 parent 42d6398 commit e6643a7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Expand Up @@ -24,7 +24,6 @@
import com.erudika.para.utils.Config;
import com.erudika.para.utils.Utils;
import static com.erudika.scoold.ScooldServer.COMMENTATOR_IFHAS;
import static com.erudika.scoold.ScooldServer.CONTEXT_PATH;
import static com.erudika.scoold.ScooldServer.HOMEPAGE;
import static com.erudika.scoold.ScooldServer.getServerURL;
import com.erudika.scoold.core.Comment;
Expand Down Expand Up @@ -155,7 +154,7 @@ private void sendCommentNotification(Post parentPost, Comment comment, Profile c
String name = commentAuthor.getName();
String body = Utils.markdownToHtml(comment.getComment());
String pic = Utils.formatMessage("<img src='{0}' width='25'>", commentAuthor.getPicture());
String postURL = getServerURL() + CONTEXT_PATH + parentPost.getPostLink(false, false);
String postURL = getServerURL() + parentPost.getPostLink(false, false);
model.put("logourl", Config.getConfigParam("small_logo_url", "https://scoold.com/logo.png"));
model.put("heading", Utils.formatMessage("New comment on <a href='{0}'>{1}</a>", postURL, parentPost.getTitle()));
model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div class='panel'>{2}</div>", pic, name, body));
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/erudika/scoold/core/Post.java
Expand Up @@ -475,12 +475,13 @@ public String getPostLink(boolean plural, boolean noid) {
Post p = this;
String ptitle = Utils.noSpaces(Utils.stripAndTrim(p.getTitle()), "-");
String pid = (noid ? "" : "/" + p.getId() + "/" + ptitle);
String ctx = ScooldServer.CONTEXT_PATH;
if (p.isQuestion()) {
return plural ? "/questions" : "/question" + pid;
return ctx + (plural ? ScooldServer.QUESTIONSLINK : ScooldServer.QUESTIONLINK + pid);
} else if (p.isFeedback()) {
return plural ? "/feedback" : "/feedback" + pid;
return ctx + ScooldServer.FEEDBACKLINK + (plural ? "" : pid);
} else if (p.isReply()) {
return "/question" + (noid ? "" : "/" + p.getParentid());
return ctx + ScooldServer.QUESTIONLINK + (noid ? "" : "/" + p.getParentid());
}
return "";
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/erudika/scoold/utils/ScooldUtils.java
Expand Up @@ -532,7 +532,7 @@ public void sendUpdatedFavTagsNotifications(Post question, List<String> addedTag
String name = postAuthor.getName();
String body = Utils.markdownToHtml(question.getBody());
String picture = Utils.formatMessage("<img src='{0}' width='25'>", postAuthor.getPicture());
String postURL = getServerURL() + CONTEXT_PATH + question.getPostLink(false, false);
String postURL = getServerURL() + question.getPostLink(false, false);
String tagsString = Optional.ofNullable(question.getTags()).orElse(Collections.emptyList()).stream().
map(t -> "<span class=\"tag\">" + (addedTags.contains(t) ? "<b>" + t + "<b>" : t) + "</span>").
collect(Collectors.joining("&nbsp;"));
Expand Down Expand Up @@ -560,7 +560,7 @@ public void sendNewPostNotifications(Post question) {
String name = postAuthor.getName();
String body = Utils.markdownToHtml(question.getBody());
String picture = Utils.formatMessage("<img src='{0}' width='25'>", postAuthor.getPicture());
String postURL = getServerURL() + CONTEXT_PATH + question.getPostLink(false, false);
String postURL = getServerURL() + question.getPostLink(false, false);
String tagsString = Optional.ofNullable(question.getTags()).orElse(Collections.emptyList()).stream().
map(t -> "<span class=\"tag\">" + t + "</span>").
collect(Collectors.joining("&nbsp;"));
Expand Down Expand Up @@ -592,7 +592,7 @@ public void sendReplyNotifications(Post parentPost, Post reply) {
String name = replyAuthor.getName();
String body = Utils.markdownToHtml(reply.getBody());
String picture = Utils.formatMessage("<img src='{0}' width='25'>", replyAuthor.getPicture());
String postURL = getServerURL() + CONTEXT_PATH + parentPost.getPostLink(false, false);
String postURL = getServerURL() + parentPost.getPostLink(false, false);
model.put("logourl", Config.getConfigParam("small_logo_url", "https://scoold.com/logo.png"));
model.put("heading", Utils.formatMessage("New reply to <a href='{0}'>{1}</a>", postURL, parentPost.getTitle()));
model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div>{2}</div>", picture, name, body));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/macro.vm
Expand Up @@ -888,7 +888,7 @@ $utils.formatDate($date, $format, $currentLocale)
#end
#end
#####################################
#macro(getpostlink $p $plural $noid)$!{request.contextPath}$p.getPostLink($plural, $noid)#end
#macro(getpostlink $p $plural $noid)$p.getPostLink($plural, $noid)#end
#####################################
#macro(ajaxloading $hide)
#if ($hide) #set($hidden = "hide") #else #set($hidden = "") #end
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/templates/questions.vm
Expand Up @@ -51,9 +51,11 @@
</div>
#end

<button class="btn mtl waves-effect waves-light" type="submit">
<i class="fa fa-paper-plane left"></i>$!lang.get('post')
</button>
<div>
<button class="btn mtl waves-effect waves-light" type="submit">
<i class="fa fa-paper-plane left"></i>$!lang.get('post')
</button>
</div>
</form>
</div>
#else
Expand Down

0 comments on commit e6643a7

Please sign in to comment.