From b75afd57d3bcf9a7a1b9d32f3aea62fb37e049ba Mon Sep 17 00:00:00 2001
From: fkiefer <none@none>
Date: Fri, 10 Mar 2017 17:23:10 +0100
Subject: [PATCH] OO-2592 collect involved creators and modifiers recursively

---
 .../modules/fo/export/SendMailStepForm.java   | 39 ++++++-------------
 .../olat/modules/fo/manager/ForumManager.java | 26 ++++++++++++-
 2 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/olat/modules/fo/export/SendMailStepForm.java b/src/main/java/org/olat/modules/fo/export/SendMailStepForm.java
index 1ce63bf0c40..f1573174ea4 100644
--- a/src/main/java/org/olat/modules/fo/export/SendMailStepForm.java
+++ b/src/main/java/org/olat/modules/fo/export/SendMailStepForm.java
@@ -155,35 +155,18 @@ public class SendMailStepForm extends StepFormBasicController {
 	
 	private List<Identity> collectCreators () {
 		Set<Identity> setOfIdentity = new HashSet<>();
-		if (startMessage.getThreadtop() == null) {
-			List<Message> messages = forumManager.getTopMessageChildren(startMessage);
-			// if  added to another thread, inform those creators and modifiers as well
-			if (parentMessage != null && !parentMessage.equals(startMessage)) {
-				List<Message> parentMessages = forumManager.getTopMessageChildren(parentMessage);
-				messages.addAll(parentMessages);
-			}
-			// iterate all messages and extract distinct identities involved
-			for (Message message : messages) {
-				Identity creator = message.getCreator();
-				if (creator != null) {
-					setOfIdentity.add(creator);
-				}
-				Identity modifier = message.getModifier();
-				if (modifier != null) {
-					setOfIdentity.add(modifier);
-				}
-			}			
-		} else {
-			// only inform the message owner and possible modifier
-			Identity creator = startMessage.getCreator(); 
-			if (creator != null){
-				setOfIdentity.add(creator);
-			}
-			Identity modifier = startMessage.getCreator(); 
-			if (modifier != null){
-				setOfIdentity.add(modifier);
-			}
+		// inform start message
+		Identity creator = startMessage.getCreator();
+		if (creator != null) {
+			setOfIdentity.add(creator);
+		}
+		Identity modifier = startMessage.getModifier();
+		if (modifier != null) {
+			setOfIdentity.add(modifier);
 		}
+		// inform children
+		forumManager.collectThreadMembersRecursively(startMessage, setOfIdentity);
+
 		return setOfIdentity.stream().collect(Collectors.toList());
 	}
 	
diff --git a/src/main/java/org/olat/modules/fo/manager/ForumManager.java b/src/main/java/org/olat/modules/fo/manager/ForumManager.java
index 2892cd38c1c..8abed75cdc6 100644
--- a/src/main/java/org/olat/modules/fo/manager/ForumManager.java
+++ b/src/main/java/org/olat/modules/fo/manager/ForumManager.java
@@ -1064,7 +1064,31 @@ public class ForumManager {
 		moveMessageContainer(oldMessage.getForum().getKey(), oldMessage.getKey(), message.getForum().getKey(), message.getKey());
 		deleteMessageRecursion(oldMessage.getForum().getKey(), oldMessage);
 		return message;
-	}	
+	}
+	
+	
+	/**
+	 * Collect message children recursively.
+	 *
+	 * @param oldParent
+	 * @param setOfIdentity 
+	 */
+	public void collectThreadMembersRecursively(Message oldParent, Set<Identity> setOfIdentity) {
+		List<Message> children = getMessageChildren(oldParent);
+		for (Message child : children) {
+			Identity creator = child.getCreator();
+			if (creator != null) {
+				setOfIdentity.add(creator);
+			}
+			Identity modifier = child.getModifier();
+			if (modifier != null) {
+				setOfIdentity.add(modifier);
+			}
+			if (hasChildren(child)) {
+				collectThreadMembersRecursively(child, setOfIdentity);
+			}			
+		}
+	}
 
 	/**
 	 * Move thread to another forum recursively.
-- 
GitLab