[Notice] Announcing the End of Demo Server [Read me]
mail: Add previous content in the notification mail
@3e8084d7e0f200ae9355600b62a34c04635c3c33
--- app/controllers/IssueApp.java
+++ app/controllers/IssueApp.java
... | ... | @@ -37,6 +37,8 @@ |
37 | 37 |
import java.io.IOException; |
38 | 38 |
import java.util.*; |
39 | 39 |
|
40 |
+import static utils.JodaDateUtil.getOptionalShortDate; |
|
41 |
+ |
|
40 | 42 |
@AnonymousCheck |
41 | 43 |
public class IssueApp extends AbstractPostingApp { |
42 | 44 |
private static final String EXCEL_EXT = "xls"; |
... | ... | @@ -897,6 +899,16 @@ |
897 | 899 |
if(StringUtils.isNotEmpty(comment.parentCommentId)){ |
898 | 900 |
comment.setParentComment(IssueComment.find.byId(Long.valueOf(comment.parentCommentId))); |
899 | 901 |
} |
902 |
+ |
|
903 |
+ if(issue.comments.size() == 0) { |
|
904 |
+ User user = User.find.byId(issue.authorId); |
|
905 |
+ comment.previousContents = getPrevious("Original issue", issue.body, issue.updatedDate, user.loginId); |
|
906 |
+ } else { |
|
907 |
+ Comment previousComment = issue.comments.get(issue.comments.size() - 1); |
|
908 |
+ User user = User.find.byId(previousComment.authorId); |
|
909 |
+ comment.previousContents = getPrevious("Previous comment", previousComment.contents, previousComment.createdDate, user.loginId); |
|
910 |
+ } |
|
911 |
+ |
|
900 | 912 |
Comment savedComment = saveComment(project, issue, comment); |
901 | 913 |
|
902 | 914 |
if( containsStateTransitionRequest() ){ |
... | ... | @@ -912,6 +924,10 @@ |
912 | 924 |
return redirect(RouteUtil.getUrl(savedComment)); |
913 | 925 |
} |
914 | 926 |
|
927 |
+ private static String getPrevious(String templateTitle, String contents, Date updatedDate, String authorLoginId) { |
|
928 |
+ return "\n\n<br />\n\n--- " + templateTitle + " from @" + authorLoginId + " " + getOptionalShortDate(updatedDate) + " ---\n\n<br />\n\n" + contents; |
|
929 |
+ } |
|
930 |
+ |
|
915 | 931 |
// Just made for compatibility. No meanings. |
916 | 932 |
public static Result updateComment(String ownerName, String projectName, Long number, Long commentId) throws IOException { |
917 | 933 |
return newComment(ownerName, projectName, number); |
--- app/models/Comment.java
+++ app/models/Comment.java
... | ... | @@ -44,6 +44,9 @@ |
44 | 44 |
@Transient |
45 | 45 |
public String parentCommentId; |
46 | 46 |
|
47 |
+ @Transient |
|
48 |
+ public String previousContents; |
|
49 |
+ |
|
47 | 50 |
public Comment() { |
48 | 51 |
createdDate = new Date(); |
49 | 52 |
} |
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
... | ... | @@ -142,11 +142,12 @@ |
142 | 142 |
} |
143 | 143 |
case NEW_ISSUE: |
144 | 144 |
case NEW_POSTING: |
145 |
- case NEW_COMMENT: |
|
146 | 145 |
case NEW_PULL_REQUEST: |
147 | 146 |
case NEW_COMMIT: |
148 | 147 |
case COMMENT_UPDATED: |
149 | 148 |
return newValue; |
149 |
+ case NEW_COMMENT: |
|
150 |
+ return newValue + oldValue; |
|
150 | 151 |
case ISSUE_BODY_CHANGED: |
151 | 152 |
case POSTING_BODY_CHANGED: |
152 | 153 |
return DiffUtil.getDiffText(oldValue, newValue); |
... | ... | @@ -240,7 +241,7 @@ |
240 | 241 |
case POSTING_BODY_CHANGED: |
241 | 242 |
return DiffUtil.getDiffPlainText(oldValue, newValue); |
242 | 243 |
default: |
243 |
- return getMessage(lang); |
|
244 |
+ return getMessage(lang).replaceAll("\n\n<br />\n", "\n\n"); |
|
244 | 245 |
} |
245 | 246 |
} |
246 | 247 |
|
... | ... | @@ -760,7 +761,7 @@ |
760 | 761 |
notiEvent.title = formatReplyTitle(post); |
761 | 762 |
notiEvent.eventType = eventType; |
762 | 763 |
notiEvent.receivers = getMandatoryReceivers(comment, eventType); |
763 |
- notiEvent.oldValue = null; |
|
764 |
+ notiEvent.oldValue = comment.previousContents; |
|
764 | 765 |
notiEvent.newValue = comment.contents; |
765 | 766 |
notiEvent.resourceType = comment.asResource().getType(); |
766 | 767 |
notiEvent.resourceId = comment.asResource().getId(); |
--- app/utils/JodaDateUtil.java
+++ app/utils/JodaDateUtil.java
... | ... | @@ -117,7 +117,6 @@ |
117 | 117 |
return dateTime.toString("yyyyMMddHHmm", Locale.getDefault()); |
118 | 118 |
} |
119 | 119 |
|
120 |
- |
|
121 | 120 |
public static String geYMDDate(Date date){ |
122 | 121 |
if (date == null) { |
123 | 122 |
return ""; |
... | ... | @@ -125,4 +124,29 @@ |
125 | 124 |
DateTime dateTime = new DateTime(date); |
126 | 125 |
return dateTime.toString("yyyy-MM-dd", Locale.getDefault()); |
127 | 126 |
} |
127 |
+ |
|
128 |
+ public static String getOptionalShortDate(Date date){ |
|
129 |
+ if (date == null) { |
|
130 |
+ return ""; |
|
131 |
+ } |
|
132 |
+ DateTime targetTime = new DateTime(date); |
|
133 |
+ DateTime currentTime = new DateTime(new Date()); |
|
134 |
+ |
|
135 |
+ if(isSameYear(targetTime, currentTime)) { |
|
136 |
+ if(isSameDay(targetTime, currentTime)) { |
|
137 |
+ return targetTime.toString("'at' h:mm a", Locale.getDefault()); |
|
138 |
+ } |
|
139 |
+ return targetTime.toString("MMM d 'at' h:mm a", Locale.getDefault()); |
|
140 |
+ } else { |
|
141 |
+ return targetTime.toString("YY.MM.dd at h:mm a", Locale.getDefault()); |
|
142 |
+ } |
|
143 |
+ } |
|
144 |
+ |
|
145 |
+ private static boolean isSameYear(DateTime targetTime, DateTime currentTime) { |
|
146 |
+ return currentTime.toString("YYYY").equals(targetTime.toString("YYYY")); |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ private static boolean isSameDay(DateTime targetTime, DateTime currentTime) { |
|
150 |
+ return currentTime.toString("YYYYMMdd").equals(targetTime.toString("YYYYMMdd")); |
|
151 |
+ } |
|
128 | 152 |
} |
--- app/utils/Markdown.java
+++ app/utils/Markdown.java
... | ... | @@ -46,7 +46,7 @@ |
46 | 46 |
.allowElements("input") |
47 | 47 |
.allowAttributes("type", "disabled", "checked").onElements("input") |
48 | 48 |
.toFactory()) |
49 |
- .and(new HtmlPolicyBuilder().allowElements("pre").toFactory()) |
|
49 |
+ .and(new HtmlPolicyBuilder().allowElements("pre", "br", "hr").toFactory()) |
|
50 | 50 |
.and(new HtmlPolicyBuilder() |
51 | 51 |
.allowAttributes("class", "id", "style", "width", "height").globally().toFactory()); |
52 | 52 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?