Skip to content

Commit

Permalink
Communication: Fix author and channel name order in notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Oct 5, 2024
1 parent 0634b5b commit 4d36797
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public static String[] createPlaceholdersForUserGroupChat(String courseTitle, St
}

@NotificationPlaceholderCreator(values = { CONVERSATION_ADD_USER_CHANNEL, CONVERSATION_REMOVE_USER_CHANNEL, CONVERSATION_DELETE_CHANNEL })
public static String[] createPlaceholdersForUserChannel(String courseTitle, String channelName, String responsibleForUserName) {
return new String[] { courseTitle, channelName, responsibleForUserName };
public static String[] createPlaceholdersForUserChannel(String courseTitle, String conversationName, String responsibleForUserName) {
return new String[] { courseTitle, conversationName, responsibleForUserName };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import de.tum.cit.aet.artemis.communication.domain.conversation.Channel;
import de.tum.cit.aet.artemis.communication.domain.conversation.Conversation;
import de.tum.cit.aet.artemis.communication.domain.conversation.GroupChat;
import de.tum.cit.aet.artemis.communication.domain.conversation.OneToOneChat;
import de.tum.cit.aet.artemis.communication.domain.notification.ConversationNotification;
import de.tum.cit.aet.artemis.communication.domain.notification.NotificationPlaceholderCreator;
import de.tum.cit.aet.artemis.communication.domain.notification.SingleUserNotification;
Expand Down Expand Up @@ -57,37 +58,39 @@ public ConversationNotificationService(ConversationNotificationRepository conver
* @return the created notification
*/
public ConversationNotification createNotification(Post createdMessage, Conversation conversation, Course course, Set<User> mentionedUsers) {
String notificationText;
String[] placeholders;
NotificationType notificationType = CONVERSATION_NEW_MESSAGE;
String conversationName = conversation.getHumanReadableNameForReceiver(createdMessage.getAuthor());
String conversationType;
String notificationText;

// add channel/groupChat/oneToOneChat string to placeholders for notification to distinguish in mobile client
if (conversation instanceof Channel channel) {
notificationText = NEW_MESSAGE_CHANNEL_TEXT;
placeholders = createPlaceholdersNewMessageChannelText(course.getTitle(), createdMessage.getContent(), createdMessage.getCreationDate().toString(),
createdMessage.getAuthor().getName(), conversationName, "channel");
notificationType = getNotificationTypeForChannel(channel);
}
else if (conversation instanceof GroupChat) {
notificationText = NEW_MESSAGE_GROUP_CHAT_TEXT;
placeholders = createPlaceholdersNewMessageChannelText(course.getTitle(), createdMessage.getContent(), createdMessage.getCreationDate().toString(),
createdMessage.getAuthor().getName(), conversationName, "groupChat");
}
else {
notificationText = NEW_MESSAGE_DIRECT_TEXT;
placeholders = createPlaceholdersNewMessageChannelText(course.getTitle(), createdMessage.getContent(), createdMessage.getCreationDate().toString(),
createdMessage.getAuthor().getName(), conversationName, "oneToOneChat");
switch (conversation) {
case Channel channel -> {
notificationText = NEW_MESSAGE_CHANNEL_TEXT;
conversationType = "channel";
notificationType = getNotificationTypeForChannel(channel);
}
case GroupChat ignored -> {
notificationText = NEW_MESSAGE_GROUP_CHAT_TEXT;
conversationType = "groupChat";
}
case OneToOneChat ignored -> {
notificationText = NEW_MESSAGE_DIRECT_TEXT;
conversationType = "oneToOneChat";
}
default -> throw new IllegalStateException("Unexpected value: " + conversation);
}
String[] placeholders = createPlaceholdersNewMessageChannelText(course.getTitle(), createdMessage.getContent(), createdMessage.getCreationDate().toString(),
conversationName, createdMessage.getAuthor().getName(), conversationType);
ConversationNotification notification = createConversationMessageNotification(course.getId(), createdMessage, notificationType, notificationText, true, placeholders);
save(notification, mentionedUsers, placeholders);
return notification;
}

@NotificationPlaceholderCreator(values = { CONVERSATION_NEW_MESSAGE })
public static String[] createPlaceholdersNewMessageChannelText(String courseTitle, String messageContent, String messageCreationDate, String channelName, String authorName,
String conversationType) {
return new String[] { courseTitle, messageContent, messageCreationDate, channelName, authorName, conversationType };
public static String[] createPlaceholdersNewMessageChannelText(String courseTitle, String messageContent, String messageCreationDate, String conversationName,
String authorName, String conversationType) {
return new String[] { courseTitle, messageContent, messageCreationDate, conversationName, authorName, conversationType };
}

private void save(ConversationNotification notification, Set<User> mentionedUsers, String[] placeHolders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void testSignatureHasNotChanged() throws URISyntaxException, IOException {
}

private String readPlaceholderText(URL url) throws URISyntaxException, IOException {
return Files.readString(Paths.get(url.toURI()));
return Files.readString(Paths.get(url.toURI())).strip();
}

private record ClassSignature(String notificationType, List<NotificationPlaceholderSignatureTest.FieldDescription> fieldDescriptions) implements Comparable<ClassSignature> {
Expand Down
10 changes: 5 additions & 5 deletions src/test/resources/placeholder-signatures.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"fieldName" : "courseTitle",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "channelName",
"fieldName" : "conversationName",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "responsibleForUserName",
Expand Down Expand Up @@ -49,7 +49,7 @@
"fieldName" : "courseTitle",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "channelName",
"fieldName" : "conversationName",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "responsibleForUserName",
Expand All @@ -67,7 +67,7 @@
"fieldName" : "messageCreationDate",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "channelName",
"fieldName" : "conversationName",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "authorName",
Expand Down Expand Up @@ -109,7 +109,7 @@
"fieldName" : "courseTitle",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "channelName",
"fieldName" : "conversationName",
"fieldType" : "java.lang.String"
}, {
"fieldName" : "responsibleForUserName",
Expand Down Expand Up @@ -595,4 +595,4 @@
"fieldName" : "courseTitle",
"fieldType" : "java.lang.String"
} ]
} ]
} ]

0 comments on commit 4d36797

Please sign in to comment.