Convert conversation notification to new email API
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 1 Aug 2016 13:18:57 +0000 (15:18 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 1 Aug 2016 14:26:31 +0000 (16:26 +0200)
files/lib/data/conversation/message/ConversationMessage.class.php
files/lib/system/user/notification/event/ConversationUserNotificationEvent.class.php
language/de.xml
language/en.xml
templates/email_notification_conversation.tpl [new file with mode: 0644]

index 9190cde3c403f5c030f8dce50881dbdd1d3aa495..d99327030e8251ec46d2143adf6d9640aeb1e833 100644 (file)
@@ -108,12 +108,24 @@ class ConversationMessage extends DatabaseObject implements IMessage {
        }
        
        /**
-        * Returns a text-only version of this message.
+        * Returns a version of this message optimized for use in emails.
         * 
+        * @param       string  $mimeType       Either 'text/plain' or 'text/html'
         * @return      string
         */
-       public function getMailText() {
-               return MessageParser::getInstance()->stripHTML($this->getSimplifiedFormattedMessage());
+       public function getMailText($mimeType = 'text/plain') {
+               switch ($mimeType) {
+                       case 'text/plain':
+                               $processor = new HtmlOutputProcessor();
+                               $processor->setOutputType('text/plain');
+                               $processor->process($this->message, 'com.woltlab.wcf.conversation.message', $this->messageID);
+                               
+                               return $processor->getHtml();
+                       case 'text/html':
+                               return $this->getSimplifiedFormattedMessage();
+               }
+               
+               throw new \LogicException('Unreachable');
        }
        
        /**
index df2f73322278a74d30564eb4c76477f0561b371b..008d42d191d6bc6841ad2492d732677b14cdc13a 100644 (file)
@@ -36,11 +36,11 @@ class ConversationUserNotificationEvent extends AbstractUserNotificationEvent {
         * @inheritDoc
         */
        public function getEmailMessage($notificationType = 'instant') {
-               return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.mail', [
-                       'conversation' => $this->userNotificationObject,
-                       'author' => $this->author,
-                       'notificationType' => $notificationType
-               ]);
+               return [
+                       'message-id' => 'com.woltlab.wcf.conversation.notification/'.$this->getUserNotificationObject()->conversationID,
+                       'template' => 'email_notification_conversation',
+                       'application' => 'wcf'
+               ];
        }
        
        /**
index f93eb5e4cf16c4757a04523f9eb3cafde14771d4..8919d7227361f2da712f57e65fa43a893c4fcf71 100644 (file)
 {/if}{link controller='Conversation' object=$message->getConversation() isEmail=true}messageID={@$message->messageID}{/link}#message{@$message->messageID}]]></item>
                <item name="wcf.user.notification.conversation.message"><![CDATA[{@$author->getAnchorTag()} hat die Konversation <a href="{link controller='Conversation' object=$conversation}{/link}">{$conversation->subject}</a> gestartet.]]></item>
                <item name="wcf.user.notification.conversation.title"><![CDATA[Neue Konversation]]></item>
-               <item name="wcf.user.notification.conversation.mail"><![CDATA[{@$author->username} hat die Konversation "{@$conversation->subject}" gestartet:
-{if $notificationType == 'instant'}
----------------------------------
-{@$conversation->getFirstMessage()->getMailText()} 
----------------------------------
-{/if}{link controller='Conversation' object=$conversation isEmail=true}{/link}]]></item>
+               <item name="wcf.user.notification.conversation.mail.plaintext"><![CDATA[{@$event->getAuthor()->username} [URL:{link controller='User' object=$event->getAuthor() isEmail=true}{/link}] hat die Konversation „{@$event->getUserNotificationObject()->subject}“ [URL:{link controller='Conversation' object=$event->getUserNotificationObject() isEmail=true}{/link}] gestartet:]]></item>
+               <item name="wcf.user.notification.conversation.mail.html"><![CDATA[<p><a href="{link controller='User' object=$event->getAuthor() isEmail=true}{/link}">{$event->getAuthor()->username}</a> hat die Konversation <a href="{link controller='Conversation' object=$event->getUserNotificationObject() isEmail=true}{/link}">{$event->getUserNotificationObject()->subject}</a> gestartet:</p>]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.conversation"><![CDATA[Konversationen]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.conversation.notification.conversation"><![CDATA[Neue Konversation]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.conversation.message.notification.conversationMessage"><![CDATA[Antwort auf bestehende Konversation]]></item>
index 459937db6d9ffe037480759fd497b190a2c9263d..04a0a7c4d9c8a4eab9f8259cb1311cddcd128e03 100644 (file)
 {@$conversation->getFirstMessage()->getMailText()} 
 ---------------------------------
 {/if}{link controller='Conversation' object=$conversation isEmail=true}{/link}]]></item>
+               <item name="wcf.user.notification.conversation.mail.plaintext"><![CDATA[{@$event->getAuthor()->username} [URL:{link controller='User' object=$event->getAuthor() isEmail=true}{/link}] started the conversation “{@$event->getUserNotificationObject()->subject}” [URL:{link controller='Conversation' object=$event->getUserNotificationObject() isEmail=true}{/link}]:]]></item>
+               <item name="wcf.user.notification.conversation.mail.html"><![CDATA[<p><a href="{link controller='User' object=$event->getAuthor() isEmail=true}{/link}">{$event->getAuthor()->username}</a> started the conversation <a href="{link controller='Conversation' object=$event->getUserNotificationObject() isEmail=true}{/link}">{$event->getUserNotificationObject()->subject}</a>:</p>]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.conversation"><![CDATA[Conversations]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.conversation.notification.conversation"><![CDATA[Notify when I receive new conversations]]></item>
                <item name="wcf.user.notification.com.woltlab.wcf.conversation.message.notification.conversationMessage"><![CDATA[Notify when I receive replies to existing conversations]]></item>
diff --git a/templates/email_notification_conversation.tpl b/templates/email_notification_conversation.tpl
new file mode 100644 (file)
index 0000000..159e60f
--- /dev/null
@@ -0,0 +1,37 @@
+{if $mimeType === 'text/plain'}
+{lang}wcf.user.notification.conversation.mail.plaintext{/lang}
+
+{@$event->getUserNotificationObject()->getFirstMessage()->getMailText($mimeType)} {* this line ends with a space *}
+{else}
+       {lang}wcf.user.notification.conversation.mail.html{/lang}
+       {assign var='user' value=$event->getAuthor()}
+       {assign var='conversation' value=$event->getUserNotificationObject()}
+       {assign var='message' value=$conversation->getFirstMessage()}
+       
+       {if $notificationType == 'instant'}{assign var='avatarSize' value=128}
+       {else}{assign var='avatarSize' value=64}{/if}
+       {capture assign='messageContent'}
+       <table cellpadding="0" cellspacing="0" border="0">
+               <tr>
+                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$message->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
+                       <td class="boxContent">
+                               <div class="containerHeadline">
+                                       <h3>
+                                               {if $message->userID}
+                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$message->username}</a>
+                                               {else}
+                                                       {$message->username}
+                                               {/if}
+                                               &#xb7;
+                                               <small>{$message->time|plainTime}</small>
+                                       </h3>
+                               </div>
+                               <div>
+                                       {@$message->getMailText($mimeType)}
+                               </div>
+                       </td>
+               </tr>
+       </table>
+       {/capture}
+       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$messageContent sandbox=true}
+{/if}