From: Tim Düsterhus Date: Mon, 1 Aug 2016 13:18:57 +0000 (+0200) Subject: Convert conversation notification to new email API X-Git-Tag: 3.0.0_Beta_1~36^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fe4319fb4c976ca8fa1618c640094ad998c0ed9b;p=GitHub%2FWoltLab%2Fcom.woltlab.wcf.conversation.git Convert conversation notification to new email API --- diff --git a/files/lib/data/conversation/message/ConversationMessage.class.php b/files/lib/data/conversation/message/ConversationMessage.class.php index 9190cde..d993270 100644 --- a/files/lib/data/conversation/message/ConversationMessage.class.php +++ b/files/lib/data/conversation/message/ConversationMessage.class.php @@ -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'); } /** diff --git a/files/lib/system/user/notification/event/ConversationUserNotificationEvent.class.php b/files/lib/system/user/notification/event/ConversationUserNotificationEvent.class.php index df2f733..008d42d 100644 --- a/files/lib/system/user/notification/event/ConversationUserNotificationEvent.class.php +++ b/files/lib/system/user/notification/event/ConversationUserNotificationEvent.class.php @@ -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' + ]; } /** diff --git a/language/de.xml b/language/de.xml index f93eb5e..8919d72 100644 --- a/language/de.xml +++ b/language/de.xml @@ -191,12 +191,8 @@ {/if}{link controller='Conversation' object=$message->getConversation() isEmail=true}messageID={@$message->messageID}{/link}#message{@$message->messageID}]]> getAnchorTag()} hat die Konversation {$conversation->subject} gestartet.]]> - username} hat die Konversation "{@$conversation->subject}" gestartet: -{if $notificationType == 'instant'} ---------------------------------- -{@$conversation->getFirstMessage()->getMailText()} ---------------------------------- -{/if}{link controller='Conversation' object=$conversation isEmail=true}{/link}]]> + 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:]]> + {$event->getAuthor()->username} hat die Konversation {$event->getUserNotificationObject()->subject} gestartet:

]]>
diff --git a/language/en.xml b/language/en.xml index 459937d..04a0a7c 100644 --- a/language/en.xml +++ b/language/en.xml @@ -200,6 +200,8 @@ {@$conversation->getFirstMessage()->getMailText()} --------------------------------- {/if}{link controller='Conversation' object=$conversation isEmail=true}{/link}]]> + 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}]:]]> + {$event->getAuthor()->username} started the conversation {$event->getUserNotificationObject()->subject}:

]]>
diff --git a/templates/email_notification_conversation.tpl b/templates/email_notification_conversation.tpl new file mode 100644 index 0000000..159e60f --- /dev/null +++ b/templates/email_notification_conversation.tpl @@ -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'} + + + + + +
{@$user->getAvatar()->getImageTag($avatarSize)} +
+

+ {if $message->userID} + {$message->username} + {else} + {$message->username} + {/if} + · + {$message->time|plainTime} +

+
+
+ {@$message->getMailText($mimeType)} +
+
+ {/capture} + {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$messageContent sandbox=true} +{/if}