THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

mail: Add previous content in the notification mail

tags/v1.11.0
Suwon Chae 1 year ago
parent
commit
3e8084d7e0
5 changed files with 49 additions and 5 deletions
  1. +16
    -0
      app/controllers/IssueApp.java
  2. +3
    -0
      app/models/Comment.java
  3. +4
    -3
      app/models/NotificationEvent.java
  4. +25
    -1
      app/utils/JodaDateUtil.java
  5. +1
    -1
      app/utils/Markdown.java

+ 16
- 0
app/controllers/IssueApp.java View File

@@ -37,6 +37,8 @@ import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.*;

import static utils.JodaDateUtil.getOptionalShortDate;

@AnonymousCheck
public class IssueApp extends AbstractPostingApp {
private static final String EXCEL_EXT = "xls";
@@ -897,6 +899,16 @@ public class IssueApp extends AbstractPostingApp {
if(StringUtils.isNotEmpty(comment.parentCommentId)){
comment.setParentComment(IssueComment.find.byId(Long.valueOf(comment.parentCommentId)));
}

if(issue.comments.size() == 0) {
User user = User.find.byId(issue.authorId);
comment.previousContents = getPrevious("Original issue", issue.body, issue.updatedDate, user.loginId);
} else {
Comment previousComment = issue.comments.get(issue.comments.size() - 1);
User user = User.find.byId(previousComment.authorId);
comment.previousContents = getPrevious("Previous comment", previousComment.contents, previousComment.createdDate, user.loginId);
}

Comment savedComment = saveComment(project, issue, comment);

if( containsStateTransitionRequest() ){
@@ -912,6 +924,10 @@ public class IssueApp extends AbstractPostingApp {
return redirect(RouteUtil.getUrl(savedComment));
}

private static String getPrevious(String templateTitle, String contents, Date updatedDate, String authorLoginId) {
return "\n\n<br />\n\n--- " + templateTitle + " from @" + authorLoginId + " " + getOptionalShortDate(updatedDate) + " ---\n\n<br />\n\n" + contents;
}

// Just made for compatibility. No meanings.
public static Result updateComment(String ownerName, String projectName, Long number, Long commentId) throws IOException {
return newComment(ownerName, projectName, number);


+ 3
- 0
app/models/Comment.java View File

@@ -44,6 +44,9 @@ abstract public class Comment extends Model implements TimelineItem, ResourceCon
@Transient
public String parentCommentId;

@Transient
public String previousContents;

public Comment() {
createdDate = new Date();
}


+ 4
- 3
app/models/NotificationEvent.java View File

@@ -142,11 +142,12 @@ public class NotificationEvent extends Model implements INotificationEvent {
}
case NEW_ISSUE:
case NEW_POSTING:
case NEW_COMMENT:
case NEW_PULL_REQUEST:
case NEW_COMMIT:
case COMMENT_UPDATED:
return newValue;
case NEW_COMMENT:
return newValue + oldValue;
case ISSUE_BODY_CHANGED:
case POSTING_BODY_CHANGED:
return DiffUtil.getDiffText(oldValue, newValue);
@@ -240,7 +241,7 @@ public class NotificationEvent extends Model implements INotificationEvent {
case POSTING_BODY_CHANGED:
return DiffUtil.getDiffPlainText(oldValue, newValue);
default:
return getMessage(lang);
return getMessage(lang).replaceAll("\n\n<br />\n", "\n\n");
}
}

@@ -760,7 +761,7 @@ public class NotificationEvent extends Model implements INotificationEvent {
notiEvent.title = formatReplyTitle(post);
notiEvent.eventType = eventType;
notiEvent.receivers = getMandatoryReceivers(comment, eventType);
notiEvent.oldValue = null;
notiEvent.oldValue = comment.previousContents;
notiEvent.newValue = comment.contents;
notiEvent.resourceType = comment.asResource().getType();
notiEvent.resourceId = comment.asResource().getId();


+ 25
- 1
app/utils/JodaDateUtil.java View File

@@ -117,7 +117,6 @@ public class JodaDateUtil {
return dateTime.toString("yyyyMMddHHmm", Locale.getDefault());
}


public static String geYMDDate(Date date){
if (date == null) {
return "";
@@ -125,4 +124,29 @@ public class JodaDateUtil {
DateTime dateTime = new DateTime(date);
return dateTime.toString("yyyy-MM-dd", Locale.getDefault());
}

public static String getOptionalShortDate(Date date){
if (date == null) {
return "";
}
DateTime targetTime = new DateTime(date);
DateTime currentTime = new DateTime(new Date());

if(isSameYear(targetTime, currentTime)) {
if(isSameDay(targetTime, currentTime)) {
return targetTime.toString("'at' h:mm a", Locale.getDefault());
}
return targetTime.toString("MMM d 'at' h:mm a", Locale.getDefault());
} else {
return targetTime.toString("YY.MM.dd at h:mm a", Locale.getDefault());
}
}

private static boolean isSameYear(DateTime targetTime, DateTime currentTime) {
return currentTime.toString("YYYY").equals(targetTime.toString("YYYY"));
}

private static boolean isSameDay(DateTime targetTime, DateTime currentTime) {
return currentTime.toString("YYYYMMdd").equals(targetTime.toString("YYYYMMdd"));
}
}

+ 1
- 1
app/utils/Markdown.java View File

@@ -46,7 +46,7 @@ public class Markdown {
.allowElements("input")
.allowAttributes("type", "disabled", "checked").onElements("input")
.toFactory())
.and(new HtmlPolicyBuilder().allowElements("pre").toFactory())
.and(new HtmlPolicyBuilder().allowElements("pre", "br", "hr").toFactory())
.and(new HtmlPolicyBuilder()
.allowAttributes("class", "id", "style", "width", "height").globally().toFactory());



Loading…
Cancel
Save