chibenwa commented on code in PR #2886:
URL: https://github.com/apache/james-project/pull/2886#discussion_r2630467484


##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/DeleteMessageListener.java:
##########
@@ -138,17 +138,28 @@ private Mono<Void> 
handleMessageDeletion(PostgresMessageDAO postgresMessageDAO,
         return Mono.just(messageId)
             .filterWhen(msgId -> isUnreferenced(msgId, 
postgresMailboxMessageDAO))
             .flatMap(msgId -> postgresMessageDAO.retrieveMessage(messageId)
-                .flatMap(executeDeletionCallbacks(mailboxId, owner))
+                .flatMap(messageRepresentation -> 
dispatchMessageContentDeletionEvent(mailboxId, owner, messageRepresentation))
                 .then(deleteBodyBlob(msgId, postgresMessageDAO))
                 .then(deleteAttachment(msgId, attachmentDAO))
                 .then(threadDAO.deleteSome(owner, msgId))
                 .then(postgresMessageDAO.deleteByMessageId(msgId)));
     }
 
-    private Function<MessageRepresentation, Mono<Void>> 
executeDeletionCallbacks(MailboxId mailboxId, Username owner) {
-        return messageRepresentation -> Flux.fromIterable(deletionCallbackList)
-            .concatMap(callback -> callback.forMessage(messageRepresentation, 
mailboxId, owner))
-            .then();
+    private Mono<Void> dispatchMessageContentDeletionEvent(MailboxId 
mailboxId, Username owner, MessageRepresentation message) {
+        return Mono.fromCallable(() -> 
IOUtils.toString(message.getHeaderContent().getInputStream(), 
StandardCharsets.UTF_8))
+            .subscribeOn(ReactorUtils.BLOCKING_CALL_WRAPPER)
+            .flatMap(headerContent -> 
Mono.from(contentDeletionEventBus.dispatch(EventFactory.messageContentDeleted()
+                    .randomEventId()
+                    .user(owner)
+                    .mailboxId(mailboxId)
+                    .messageId(message.getMessageId())
+                    .size(message.getSize())
+                    .instant(message.getInternalDate().toInstant())
+                    .hasAttachments(!message.getAttachments().isEmpty())
+                    .bodyBlobId(message.getBodyBlobId().asString())
+                    .headerContent(headerContent)
+                    .build(),

Review Comment:
   I would extract event creation into a dedicated method for more clarity



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to