[seam-commits] Seam SVN: r10395 - in trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum: i18n and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Apr 14 10:38:49 EDT 2009


Author: christian.bauer at jboss.com
Date: 2009-04-14 10:38:48 -0400 (Tue, 14 Apr 2009)
New Revision: 10395

Added:
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/default/mailtemplates/forumNotifyReplyToPosters.xhtml
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/inrelationto/mailtemplates/forumNotifyReplyToPosters.xhtml
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/sfwkorg/mailtemplates/forumNotifyReplyToPosters.xhtml
Modified:
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/ReplyHome.java
   trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties
Log:
JBSEAM-4009, e-mail all posters of a forum thread if enabled in profile

Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/ReplyHome.java
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/ReplyHome.java	2009-04-14 14:28:35 UTC (rev 10394)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/ReplyHome.java	2009-04-14 14:38:48 UTC (rev 10395)
@@ -2,6 +2,7 @@
 
 import org.jboss.seam.Component;
 import org.jboss.seam.ScopeType;
+import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.annotations.*;
 import org.jboss.seam.faces.Renderer;
 import org.jboss.seam.international.StatusMessages;
@@ -9,18 +10,24 @@
 import org.jboss.seam.wiki.core.action.CommentHome;
 import org.jboss.seam.wiki.core.model.WikiComment;
 import org.jboss.seam.wiki.core.model.WikiNode;
+import org.jboss.seam.wiki.core.model.User;
 import org.jboss.seam.wiki.core.ui.WikiRedirect;
 import org.jboss.seam.wiki.core.plugin.PluginRegistry;
 import org.jboss.seam.wiki.preferences.Preferences;
 
 import static org.jboss.seam.international.StatusMessage.Severity.INFO;
 
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
 @Name("replyHome")
 @Scope(ScopeType.CONVERSATION)
 public class ReplyHome extends CommentHome {
 
-    public static final String REPLY_NOTIFY_TEMPLATE        = "/mailtemplates/forumNotifyReply.xhtml";
-    public static final String REPLY_NOTIFY_LIST_TEMPLATE   = "/mailtemplates/forumNotifyReplyToList.xhtml";
+    public static final String REPLY_NOTIFY_ORIGINAL_POSTER_TEMPLATE    = "/mailtemplates/forumNotifyReply.xhtml";
+    public static final String REPLY_NOTIFY_LIST_TEMPLATE               = "/mailtemplates/forumNotifyReplyToList.xhtml";
+    public static final String REPLY_NOTIFY_POSTERS_TEMPLATE            = "/mailtemplates/forumNotifyReplyToPosters.xhtml";
 
     @Override
     public void create() {
@@ -33,9 +40,9 @@
     @In(create = true)
     private Renderer renderer;
 
+    // Triggered by superclass after persist() method completes
     @Observer(value = "Comment.persisted", create = false)
     public void sendNotificationMails() {
-        // Triggered by superclass after reply was persisted
 
         // Notify forum mailing list
         String notificationMailingList =
@@ -45,13 +52,48 @@
             renderer.render(PluginRegistry.instance().getPlugin("forum").getPackageThemePath()+REPLY_NOTIFY_LIST_TEMPLATE);
         }
 
-        // Notify original poster
+        // Notify original poster (unless it is the user who posted the comment)
         if (documentHome.getInstance().macroPresent(TopicHome.TOPIC_NOTIFY_ME_MACRO)
-            && !documentHome.getInstance().getCreatedBy().getUsername().equals(getInstance().getCreatedBy().getUsername())
+            && !documentHome.getInstance().getCreatedBy().getId().equals(getInstance().getCreatedBy().getId())
            ) {
-            getLog().debug("sending reply notification e-mail to original poster");
-            renderer.render(PluginRegistry.instance().getPlugin("forum").getPackageThemePath()+REPLY_NOTIFY_TEMPLATE);
+            getLog().debug("sending reply notification e-mail to original poster of topic");
+            renderer.render(PluginRegistry.instance().getPlugin("forum").getPackageThemePath()+ REPLY_NOTIFY_ORIGINAL_POSTER_TEMPLATE);
         }
+
+        // Find all posters of the thread
+        Set<User> notifyPosters = new HashSet();
+        getLog().debug("finding all posters of current topic thread");
+        List<WikiComment> comments = getWikiNodeDAO().findWikiCommentsFlat(documentHome.getInstance(), true);
+        for (WikiComment comment : comments) {
+
+            Long commentPosterId = comment.getCreatedBy().getId();
+            // Notify the guy if he is not a) the poster of the current comment or b) the original topic poster
+            if (!commentPosterId.equals(getInstance().getCreatedBy().getId()) &&
+                !commentPosterId.equals(documentHome.getInstance().getCreatedBy().getId())) {
+
+                getLog().debug("adding poster to notification list: " + comment.getCreatedBy());
+                notifyPosters.add(comment.getCreatedBy()); // The set filters duplicate user instances
+            }
+        }
+
+        // Send them an e-mail as well if preferences option is enabled
+        for (User poster : notifyPosters) {
+
+            // Reading this users preferences is a bit awkward...
+            Contexts.getEventContext().set("currentPreferencesUser", poster);
+            Boolean preferencesNotifyReplies = Preferences.instance().get(ForumPreferences.class).getNotifyMeOfReplies();
+            boolean notifyReplies = preferencesNotifyReplies != null && preferencesNotifyReplies;
+            Contexts.getEventContext().remove("currentPreferencesUser");
+
+            if (notifyReplies) {
+                getLog().debug("sending reply notification e-mail to poster on the thread: " + poster);
+                Contexts.getEventContext().set("notifyPoster", poster);
+                renderer.render(PluginRegistry.instance().getPlugin("forum").getPackageThemePath()+ REPLY_NOTIFY_POSTERS_TEMPLATE);
+            } else {
+                getLog().debug("notification not enabled for poster: " + poster);
+            }
+        }
+
     }
 
     @Begin(flushMode = FlushModeType.MANUAL, join = true)

Modified: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties	2009-04-14 14:28:35 UTC (rev 10394)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/i18n/messages_forum_en.properties	2009-04-14 14:38:48 UTC (rev 10395)
@@ -4,7 +4,7 @@
 forum.preferences.description=Plugin: Forum
 forum.preferences.property.topicsPerPage=Number of topics per page
 forum.preferences.property.notificationMailingList=Send all topics/replies to this e-mail address (empty to disable)
-forum.preferences.property.notifyMeOfReplies=Enable e-mail reply notification switch by default
+forum.preferences.property.notifyMeOfReplies=E-mail me replies to my topics or any threads I posted on
 
 forum.list.label=Forum List
 forum.list.description=List of all forum subdirectories
@@ -12,7 +12,7 @@
 forum.topics.label=Forum Topics
 forum.topics.description=List of all topics in a forum directory
 forum.topics.preferences.description=Plugin: Forum Topics
-forum.topics.preferences.property.mailingList=Send and receive topics to and from this mailinglist
+forum.topics.preferences.property.mailingList=Send and receive topics to and from this mailinglist (TODO)
 
 forum.posting.label=Forum Posting
 forum.posting.description=Turns a WikiDocument into a regular forum posting
@@ -21,7 +21,7 @@
 forum.stickyPosting.description=Turns a WikiDocument into a sticky forum posting
 
 forum.notifyReplies.label=Forum Reply Notification
-forum.notifyReplies.description=Send an e-mail to the owner of the posting if a reply is posted
+forum.notifyReplies.description=Send an e-mail to the owner of the topic if a reply is posted
 
 forum.replies.label=Forum Replies
 forum.replies.description=Shows wiki comments as posting replies thread

Added: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/default/mailtemplates/forumNotifyReplyToPosters.xhtml
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/default/mailtemplates/forumNotifyReplyToPosters.xhtml	                        (rev 0)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/default/mailtemplates/forumNotifyReplyToPosters.xhtml	2009-04-14 14:38:48 UTC (rev 10395)
@@ -0,0 +1,68 @@
+<m:message xmlns="http://www.w3.org/1999/xhtml"
+            xmlns:m="http://jboss.com/products/seam/mail"
+            xmlns:h="http://java.sun.com/jsf/html"
+            xmlns:f="http://java.sun.com/jsf/core"
+            xmlns:c="http://java.sun.com/jstl/core"
+            xmlns:wiki="http://jboss.com/products/seam/wiki">
+    <m:header name="X-Sent-From" value="JBoss Seam" />
+    <m:header name="Precedence" value="list"/>
+    <m:from name="Seam Wiki" address="do-not-reply at jboss.com" />
+    <m:to name="#{notifyPoster.fullname}">#{notifyPoster.email}</m:to>
+    <m:subject>[LaceWiki Forums] #{replyHome.instance.subject}</m:subject>
+    <m:body>
+        <html>
+            <body>
+            <p>Hello #{notifyPoster.firstname},</p>
+
+            <p>
+              a <a href="#{wikiURLRenderer.renderURL(replyHome.instance, true)}">response</a> was made
+              on a <a href="#{wikiURLRenderer.renderURL(currentDocument, true)}">thread</a> on the
+              LaceWiki forum. You also commented on this topic, and you have this notification enabled
+              in your profile preferences.
+            </p>
+
+            <p>
+                This is the new comment, posted by #{replyHome.instance.createdBy.fullname}:
+            </p>
+
+            <hr/>
+
+            <c:if test="#{replyHome.instance.useWikiText}">
+                <wiki:formattedText value="#{replyHome.instance.content}"
+                                    linkStyleClass="regularLink"
+                                    brokenLinkStyleClass="brokenLink"
+                                    attachmentLinkStyleClass="regularLink"
+                                    thumbnailLinkStyleClass="regularLink"
+                                    linkBaseFile="#{currentDocument}"
+                                    currentAreaNumber="#{currentDocument.areaNumber}"
+                                    enableMacroRendering="false"/>
+            </c:if>
+            <c:if test="#{not replyHome.instance.useWikiText}">
+                <div style="font-family: Andale Mono, Courier New, monospace;">
+                    <h:outputText escape="false" value="#{wiki:escapeHTML(replyHome.instance.content, true, true)}"/>
+                </div>
+            </c:if>
+
+            <hr/>
+            <a href="#{wikiURLRenderer.renderURL(replyHome.instance, true)}">Click here</a> to reply...
+
+            </body>
+        </html>
+        <f:facet name="alternative">
+            <h:outputText>
+Hello #{notifyPoster.firstname},
+
+a response was made on a forum thread on the LaceWiki community forum. You also
+commented on this topic, and you have this notification enabled in your
+profile preferences:
+
+From: #{replyHome.instance.createdBy.fullname}
+Subject:#{replyHome.instance.subject}
+
+Follow this link to read and reply:
+
+#{wikiURLRenderer.renderURL(replyHome.instance, true)}
+</h:outputText>
+        </f:facet>
+    </m:body>
+</m:message>

Added: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/inrelationto/mailtemplates/forumNotifyReplyToPosters.xhtml
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/inrelationto/mailtemplates/forumNotifyReplyToPosters.xhtml	                        (rev 0)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/inrelationto/mailtemplates/forumNotifyReplyToPosters.xhtml	2009-04-14 14:38:48 UTC (rev 10395)
@@ -0,0 +1,68 @@
+<m:message xmlns="http://www.w3.org/1999/xhtml"
+            xmlns:m="http://jboss.com/products/seam/mail"
+            xmlns:h="http://java.sun.com/jsf/html"
+            xmlns:f="http://java.sun.com/jsf/core"
+            xmlns:c="http://java.sun.com/jstl/core"
+            xmlns:wiki="http://jboss.com/products/seam/wiki">
+    <m:header name="X-Sent-From" value="JBoss Seam" />
+    <m:header name="Precedence" value="list"/>
+    <m:from name="Seam Wiki" address="do-not-reply at jboss.com" />
+    <m:to name="#{notifyPoster.fullname}">#{notifyPoster.email}</m:to>
+    <m:subject>[LaceWiki Forums] #{replyHome.instance.subject}</m:subject>
+    <m:body>
+        <html>
+            <body>
+            <p>Hello #{notifyPoster.firstname},</p>
+
+            <p>
+              a <a href="#{wikiURLRenderer.renderURL(replyHome.instance, true)}">response</a> was made
+              on a <a href="#{wikiURLRenderer.renderURL(currentDocument, true)}">thread</a> on the
+              LaceWiki forum. You also commented on this topic, and you have this notification enabled
+              in your profile preferences.
+            </p>
+
+            <p>
+                This is the new comment, posted by #{replyHome.instance.createdBy.fullname}:
+            </p>
+
+            <hr/>
+
+            <c:if test="#{replyHome.instance.useWikiText}">
+                <wiki:formattedText value="#{replyHome.instance.content}"
+                                    linkStyleClass="regularLink"
+                                    brokenLinkStyleClass="brokenLink"
+                                    attachmentLinkStyleClass="regularLink"
+                                    thumbnailLinkStyleClass="regularLink"
+                                    linkBaseFile="#{currentDocument}"
+                                    currentAreaNumber="#{currentDocument.areaNumber}"
+                                    enableMacroRendering="false"/>
+            </c:if>
+            <c:if test="#{not replyHome.instance.useWikiText}">
+                <div style="font-family: Andale Mono, Courier New, monospace;">
+                    <h:outputText escape="false" value="#{wiki:escapeHTML(replyHome.instance.content, true, true)}"/>
+                </div>
+            </c:if>
+
+            <hr/>
+            <a href="#{wikiURLRenderer.renderURL(replyHome.instance, true)}">Click here</a> to reply...
+
+            </body>
+        </html>
+        <f:facet name="alternative">
+            <h:outputText>
+Hello #{notifyPoster.firstname},
+
+a response was made on a forum thread on the LaceWiki community forum. You also
+commented on this topic, and you have this notification enabled in your
+profile preferences:
+
+From: #{replyHome.instance.createdBy.fullname}
+Subject:#{replyHome.instance.subject}
+
+Follow this link to read and reply:
+
+#{wikiURLRenderer.renderURL(replyHome.instance, true)}
+</h:outputText>
+        </f:facet>
+    </m:body>
+</m:message>

Added: trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/sfwkorg/mailtemplates/forumNotifyReplyToPosters.xhtml
===================================================================
--- trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/sfwkorg/mailtemplates/forumNotifyReplyToPosters.xhtml	                        (rev 0)
+++ trunk/examples/wiki/src/plugin/org/jboss/seam/wiki/plugin/forum/themes/sfwkorg/mailtemplates/forumNotifyReplyToPosters.xhtml	2009-04-14 14:38:48 UTC (rev 10395)
@@ -0,0 +1,68 @@
+<m:message xmlns="http://www.w3.org/1999/xhtml"
+            xmlns:m="http://jboss.com/products/seam/mail"
+            xmlns:h="http://java.sun.com/jsf/html"
+            xmlns:f="http://java.sun.com/jsf/core"
+            xmlns:c="http://java.sun.com/jstl/core"
+            xmlns:wiki="http://jboss.com/products/seam/wiki">
+    <m:header name="X-Sent-From" value="SeamFramework.org" />
+    <m:header name="Precedence" value="list"/>
+    <m:from name="SeamFramework.org" address="do-not-reply at jboss.com" />
+    <m:to name="#{notifyPoster.fullname}">#{notifyPoster.email}</m:to>
+    <m:subject>[SeamFramework.org Forums] #{replyHome.instance.subject}</m:subject>
+    <m:body>
+        <html>
+            <body>
+            <p>Hello #{notifyPoster.firstname},</p>
+
+            <p>
+              a <a href="#{wikiURLRenderer.renderURL(replyHome.instance, true)}">response</a> was made
+              on a <a href="#{wikiURLRenderer.renderURL(currentDocument, true)}">thread</a> on the
+              Seam community forum. You also commented on this topic, and you have this notification enabled
+              in your profile preferences.
+            </p>
+
+            <p>
+                This is the new comment, posted by #{replyHome.instance.createdBy.fullname}:
+            </p>
+
+            <hr/>
+
+            <c:if test="#{replyHome.instance.useWikiText}">
+                <wiki:formattedText value="#{replyHome.instance.content}"
+                                    linkStyleClass="regularLink"
+                                    brokenLinkStyleClass="brokenLink"
+                                    attachmentLinkStyleClass="regularLink"
+                                    thumbnailLinkStyleClass="regularLink"
+                                    linkBaseFile="#{currentDocument}"
+                                    currentAreaNumber="#{currentDocument.areaNumber}"
+                                    enableMacroRendering="false"/>
+            </c:if>
+            <c:if test="#{not replyHome.instance.useWikiText}">
+                <div style="font-family: Andale Mono, Courier New, monospace;">
+                    <h:outputText escape="false" value="#{wiki:escapeHTML(replyHome.instance.content, true, true)}"/>
+                </div>
+            </c:if>
+
+            <hr/>
+            <a href="#{wikiURLRenderer.renderURL(replyHome.instance, true)}">Click here</a> to reply...
+
+            </body>
+        </html>
+        <f:facet name="alternative">
+            <h:outputText>
+Hello #{notifyPoster.firstname},
+
+a response was made on a forum thread on the Seam community forum. You also
+commented on this topic, and you have this notification enabled in your
+profile preferences:
+
+From: #{replyHome.instance.createdBy.fullname}
+Subject:#{replyHome.instance.subject}
+
+Follow this link to read and reply:
+
+#{wikiURLRenderer.renderURL(replyHome.instance, true)}
+</h:outputText>
+        </f:facet>
+    </m:body>
+</m:message>




More information about the seam-commits mailing list