From 6f903974cb58870fc9ae86f52f06d2c9c90c84f4 Mon Sep 17 00:00:00 2001 From: Hiroki Terashima Date: Mon, 9 Mar 2026 12:17:01 -0700 Subject: [PATCH] feat(Discussion): Hide inappropriate posts in real-time --- .../data/redis/RedisMessageSubscriber.java | 1 + .../web/wise5/TeacherPostDataController.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/wise/portal/spring/data/redis/RedisMessageSubscriber.java b/src/main/java/org/wise/portal/spring/data/redis/RedisMessageSubscriber.java index aba41d2bd..2372a18e6 100644 --- a/src/main/java/org/wise/portal/spring/data/redis/RedisMessageSubscriber.java +++ b/src/main/java/org/wise/portal/spring/data/redis/RedisMessageSubscriber.java @@ -37,6 +37,7 @@ public void onMessage(Message message, byte[] pattern) { createAndSendWebSocketMessage("newStudentAchievement", messageJSON, "achievement"); break; case "annotationToStudent": + case "annotationToClassroom": createAndSendWebSocketMessage("annotation", messageJSON, "annotation"); break; case "notification": diff --git a/src/main/java/org/wise/vle/web/wise5/TeacherPostDataController.java b/src/main/java/org/wise/vle/web/wise5/TeacherPostDataController.java index 9d68ed8aa..383013bb1 100644 --- a/src/main/java/org/wise/vle/web/wise5/TeacherPostDataController.java +++ b/src/main/java/org/wise/vle/web/wise5/TeacherPostDataController.java @@ -174,8 +174,11 @@ private void sendAnnotationNotificationToStudent(Annotation annotation) { try { Notification notification = this.createNotificationForAnnotation(annotation); Long toWorkgroupId = notification.getToWorkgroup().getId(); - broadcastAnnotationToStudent(toWorkgroupId, annotation); - broadcastNotificationToStudent(toWorkgroupId, notification); + this.broadcastAnnotationToStudent(toWorkgroupId, annotation); + if (annotation.getType().equals("inappropriateFlag")) { + this.broadcastAnnotationToClassroom(annotation); + } + this.broadcastNotificationToStudent(toWorkgroupId, notification); } catch (Exception e) { e.printStackTrace(); } @@ -217,7 +220,7 @@ private Notification createNotificationForAnnotation(Annotation annotation) { return notification; } - public void broadcastAnnotationToStudent(Long toWorkgroupId, Annotation annotation) + private void broadcastAnnotationToStudent(Long toWorkgroupId, Annotation annotation) throws JSONException { annotation.convertToClientAnnotation(); JSONObject message = new JSONObject(); @@ -227,7 +230,17 @@ public void broadcastAnnotationToStudent(Long toWorkgroupId, Annotation annotati redisPublisher.publish(message.toString()); } - public void broadcastNotificationToStudent(Long toWorkgroupId, Notification notification) + private void broadcastAnnotationToClassroom(Annotation annotation) throws JSONException { + annotation.convertToClientAnnotation(); + JSONObject message = new JSONObject(); + message.put("type", "annotationToClassroom"); + message.put("topic", String.format("/topic/classroom/%s/%s", annotation.getRun().getId(), + annotation.getPeriod().getId())); + message.put("annotation", annotation.toJSON()); + redisPublisher.publish(message.toString()); + } + + private void broadcastNotificationToStudent(Long toWorkgroupId, Notification notification) throws JSONException { notification.convertToClientNotification(); JSONObject message = new JSONObject(); @@ -236,4 +249,5 @@ public void broadcastNotificationToStudent(Long toWorkgroupId, Notification noti message.put("notification", notification.toJSON()); redisPublisher.publish(message.toString()); } + }